diff options
author | Paul Ganssle <pganssle@users.noreply.github.com> | 2018-11-13 11:53:53 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-13 11:53:53 -0500 |
commit | f201daa40c9bda467ea516658d2c7658e83aadd7 (patch) | |
tree | 52fc869345f1c2ac7779aea61323894b8f77828c | |
parent | 04fe4bef3a83b2f3ace70dcb4a3409ccd0fbaa5f (diff) | |
parent | 25efbbea5735ef356c6f9782037aaa99d6522c1f (diff) | |
download | dateutil-f201daa40c9bda467ea516658d2c7658e83aadd7.tar.gz |
Merge pull request #839 from pganssle/test_fold_replace
Test fold replace
-rw-r--r-- | changelog.d/839.misc.rst | 1 | ||||
-rw-r--r-- | dateutil/test/test_tz.py | 36 |
2 files changed, 30 insertions, 7 deletions
diff --git a/changelog.d/839.misc.rst b/changelog.d/839.misc.rst new file mode 100644 index 0000000..258e61f --- /dev/null +++ b/changelog.d/839.misc.rst @@ -0,0 +1 @@ +Added some tests for _DatetimeWithFold to improve test coverage. diff --git a/dateutil/test/test_tz.py b/dateutil/test/test_tz.py index 97a0c68..386b909 100644 --- a/dateutil/test/test_tz.py +++ b/dateutil/test/test_tz.py @@ -2635,22 +2635,44 @@ class DatetimeExistsTest(unittest.TestCase): self.assertFalse(tz.datetime_exists(dt, tz=AEST)) -class EnfoldTest(unittest.TestCase): - def testEnterFoldDefault(self): +class TestEnfold: + def test_enter_fold_default(self): dt = tz.enfold(datetime(2020, 1, 19, 3, 32)) - self.assertEqual(dt.fold, 1) + assert dt.fold == 1 - def testEnterFold(self): + def test_enter_fold(self): dt = tz.enfold(datetime(2020, 1, 19, 3, 32), fold=1) - self.assertEqual(dt.fold, 1) + assert dt.fold == 1 - def testExitFold(self): + def test_exit_fold(self): dt = tz.enfold(datetime(2020, 1, 19, 3, 32), fold=0) # Before Python 3.6, dt.fold won't exist if fold is 0. - self.assertEqual(getattr(dt, 'fold', 0), 0) + assert getattr(dt, 'fold', 0) == 0 + + def test_defold(self): + dt = tz.enfold(datetime(2020, 1, 19, 3, 32), fold=1) + + dt2 = tz.enfold(dt, fold=0) + + assert getattr(dt2, 'fold', 0) == 0 + + def test_fold_replace_args(self): + # This test can be dropped when Python < 3.6 is dropped, since it + # is mainly to cover the `replace` method on _DatetimeWithFold + dt = tz.enfold(datetime(1950, 1, 2, 12, 30, 15, 8), fold=1) + + dt2 = dt.replace(1952, 2, 3, 13, 31, 16, 9) + assert dt2 == tz.enfold(datetime(1952, 2, 3, 13, 31, 16, 9), fold=1) + assert dt2.fold == 1 + + def test_fold_replace_exception_duplicate_args(self): + dt = tz.enfold(datetime(1999, 1, 3), fold=1) + + with pytest.raises(TypeError): + dt.replace(1950, year=2000) @pytest.mark.tz_resolve_imaginary |