Skip to content

Commit 7439025

Browse files
authored
Merge pull request #610 from ax3l/fix-throwNoHandler
Series: Throw on Dummy Handler
2 parents 7218317 + 592a7a2 commit 7439025

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Bug Fixes
4141
- xlC 16.1: work-around C-array initializer parsing issue #547
4242
- icc 19.0.0 and PGI 19.5: fix compiler ID identification #548
4343
- CMake: fix false-positives in ``FindADIOS.cmake`` module #609
44+
- Series: throws an error message if no file ending is specified #610
4445

4546
Other
4647
"""""

NEWS.rst

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ We will change this default in upcoming releases to prefer ADIOS2.
1414
The JSON backend is now always enabled.
1515
The CMake option ``-DopenPMD_USE_JSON`` has been removed (as it is always ``ON`` now).
1616

17+
Previously, omitting a file ending in the ``Series`` constructor chose a "dummy" no-operation file backend.
18+
This was confusing and instead a runtime error is now thrown.
19+
20+
1721
0.9.0-alpha
1822
-----------
1923

src/IO/AbstractIOHandlerHelper.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ namespace openPMD
5353
case Format::ADIOS2:
5454
return std::make_shared<ADIOS2IOHandler>(path, accessTypeBackend, comm);
5555
default:
56+
throw std::runtime_error("Unknown file format! Did you specify a file ending?" );
5657
return std::make_shared< DummyIOHandler >(path, accessTypeBackend);
5758
}
5859
}
@@ -82,6 +83,7 @@ namespace openPMD
8283
case Format::JSON:
8384
return std::make_shared< JSONIOHandler >(path, accessType);
8485
default:
86+
throw std::runtime_error("Unknown file format! Did you specify a file ending?" );
8587
return std::make_shared< DummyIOHandler >(path, accessType);
8688
}
8789
}

test/AuxiliaryTest.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct TestHelper : public Attributable
3333
{
3434
TestHelper()
3535
{
36-
m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::DUMMY);
36+
m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::JSON);
3737
IOHandler = m_writable->IOHandler.get();
3838
}
3939
};
@@ -108,7 +108,7 @@ TEST_CASE( "container_default_test", "[auxiliary]")
108108
{
109109
#if openPMD_USE_INVASIVE_TESTS
110110
Container< openPMD::test::S > c = Container< openPMD::test::S >();
111-
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::DUMMY);
111+
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::JSON);
112112
c.IOHandler = c.m_writable->IOHandler.get();
113113

114114
REQUIRE(c.empty());
@@ -143,7 +143,7 @@ TEST_CASE( "container_retrieve_test", "[auxiliary]" )
143143
#if openPMD_USE_INVASIVE_TESTS
144144
using structure = openPMD::test::structure;
145145
Container< structure > c = Container< structure >();
146-
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::DUMMY);
146+
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::JSON);
147147
c.IOHandler = c.m_writable->IOHandler.get();
148148

149149
structure s;
@@ -220,7 +220,7 @@ TEST_CASE( "container_access_test", "[auxiliary]" )
220220
#if openPMD_USE_INVASIVE_TESTS
221221
using Widget = openPMD::test::Widget;
222222
Container< Widget > c = Container< Widget >();
223-
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::DUMMY);
223+
c.m_writable->IOHandler = createIOHandler(".", AccessType::CREATE, Format::JSON);
224224
c.IOHandler = c.m_writable->IOHandler.get();
225225

226226
c["firstWidget"] = Widget(0);

test/CoreTest.cpp

+32-19
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ TEST_CASE( "attribute_dtype_test", "[core]" )
128128
TEST_CASE( "output_default_test", "[core]" )
129129
{
130130
using IE = IterationEncoding;
131-
Series o = Series("./new_openpmd_output_%T", AccessType::CREATE);
131+
Series o = Series("./new_openpmd_output_%T.json", AccessType::CREATE);
132132

133133
REQUIRE(o.openPMD() == "1.1.0");
134134
REQUIRE(o.openPMDextension() == static_cast<uint32_t>(0));
@@ -145,7 +145,7 @@ TEST_CASE( "output_default_test", "[core]" )
145145
TEST_CASE( "output_constructor_test", "[core]" )
146146
{
147147
using IE = IterationEncoding;
148-
Series o = Series("./MyCustomOutput", AccessType::CREATE);
148+
Series o = Series("./MyCustomOutput.json", AccessType::CREATE);
149149

150150
o.setMeshesPath("customMeshesPath").setParticlesPath("customParticlesPath");
151151

@@ -169,7 +169,7 @@ TEST_CASE( "output_constructor_test", "[core]" )
169169

170170
TEST_CASE( "output_modification_test", "[core]" )
171171
{
172-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
172+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
173173

174174
o.setOpenPMD("1.0.0");
175175
REQUIRE(o.openPMD() == "1.0.0");
@@ -194,7 +194,7 @@ TEST_CASE( "output_modification_test", "[core]" )
194194

195195
TEST_CASE( "iteration_default_test", "[core]" )
196196
{
197-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
197+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
198198

199199
Iteration& i = o.iterations[42];
200200

@@ -208,7 +208,7 @@ TEST_CASE( "iteration_default_test", "[core]" )
208208

209209
TEST_CASE( "iteration_modification_test", "[core]" )
210210
{
211-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
211+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
212212

213213
Iteration& i = o.iterations[42];
214214

@@ -226,7 +226,7 @@ TEST_CASE( "iteration_modification_test", "[core]" )
226226

227227
TEST_CASE( "particleSpecies_modification_test", "[core]" )
228228
{
229-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
229+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
230230

231231
auto& particles = o.iterations[42].particles;
232232
REQUIRE(0 == particles.numAttributes());
@@ -255,7 +255,7 @@ TEST_CASE( "particleSpecies_modification_test", "[core]" )
255255

256256
TEST_CASE( "record_constructor_test", "[core]" )
257257
{
258-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
258+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
259259

260260
ParticleSpecies ps = o.iterations[42].particles["species"];
261261
Record& r = ps["record"];
@@ -277,7 +277,7 @@ TEST_CASE( "record_constructor_test", "[core]" )
277277

278278
TEST_CASE( "record_modification_test", "[core]" )
279279
{
280-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
280+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
281281

282282
auto species = o.iterations[42].particles["species"];
283283
Record& r = species["position"];
@@ -305,7 +305,7 @@ TEST_CASE( "record_modification_test", "[core]" )
305305

306306
TEST_CASE( "recordComponent_modification_test", "[core]" )
307307
{
308-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
308+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
309309

310310
ParticleSpecies ps = o.iterations[42].particles["species"];
311311
Record& r = ps["record"];
@@ -327,7 +327,7 @@ TEST_CASE( "recordComponent_modification_test", "[core]" )
327327

328328
TEST_CASE( "mesh_constructor_test", "[core]" )
329329
{
330-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
330+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
331331

332332
Mesh &m = o.iterations[42].meshes["E"];
333333

@@ -355,7 +355,7 @@ TEST_CASE( "mesh_constructor_test", "[core]" )
355355

356356
TEST_CASE( "mesh_modification_test", "[core]" )
357357
{
358-
Series o = Series("./MyOutput_%T", AccessType::CREATE);
358+
Series o = Series("./MyOutput_%T.json", AccessType::CREATE);
359359

360360
Mesh &m = o.iterations[42].meshes["E"];
361361
m["x"];
@@ -395,7 +395,7 @@ TEST_CASE( "mesh_modification_test", "[core]" )
395395
TEST_CASE( "structure_test", "[core]" )
396396
{
397397
#if openPMD_USE_INVASIVE_TESTS
398-
Series o = Series("./new_openpmd_output_%T", AccessType::CREATE);
398+
Series o = Series("./new_openpmd_output_%T.json", AccessType::CREATE);
399399

400400
REQUIRE(o.IOHandler);
401401
REQUIRE(o.iterations.IOHandler);
@@ -520,7 +520,7 @@ TEST_CASE( "structure_test", "[core]" )
520520

521521
TEST_CASE( "wrapper_test", "[core]" )
522522
{
523-
Series o = Series("./new_openpmd_output", AccessType::CREATE);
523+
Series o = Series("./new_openpmd_output.json", AccessType::CREATE);
524524

525525
o.setOpenPMDextension(42);
526526
o.setIterationEncoding(IterationEncoding::fileBased);
@@ -569,8 +569,11 @@ TEST_CASE( "wrapper_test", "[core]" )
569569
mrc2.loadChunk(shareRaw(&loadData), {0}, {1});
570570
o.flush();
571571
REQUIRE(loadData == value);
572-
value = 43.;
573-
mrc2.makeConstant(value);
572+
// TODO: do we want to be able to make data constant after already writing it once?
573+
// value = 43.;
574+
// mrc2.makeConstant(value);
575+
REQUIRE_THROWS_WITH(mrc2.makeConstant(value),
576+
Catch::Equals("A recordComponent can not (yet) be made constant after it has been written."));
574577
std::array< double, 1 > moreData = {{ 112233. }};
575578
o.iterations[4].meshes["E"]["y"].loadChunk(shareRaw(moreData), {0}, {1});
576579
o.flush();
@@ -639,7 +642,7 @@ TEST_CASE( "wrapper_test", "[core]" )
639642

640643
TEST_CASE( "use_count_test", "[core]" )
641644
{
642-
Series o = Series("./new_openpmd_output", AccessType::CREATE);
645+
Series o = Series("./new_openpmd_output.json", AccessType::CREATE);
643646

644647
MeshRecordComponent mrc = o.iterations[1].meshes["E"]["x"];
645648
mrc.resetDataset(Dataset(determineDatatype<uint16_t>(), {42}));
@@ -663,7 +666,7 @@ TEST_CASE( "use_count_test", "[core]" )
663666

664667
TEST_CASE( "empty_record_test", "[core]" )
665668
{
666-
Series o = Series("./new_openpmd_output", AccessType::CREATE);
669+
Series o = Series("./new_openpmd_output.json", AccessType::CREATE);
667670

668671
o.iterations[1].meshes["E"].setComment("No assumption about contained RecordComponents will be made");
669672
REQUIRE_THROWS_WITH(o.flush(),
@@ -674,7 +677,7 @@ TEST_CASE( "empty_record_test", "[core]" )
674677

675678
TEST_CASE( "zero_extent_component", "[core]" )
676679
{
677-
Series o = Series("./new_openpmd_output", AccessType::CREATE);
680+
Series o = Series("./new_openpmd_output.json", AccessType::CREATE);
678681

679682
auto E_x = o.iterations[1].meshes["E"]["x"];
680683
E_x.setComment("Datasets must contain dimensions.");
@@ -683,4 +686,14 @@ TEST_CASE( "zero_extent_component", "[core]" )
683686
REQUIRE_THROWS_WITH(E_x.makeEmpty<int>(0),
684687
Catch::Equals("Dataset extent must be at least 1D."));
685688
E_x.resetDataset(Dataset(Datatype::DOUBLE, {1}));
686-
}
689+
}
690+
691+
TEST_CASE( "no_file_ending", "[core]" )
692+
{
693+
REQUIRE_THROWS_WITH(Series("./new_openpmd_output", AccessType::CREATE),
694+
Catch::Equals("Unknown file format! Did you specify a file ending?"));
695+
REQUIRE_THROWS_WITH(Series("./new_openpmd_output_%T", AccessType::CREATE),
696+
Catch::Equals("Unknown file format! Did you specify a file ending?"));
697+
REQUIRE_THROWS_WITH(Series("./new_openpmd_output_%05T", AccessType::CREATE),
698+
Catch::Equals("Unknown file format! Did you specify a file ending?"));
699+
}

0 commit comments

Comments
 (0)