Skip to content

Commit

Permalink
Merge branch 'master' of github.com:bobfang1992/pytomlpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bobfang1992 committed Jul 2, 2020
2 parents f2c2323 + 7b84f61 commit 541a2e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 8 additions & 8 deletions include/pytomlpp/toml_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ template <> class type_caster<toml::date> {
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;

Expand Down Expand Up @@ -99,15 +99,15 @@ template <> class type_caster<toml::date_time> {

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

Expand Down
12 changes: 12 additions & 0 deletions tests/python-tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 541a2e7

Please sign in to comment.