From 84f1eed91fca246b26f3af7f4e807e5278b716de Mon Sep 17 00:00:00 2001 From: Laurie O Date: Thu, 2 Jul 2020 08:19:48 +1000 Subject: [PATCH 1/2] Add round-trip test --- tests/python-tests/test_api.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/python-tests/test_api.py b/tests/python-tests/test_api.py index ed5dac5..f562db3 100644 --- a/tests/python-tests/test_api.py +++ b/tests/python-tests/test_api.py @@ -97,6 +97,18 @@ def test_invalid_toml_files(toml_file): pytomlpp.loads(toml_file_string) +@pytest.mark.parametrize("toml_file", valid_toml_files) +def test_round_trip_for_valid_toml_files(toml_file): + with open(str(toml_file), "r") as f: + text = f.read() + print(text.strip(), end="\n\n") + table = pytomlpp.loads(text) + print(table, end="\n\n") + + text2 = pytomlpp.dumps(table) + print(text2, end="\n\n") + table2 = pytomlpp.loads(text2) + assert table == table2 def test_invalid_encode(): From 7b84f611aa8ea0b6988df545835d08d9f090ab7b Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 2 Jul 2020 12:26:36 +0530 Subject: [PATCH 2/2] Fix bugs in datetime parsing (#35) --- include/pytomlpp/toml_types.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/pytomlpp/toml_types.hpp b/include/pytomlpp/toml_types.hpp index 7f1ef2c..c89acbb 100644 --- a/include/pytomlpp/toml_types.hpp +++ b/include/pytomlpp/toml_types.hpp @@ -22,9 +22,9 @@ template <> class type_caster { toml::date d; if (PyDate_Check(src.ptr())) { - d.year = PyDateTime_GET_DAY(src.ptr()); + d.year = PyDateTime_GET_YEAR(src.ptr()); d.month = PyDateTime_GET_MONTH(src.ptr()); - d.day = PyDateTime_GET_YEAR(src.ptr()); + d.day = PyDateTime_GET_DAY(src.ptr()); } else return false; @@ -99,15 +99,15 @@ template <> class type_caster { if (PyDateTime_Check(src.ptr())) { toml::date d; - d.year = PyDateTime_GET_DAY(src.ptr()); + d.year = PyDateTime_GET_YEAR(src.ptr()); d.month = PyDateTime_GET_MONTH(src.ptr()); - d.day = PyDateTime_GET_YEAR(src.ptr()); + d.day = PyDateTime_GET_DAY(src.ptr()); toml::time t; - t.hour = PyDateTime_TIME_GET_HOUR(src.ptr()); - t.minute = PyDateTime_TIME_GET_MINUTE(src.ptr()); - t.second = PyDateTime_TIME_GET_SECOND(src.ptr()); - t.nanosecond = PyDateTime_TIME_GET_MICROSECOND(src.ptr()) * 1000; + t.hour = PyDateTime_DATE_GET_HOUR(src.ptr()); + t.minute = PyDateTime_DATE_GET_MINUTE(src.ptr()); + t.second = PyDateTime_DATE_GET_SECOND(src.ptr()); + t.nanosecond = PyDateTime_DATE_GET_MICROSECOND(src.ptr()) * 1000; py::object tz_info = src.attr("tzinfo");