From cb2a9ce58f938c2d7934dd040667ee8aa01f522f Mon Sep 17 00:00:00 2001 From: Mark Marlow Date: Fri, 16 Oct 2020 10:29:51 +1100 Subject: [PATCH] updated to have 1-6 microseconds (#314) --- tests/test_api.py | 12 ++++++++++++ toml/decoder.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/test_api.py b/tests/test_api.py index 67bcd88..c928e85 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -43,6 +43,18 @@ def test_bug_196(): assert round_trip_bug_dict == bug_dict assert round_trip_bug_dict['x'] == bug_dict['x'] +def test_bug_314(): + data = """12:34:56.1 1 +12:34:56.12 12 +12:34:56.123 123 +12:34:56.1234 1234 +12:34:56.12345 12345 +12:34:56.123456 123456 +12:34:56.1234567 123456""" + for line in data.splitlines(): + input_, expected = tuple(line.split(" ")) + decoded = toml.loads(f"a={input_}")['a'] + assert decoded.microsecond == int(expected) def test_valid_tests(): valid_dir = "toml-test/tests/valid/" diff --git a/toml/decoder.py b/toml/decoder.py index 3ec5b43..4f48ced 100644 --- a/toml/decoder.py +++ b/toml/decoder.py @@ -44,7 +44,7 @@ def _getpath(p): FNFError = IOError -TIME_RE = re.compile(r"([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]{3,6}))?") +TIME_RE = re.compile(r"([0-9]{2}):([0-9]{2}):([0-9]{2})(\.([0-9]{1,6}))?") class TomlDecodeError(ValueError):