Skip to content

Commit

Permalink
Enable .toml tests in generic tests
Browse files Browse the repository at this point in the history
Also fix floating point precision in JSON/TOML writing
  • Loading branch information
franzpoeschel committed May 10, 2023
1 parent da136d2 commit e5ec9b9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/auxiliary/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ namespace
case nlohmann::json::value_t::number_unsigned:
return val.get<nlohmann::json::number_unsigned_t>();
case nlohmann::json::value_t::number_float:
return val.get<nlohmann::json::number_float_t>();
return (long double)val.get<nlohmann::json::number_float_t>();
case nlohmann::json::value_t::binary:
return val.get<nlohmann::json::binary_t>();
case nlohmann::json::value_t::discarded:
Expand Down
2 changes: 2 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ std::map<std::string, bool> openPMD::getVariants()
return std::map<std::string, bool>{
{"mpi", bool(openPMD_HAVE_MPI)},
{"json", true},
{"toml", true},
{"hdf5", bool(openPMD_HAVE_HDF5)},
{"adios1", false},
{"adios2", bool(openPMD_HAVE_ADIOS2)}};
Expand All @@ -43,6 +44,7 @@ std::vector<std::string> openPMD::getFileExtensions()
{
std::vector<std::string> fext;
fext.emplace_back("json");
fext.emplace_back("toml");
#if openPMD_HAVE_ADIOS2
fext.emplace_back("bp");
#endif
Expand Down
22 changes: 19 additions & 3 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,14 +1287,21 @@ TEST_CASE("particle_patches", "[serial]")
}
}

inline void dtype_test(const std::string &backend)
inline void dtype_test(
const std::string &backend,
std::optional<std::string> activateTemplateMode = {})
{
bool test_long_double =
(backend != "json" || sizeof(long double) <= 8) && backend != "toml";
bool test_long_long =
(backend != "json" || sizeof(long long) <= 8) && backend != "toml";
{
Series s = Series("../samples/dtype_test." + backend, Access::CREATE);
Series s = activateTemplateMode.has_value()
? Series(
"../samples/dtype_test." + backend,
Access::CREATE,
activateTemplateMode.value())
: Series("../samples/dtype_test." + backend, Access::CREATE);
bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1";

char c = 'c';
Expand Down Expand Up @@ -1424,7 +1431,12 @@ inline void dtype_test(const std::string &backend)
}
}

Series s = Series("../samples/dtype_test." + backend, Access::READ_ONLY);
Series s = activateTemplateMode.has_value()
? Series(
"../samples/dtype_test." + backend,
Access::READ_ONLY,
activateTemplateMode.value())
: Series("../samples/dtype_test." + backend, Access::READ_ONLY);
bool adios1 = s.backend() == "ADIOS1" || s.backend() == "MPI_ADIOS1";

REQUIRE(s.getAttribute("char").get<char>() == 'c');
Expand Down Expand Up @@ -1502,6 +1514,10 @@ inline void dtype_test(const std::string &backend)
REQUIRE(s.getAttribute("bool").get<bool>() == true);
REQUIRE(s.getAttribute("boolF").get<bool>() == false);

if (activateTemplateMode.has_value())
{
return;
}
// same implementation types (not necessary aliases) detection
#if !defined(_MSC_VER)
REQUIRE(s.getAttribute("short").dtype == Datatype::SHORT);
Expand Down
5 changes: 3 additions & 2 deletions test/python/unittest/API/APITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ def attributeRoundTrip(self, file_ending):
# c_types
self.assertEqual(series.get_attribute("byte_c"), 30)
self.assertEqual(series.get_attribute("ubyte_c"), 50)
if file_ending != "json": # TODO: returns [100] instead of 100 in json
# TODO: returns [100] instead of 100 in json
if file_ending != "json" and file_ending != "toml":
self.assertEqual(chr(series.get_attribute("char_c")), 'd')
self.assertEqual(series.get_attribute("int16_c"), 2)
self.assertEqual(series.get_attribute("int32_c"), 3)
Expand Down Expand Up @@ -1824,7 +1825,7 @@ def testIterator(self):
self.makeIteratorRoundTrip(b, backend_filesupport[b])

def makeAvailableChunksRoundTrip(self, ext):
if ext == "h5":
if ext == "h5" or ext == "toml":
return
name = "../samples/available_chunks_python." + ext
write = io.Series(
Expand Down

0 comments on commit e5ec9b9

Please sign in to comment.