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"); 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():