From a7a1323dafdff989608c716f7333bdfb622c2711 Mon Sep 17 00:00:00 2001 From: Fan Huang Date: Sat, 23 Feb 2019 14:33:12 -0600 Subject: [PATCH 1/2] Fix isoparser test and coverage There is one bug here in the tests, which was detected when we saw that the coverage on the test files was less than 100%. This fixes the bug and also uses nocover pragmas for known-uncovered parts of the tests, so that the baseline is 100%. --- dateutil/test/test_isoparser.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/dateutil/test/test_isoparser.py b/dateutil/test/test_isoparser.py index ecd6e84a3..c7fa9b194 100644 --- a/dateutil/test/test_isoparser.py +++ b/dateutil/test/test_isoparser.py @@ -77,13 +77,13 @@ def _isoparse_date_and_time(dt, date_fmt, time_fmt, tzoffset, dtstr = dt.strftime(fmt) if microsecond_precision is not None: - if not fmt.endswith('%f'): + if not fmt.endswith('%f'): # pragma: nocover raise ValueError('Time format has no microseconds!') - if microsecond_precision != 6: + if microsecond_precision != 6: dtstr = dtstr[:-(6 - microsecond_precision)] - elif microsecond_precision > 6: - raise ValueError('Precision must be 1-6') + elif microsecond_precision > 6: # pragma: nocover + raise ValueError('Precision must be 1-6') dtstr += offset_str @@ -286,8 +286,8 @@ def test_iso_with_sep_raises(sep_act, valid_sep, exception): parser.isoparse(isostr) -@pytest.mark.xfail() -@pytest.mark.parametrize('isostr,exception', [ +@pytest.mark.xfail() +@pytest.mark.parametrize('isostr,exception', [ # pragma: nocover ('20120425T01:2000', ValueError), # Inconsistent time separators ]) def test_iso_raises_failing(isostr, exception): @@ -454,9 +454,9 @@ def __make_time_examples(): @pytest.mark.parametrize('as_bytes', [True, False]) def test_isotime(time_val, time_fmt, as_bytes): tstr = time_val.strftime(time_fmt) - if isinstance(time_val, six.text_type) and as_bytes: + if isinstance(tstr, six.text_type) and as_bytes: tstr = tstr.encode('ascii') - elif isinstance(time_val, bytes) and not as_bytes: + elif isinstance(tstr, bytes) and not as_bytes: tstr = tstr.decode('ascii') iparser = isoparser() @@ -505,8 +505,8 @@ def test_isotime_raises(isostr, exception): iparser.parse_isotime(isostr) -@pytest.mark.xfail() -@pytest.mark.parametrize('isostr,exception', [ +@pytest.mark.xfail() +@pytest.mark.parametrize('isostr,exception', [ # pragma: nocover ('14:3015', ValueError), # Inconsistent separator use ('201202', ValueError) # Invalid ISO format ]) From 69f788461c8bb250ad84f52d2ab20407e25d73be Mon Sep 17 00:00:00 2001 From: Fan Huang Date: Sat, 23 Feb 2019 15:32:33 -0600 Subject: [PATCH 2/2] Add Fan Huang to AUTHORS.md and changelog for #879 --- AUTHORS.md | 1 + changelog.d/879.misc.rst | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 changelog.d/879.misc.rst diff --git a/AUTHORS.md b/AUTHORS.md index 9d71a7251..fe02288c6 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -43,6 +43,7 @@ switch, and thus all their contributions are dual-licensed. - Dominik Kozaczko - Elliot Hughes (gh: @ElliotJH) **D** - Elvis Pranskevichus +- Fan Huang (gh: @fhuang5) **D** - Florian Rathgeber (gh: @kynan) **D** - Gabriel Bianconi (gh: @GabrielBianconi) **D** - Gabriel Poesia diff --git a/changelog.d/879.misc.rst b/changelog.d/879.misc.rst new file mode 100644 index 000000000..769623387 --- /dev/null +++ b/changelog.d/879.misc.rst @@ -0,0 +1,3 @@ +Fixed a minor bug in ``test_isoparser`` related to ``bytes``/``str`` handling. +Fixed by @fhuang5 (gh issue #776, gh pr #879) +