diff --git a/tests/unit/common/spatial/test_cartesian_point.py b/tests/unit/common/spatial/test_cartesian_point.py index 5ec40ac5e..8e22f1a9e 100644 --- a/tests/unit/common/spatial/test_cartesian_point.py +++ b/tests/unit/common/spatial/test_cartesian_point.py @@ -16,29 +16,29 @@ # limitations under the License. -from unittest import TestCase +import pytest from neo4j.spatial import CartesianPoint -class CartesianPointTestCase(TestCase): +class CartesianPointTestCase: def test_alias_3d(self): x, y, z = 3.2, 4.0, -1.2 p = CartesianPoint((x, y, z)) - self.assertTrue(hasattr(p, "x")) - self.assertEqual(p.x, x) - self.assertTrue(hasattr(p, "y")) - self.assertEqual(p.y, y) - self.assertTrue(hasattr(p, "z")) - self.assertEqual(p.z, z) + assert hasattr(p, "x") + assert p.x == x + assert hasattr(p, "y") + assert p.y == y + assert hasattr(p, "z") + assert p.z == z def test_alias_2d(self): x, y = 3.2, 4.0 p = CartesianPoint((x, y)) - self.assertTrue(hasattr(p, "x")) - self.assertEqual(p.x, x) - self.assertTrue(hasattr(p, "y")) - self.assertEqual(p.y, y) - with self.assertRaises(AttributeError): + assert hasattr(p, "x") + assert p.x == x + assert hasattr(p, "y") + assert p.y == y + with pytest.raises(AttributeError): p.z diff --git a/tests/unit/common/spatial/test_point.py b/tests/unit/common/spatial/test_point.py index 3122e2de3..5ede95716 100644 --- a/tests/unit/common/spatial/test_point.py +++ b/tests/unit/common/spatial/test_point.py @@ -16,7 +16,7 @@ # limitations under the License. -from unittest import TestCase +import pytest from neo4j._spatial import ( Point, @@ -24,29 +24,27 @@ ) -class PointTestCase(TestCase): +class PointTestCase: - def test_wrong_type_arguments(self): - for argument in (("a", "b"), ({"x": 1.0, "y": 2.0})): - with self.subTest(): - with self.assertRaises(ValueError): - Point(argument) + @pytest.mark.parametrize("argument", ("a", "b"), ({"x": 1.0, "y": 2.0})) + def test_wrong_type_arguments(self, argument): + with pytest.raises(ValueError): + Point(argument) - def test_number_arguments(self): - for argument in ((1, 2), (1.2, 2.1)): - with self.subTest(): - p = Point(argument) - assert tuple(p) == argument + @pytest.mark.parametrize("argument", (1, 2), (1.2, 2.1)) + def test_number_arguments(self, argument): + p = Point(argument) + assert tuple(p) == argument def test_immutable_coordinates(self): MyPoint = point_type("MyPoint", ["x", "y"], {2: 1234}) coordinates = (.1, 0) p = MyPoint(coordinates) - with self.assertRaises(AttributeError): + with pytest.raises(AttributeError): p.x = 2.0 - with self.assertRaises(AttributeError): + with pytest.raises(AttributeError): p.y = 2.0 - with self.assertRaises(TypeError): + with pytest.raises(TypeError): p[0] = 2.0 - with self.assertRaises(TypeError): + with pytest.raises(TypeError): p[1] = 2.0 diff --git a/tests/unit/common/spatial/test_wgs84_point.py b/tests/unit/common/spatial/test_wgs84_point.py index 540cfd2c4..aad72ab6c 100644 --- a/tests/unit/common/spatial/test_wgs84_point.py +++ b/tests/unit/common/spatial/test_wgs84_point.py @@ -16,47 +16,47 @@ # limitations under the License. -from unittest import TestCase +import pytest from neo4j.spatial import WGS84Point -class WGS84PointTestCase(TestCase): +class WGS84PointTestCase: def test_alias_3d(self): x, y, z = 3.2, 4.0, -1.2 p = WGS84Point((x, y, z)) - self.assertTrue(hasattr(p, "longitude")) - self.assertEqual(p.longitude, x) - self.assertTrue(hasattr(p, "x")) - self.assertEqual(p.x, x) + assert hasattr(p, "longitude") + assert p.longitude == x + assert hasattr(p, "x") + assert p.x == x - self.assertTrue(hasattr(p, "latitude")) - self.assertEqual(p.latitude, y) - self.assertTrue(hasattr(p, "y")) - self.assertEqual(p.y, y) + assert hasattr(p, "latitude") + assert p.latitude == y + assert hasattr(p, "y") + assert p.y == y - self.assertTrue(hasattr(p, "height")) - self.assertEqual(p.height, z) - self.assertTrue(hasattr(p, "z")) - self.assertEqual(p.z, z) + assert hasattr(p, "height") + assert p.height == z + assert hasattr(p, "z") + assert p.z == z def test_alias_2d(self): x, y = 3.2, 4.0 p = WGS84Point((x, y)) - self.assertTrue(hasattr(p, "longitude")) - self.assertEqual(p.longitude, x) - self.assertTrue(hasattr(p, "x")) - self.assertEqual(p.x, x) + assert hasattr(p, "longitude") + assert p.longitude == x + assert hasattr(p, "x") + assert p.x == x - self.assertTrue(hasattr(p, "latitude")) - self.assertEqual(p.latitude, y) - self.assertTrue(hasattr(p, "y")) - self.assertEqual(p.y, y) + assert hasattr(p, "latitude") + assert p.latitude == y + assert hasattr(p, "y") + assert p.y == y - with self.assertRaises(AttributeError): + with pytest.raises(AttributeError): p.height - with self.assertRaises(AttributeError): + with pytest.raises(AttributeError): p.z diff --git a/tests/unit/common/time/test_clock.py b/tests/unit/common/time/test_clock.py index f5fc41b8a..c9fba6caa 100644 --- a/tests/unit/common/time/test_clock.py +++ b/tests/unit/common/time/test_clock.py @@ -16,7 +16,7 @@ # limitations under the License. -from unittest import TestCase +import pytest from neo4j.time._clock_implementations import ( Clock, @@ -24,48 +24,48 @@ ) -class TestClock(TestCase): +class TestClock: def test_no_clock_implementations(self): try: Clock._Clock__implementations = [] - with self.assertRaises(RuntimeError): + with pytest.raises(RuntimeError): _ = Clock() finally: Clock._Clock__implementations = None def test_base_clock_precision(self): clock = object.__new__(Clock) - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): _ = clock.precision() def test_base_clock_available(self): clock = object.__new__(Clock) - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): _ = clock.available() def test_base_clock_utc_time(self): clock = object.__new__(Clock) - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): _ = clock.utc_time() def test_local_offset(self): clock = object.__new__(Clock) offset = clock.local_offset() - self.assertIsInstance(offset, ClockTime) + assert isinstance(offset, ClockTime) def test_local_time(self): _ = Clock() for impl in Clock._Clock__implementations: - self.assertTrue(issubclass(impl, Clock)) + assert issubclass(impl, Clock) clock = object.__new__(impl) time = clock.local_time() - self.assertIsInstance(time, ClockTime) + assert isinstance(time, ClockTime) def test_utc_time(self): _ = Clock() for impl in Clock._Clock__implementations: - self.assertTrue(issubclass(impl, Clock)) + assert issubclass(impl, Clock) clock = object.__new__(impl) time = clock.utc_time() - self.assertIsInstance(time, ClockTime) + assert isinstance(time, ClockTime) diff --git a/tests/unit/common/time/test_clocktime.py b/tests/unit/common/time/test_clocktime.py index 6c1c7842b..adb8554ca 100644 --- a/tests/unit/common/time/test_clocktime.py +++ b/tests/unit/common/time/test_clocktime.py @@ -16,7 +16,7 @@ # limitations under the License. -from unittest import TestCase +import pytest from neo4j.time import ( ClockTime, @@ -24,79 +24,79 @@ ) -class TestClockTime(TestCase): +class TestClockTime: def test_zero_(self): ct = ClockTime() - self.assertEqual(ct.seconds, 0) - self.assertEqual(ct.nanoseconds, 0) + assert ct.seconds == 0 + assert ct.nanoseconds == 0 def test_only_seconds(self): ct = ClockTime(123456) - self.assertEqual(ct.seconds, 123456) - self.assertEqual(ct.nanoseconds, 0) + assert ct.seconds == 123456 + assert ct.nanoseconds == 0 def test_float(self): ct = ClockTime(123456.789) - self.assertEqual(ct.seconds, 123456) - self.assertEqual(ct.nanoseconds, 789000000) + assert ct.seconds == 123456 + assert ct.nanoseconds == 789000000 def test_only_nanoseconds(self): ct = ClockTime(0, 123456789) - self.assertEqual(ct.seconds, 0) - self.assertEqual(ct.nanoseconds, 123456789) + assert ct.seconds == 0 + assert ct.nanoseconds == 123456789 def test_nanoseconds_overflow(self): ct = ClockTime(0, 2123456789) - self.assertEqual(ct.seconds, 2) - self.assertEqual(ct.nanoseconds, 123456789) + assert ct.seconds == 2 + assert ct.nanoseconds == 123456789 def test_positive_nanoseconds(self): ct = ClockTime(1, 1) - self.assertEqual(ct.seconds, 1) - self.assertEqual(ct.nanoseconds, 1) + assert ct.seconds == 1 + assert ct.nanoseconds == 1 def test_negative_nanoseconds(self): ct = ClockTime(1, -1) - self.assertEqual(ct.seconds, 0) - self.assertEqual(ct.nanoseconds, 999999999) + assert ct.seconds == 0 + assert ct.nanoseconds == 999999999 def test_add_float(self): ct = ClockTime(123456.789) + 0.1 - self.assertEqual(ct.seconds, 123456) - self.assertEqual(ct.nanoseconds, 889000000) + assert ct.seconds == 123456 + assert ct.nanoseconds == 889000000 def test_add_duration(self): ct = ClockTime(123456.789) + Duration(seconds=1) - self.assertEqual(ct.seconds, 123457) - self.assertEqual(ct.nanoseconds, 789000000) + assert ct.seconds == 123457 + assert ct.nanoseconds == 789000000 def test_add_duration_with_months(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = ClockTime(123456.789) + Duration(months=1) def test_add_object(self): - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = ClockTime(123456.789) + object() def test_sub_float(self): ct = ClockTime(123456.789) - 0.1 - self.assertEqual(ct.seconds, 123456) - self.assertEqual(ct.nanoseconds, 689000000) + assert ct.seconds == 123456 + assert ct.nanoseconds == 689000000 def test_sub_duration(self): ct = ClockTime(123456.789) - Duration(seconds=1) - self.assertEqual(ct.seconds, 123455) - self.assertEqual(ct.nanoseconds, 789000000) + assert ct.seconds == 123455 + assert ct.nanoseconds == 789000000 def test_sub_duration_with_months(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = ClockTime(123456.789) - Duration(months=1) def test_sub_object(self): - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = ClockTime(123456.789) - object() def test_repr(self): ct = ClockTime(123456.789) - self.assertTrue(repr(ct).startswith("ClockTime")) + assert repr(ct).startswith("ClockTime") diff --git a/tests/unit/common/time/test_date.py b/tests/unit/common/time/test_date.py index 4b8e4e761..f7d9c0c5e 100644 --- a/tests/unit/common/time/test_date.py +++ b/tests/unit/common/time/test_date.py @@ -20,7 +20,6 @@ import datetime from datetime import date from time import struct_time -from unittest import TestCase import pytest import pytz @@ -37,507 +36,512 @@ timezone_utc = pytz.utc -class TestDate(TestCase): +class TestDate: def test_bad_attribute(self): d = Date(2000, 1, 1) - with self.assertRaises(AttributeError): + with pytest.raises(AttributeError): _ = d.x def test_zero_date(self): d = Date(0, 0, 0) - self.assertEqual(d.year_month_day, (0, 0, 0)) - self.assertEqual(d.year, 0) - self.assertEqual(d.month, 0) - self.assertEqual(d.day, 0) - self.assertIs(d, ZeroDate) + assert d.year_month_day == (0, 0, 0) + assert d.year == 0 + assert d.month == 0 + assert d.day == 0 + assert d is ZeroDate def test_zero_ordinal(self): d = Date.from_ordinal(0) - self.assertEqual(d.year_month_day, (0, 0, 0)) - self.assertEqual(d.year, 0) - self.assertEqual(d.month, 0) - self.assertEqual(d.day, 0) - self.assertIs(d, ZeroDate) + assert d.year_month_day == (0, 0, 0) + assert d.year == 0 + assert d.month == 0 + assert d.day == 0 + assert d is ZeroDate def test_ordinal_at_start_of_1970(self): d = Date.from_ordinal(719163) - self.assertEqual(d.year_month_day, (1970, 1, 1)) - self.assertEqual(d.year, 1970) - self.assertEqual(d.month, 1) - self.assertEqual(d.day, 1) + assert d.year_month_day == (1970, 1, 1) + assert d.year == 1970 + assert d.month == 1 + assert d.day == 1 def test_ordinal_at_end_of_1969(self): d = Date.from_ordinal(719162) - self.assertEqual(d.year_month_day, (1969, 12, 31)) - self.assertEqual(d.year, 1969) - self.assertEqual(d.month, 12) - self.assertEqual(d.day, 31) + assert d.year_month_day == (1969, 12, 31) + assert d.year == 1969 + assert d.month == 12 + assert d.day == 31 def test_ordinal_at_start_of_2018(self): d = Date.from_ordinal(736695) - self.assertEqual(d.year_month_day, (2018, 1, 1)) - self.assertEqual(d.year, 2018) - self.assertEqual(d.month, 1) - self.assertEqual(d.day, 1) + assert d.year_month_day == (2018, 1, 1) + assert d.year == 2018 + assert d.month == 1 + assert d.day == 1 def test_ordinal_at_end_of_2017(self): d = Date.from_ordinal(736694) - self.assertEqual(d.year_month_day, (2017, 12, 31)) - self.assertEqual(d.year, 2017) - self.assertEqual(d.month, 12) - self.assertEqual(d.day, 31) + assert d.year_month_day == (2017, 12, 31) + assert d.year == 2017 + assert d.month == 12 + assert d.day == 31 def test_all_positive_days_of_month_for_31_day_month(self): for day in range(1, 32): t = Date(1976, 1, day) - self.assertEqual(t.year_month_day, (1976, 1, day)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 1) - self.assertEqual(t.day, day) - with self.assertRaises(ValueError): + assert t.year_month_day == (1976, 1, day) + assert t.year == 1976 + assert t.month == 1 + assert t.day == day + with pytest.raises(ValueError): _ = Date(1976, 1, 32) def test_all_positive_days_of_month_for_30_day_month(self): for day in range(1, 31): t = Date(1976, 6, day) - self.assertEqual(t.year_month_day, (1976, 6, day)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 6) - self.assertEqual(t.day, day) - with self.assertRaises(ValueError): + assert t.year_month_day == (1976, 6, day) + assert t.year == 1976 + assert t.month == 6 + assert t.day == day + with pytest.raises(ValueError): _ = Date(1976, 6, 31) def test_all_positive_days_of_month_for_29_day_month(self): for day in range(1, 30): t = Date(1976, 2, day) - self.assertEqual(t.year_month_day, (1976, 2, day)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 2) - self.assertEqual(t.day, day) - with self.assertRaises(ValueError): + assert t.year_month_day == (1976, 2, day) + assert t.year == 1976 + assert t.month == 2 + assert t.day == day + with pytest.raises(ValueError): _ = Date(1976, 2, 30) def test_all_positive_days_of_month_for_28_day_month(self): for day in range(1, 29): t = Date(1977, 2, day) - self.assertEqual(t.year_month_day, (1977, 2, day)) - self.assertEqual(t.year, 1977) - self.assertEqual(t.month, 2) - self.assertEqual(t.day, day) - with self.assertRaises(ValueError): + assert t.year_month_day == (1977, 2, day) + assert t.year == 1977 + assert t.month == 2 + assert t.day == day + with pytest.raises(ValueError): _ = Date(1977, 2, 29) def test_last_but_2_day_for_31_day_month(self): t = Date(1976, 1, -3) - self.assertEqual(t.year_month_day, (1976, 1, 29)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 1) - self.assertEqual(t.day, 29) + assert t.year_month_day == (1976, 1, 29) + assert t.year == 1976 + assert t.month == 1 + assert t.day == 29 def test_last_but_1_day_for_31_day_month(self): t = Date(1976, 1, -2) - self.assertEqual(t.year_month_day, (1976, 1, 30)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 1) - self.assertEqual(t.day, 30) + assert t.year_month_day == (1976, 1, 30) + assert t.year == 1976 + assert t.month == 1 + assert t.day == 30 def test_last_day_for_31_day_month(self): t = Date(1976, 1, -1) - self.assertEqual(t.year_month_day, (1976, 1, 31)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 1) - self.assertEqual(t.day, 31) + assert t.year_month_day == (1976, 1, 31) + assert t.year == 1976 + assert t.month == 1 + assert t.day == 31 def test_last_but_1_day_for_30_day_month(self): t = Date(1976, 6, -2) - self.assertEqual(t.year_month_day, (1976, 6, 29)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 6) - self.assertEqual(t.day, 29) + assert t.year_month_day == (1976, 6, 29) + assert t.year == 1976 + assert t.month == 6 + assert t.day == 29 def test_last_day_for_30_day_month(self): t = Date(1976, 6, -1) - self.assertEqual(t.year_month_day, (1976, 6, 30)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 6) - self.assertEqual(t.day, 30) + assert t.year_month_day == (1976, 6, 30) + assert t.year == 1976 + assert t.month == 6 + assert t.day == 30 def test_day_28_for_29_day_month(self): t = Date(1976, 2, 28) - self.assertEqual(t.year_month_day, (1976, 2, 28)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 2) - self.assertEqual(t.day, 28) + assert t.year_month_day == (1976, 2, 28) + assert t.year == 1976 + assert t.month == 2 + assert t.day == 28 def test_last_day_for_29_day_month(self): t = Date(1976, 2, -1) - self.assertEqual(t.year_month_day, (1976, 2, 29)) - self.assertEqual(t.year, 1976) - self.assertEqual(t.month, 2) - self.assertEqual(t.day, 29) + assert t.year_month_day == (1976, 2, 29) + assert t.year == 1976 + assert t.month == 2 + assert t.day == 29 def test_last_day_for_28_day_month(self): t = Date(1977, 2, -1) - self.assertEqual(t.year_month_day, (1977, 2, 28)) - self.assertEqual(t.year, 1977) - self.assertEqual(t.month, 2) - self.assertEqual(t.day, 28) + assert t.year_month_day == (1977, 2, 28) + assert t.year == 1977 + assert t.month == 2 + assert t.day == 28 def test_cannot_use_year_lower_than_one(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date(0, 2, 1) def test_cannot_use_year_higher_than_9999(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date(10000, 2, 1) def test_from_timestamp_without_tz(self): d = Date.from_timestamp(0) - self.assertEqual(d, Date(1970, 1, 1)) + assert d == Date(1970, 1, 1) def test_from_timestamp_with_tz(self): d = Date.from_timestamp(0, tz=timezone_eastern) - self.assertEqual(d, Date(1969, 12, 31)) + assert d == Date(1969, 12, 31) def test_utc_from_timestamp(self): d = Date.utc_from_timestamp(0) - self.assertEqual(d, Date(1970, 1, 1)) + assert d == Date(1970, 1, 1) def test_from_ordinal(self): d = Date.from_ordinal(1) - self.assertEqual(d, Date(1, 1, 1)) + assert d == Date(1, 1, 1) def test_parse(self): d = Date.parse("2018-04-30") - self.assertEqual(d, Date(2018, 4, 30)) + assert d == Date(2018, 4, 30) def test_bad_parse_1(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date.parse("30 April 2018") def test_bad_parse_2(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date.parse("2018-04") def test_bad_parse_3(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date.parse(object()) def test_replace(self): d1 = Date(2018, 4, 30) d2 = d1.replace(year=2017) - self.assertEqual(d2, Date(2017, 4, 30)) + assert d2 == Date(2017, 4, 30) def test_from_clock_time(self): d = Date.from_clock_time((0, 0), epoch=UnixEpoch) - self.assertEqual(d, Date(1970, 1, 1)) + assert d == Date(1970, 1, 1) def test_bad_from_clock_time(self): - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = Date.from_clock_time(object(), None) def test_is_leap_year(self): - self.assertTrue(Date.is_leap_year(2000)) - self.assertFalse(Date.is_leap_year(2001)) + assert Date.is_leap_year(2000) + assert not Date.is_leap_year(2001) def test_days_in_year(self): - self.assertEqual(Date.days_in_year(2000), 366) - self.assertEqual(Date.days_in_year(2001), 365) + assert Date.days_in_year(2000) == 366 + assert Date.days_in_year(2001) == 365 def test_days_in_month(self): - self.assertEqual(Date.days_in_month(2000, 1), 31) - self.assertEqual(Date.days_in_month(2000, 2), 29) - self.assertEqual(Date.days_in_month(2001, 2), 28) + assert Date.days_in_month(2000, 1) == 31 + assert Date.days_in_month(2000, 2) == 29 + assert Date.days_in_month(2001, 2) == 28 def test_instance_attributes(self): d = Date(2018, 4, 30) - self.assertEqual(d.year, 2018) - self.assertEqual(d.month, 4) - self.assertEqual(d.day, 30) - self.assertEqual(d.year_month_day, (2018, 4, 30)) - self.assertEqual(d.year_week_day, (2018, 18, 1)) - self.assertEqual(d.year_day, (2018, 120)) + assert d.year == 2018 + assert d.month == 4 + assert d.day == 30 + assert d.year_month_day == (2018, 4, 30) + assert d.year_week_day == (2018, 18, 1) + assert d.year_day == (2018, 120) def test_can_add_years(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(years=2) - self.assertEqual(d2, Date(1978, 6, 13)) + assert d2 == Date(1978, 6, 13) def test_can_add_negative_years(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(years=-2) - self.assertEqual(d2, Date(1974, 6, 13)) + assert d2 == Date(1974, 6, 13) def test_can_add_years_and_months(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(years=2, months=3) - self.assertEqual(d2, Date(1978, 9, 13)) + assert d2 == Date(1978, 9, 13) def test_can_add_negative_years_and_months(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(years=-2, months=-3) - self.assertEqual(d2, Date(1974, 3, 13)) + assert d2 == Date(1974, 3, 13) def test_can_retain_offset_from_end_of_month(self): d = Date(1976, 1, -1) - self.assertEqual(d, Date(1976, 1, 31)) + assert d == Date(1976, 1, 31) d += Duration(months=1) - self.assertEqual(d, Date(1976, 2, 29)) + assert d == Date(1976, 2, 29) d += Duration(months=1) - self.assertEqual(d, Date(1976, 3, 31)) + assert d == Date(1976, 3, 31) d += Duration(months=1) - self.assertEqual(d, Date(1976, 4, 30)) + assert d == Date(1976, 4, 30) d += Duration(months=1) - self.assertEqual(d, Date(1976, 5, 31)) + assert d == Date(1976, 5, 31) d += Duration(months=1) - self.assertEqual(d, Date(1976, 6, 30)) + assert d == Date(1976, 6, 30) def test_can_roll_over_end_of_year(self): d = Date(1976, 12, 1) - self.assertEqual(d, Date(1976, 12, 1)) + assert d == Date(1976, 12, 1) d += Duration(months=1) - self.assertEqual(d, Date(1977, 1, 1)) + assert d == Date(1977, 1, 1) def test_can_add_months_and_days(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(months=1, days=1) - self.assertEqual(d2, Date(1976, 7, 14)) + assert d2 == Date(1976, 7, 14) def test_can_add_months_then_days(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(months=1) + Duration(days=1) - self.assertEqual(d2, Date(1976, 7, 14)) + assert d2 == Date(1976, 7, 14) def test_cannot_add_seconds(self): d1 = Date(1976, 6, 13) - with self.assertRaises(ValueError): + with pytest.raises(ValueError): _ = d1 + Duration(seconds=1) def test_adding_empty_duration_returns_self(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration() - self.assertIs(d1, d2) + assert d1 is d2 def test_adding_object(self): d1 = Date(1976, 6, 13) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = d1 + object() def test_can_add_days_then_months(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(days=1) + Duration(months=1) - self.assertEqual(d2, Date(1976, 7, 14)) + assert d2 == Date(1976, 7, 14) def test_can_add_months_and_days_for_last_day_of_short_month(self): d1 = Date(1976, 6, 30) d2 = d1 + Duration(months=1, days=1) - self.assertEqual(d2, Date(1976, 8, 1)) + assert d2 == Date(1976, 8, 1) def test_can_add_months_then_days_for_last_day_of_short_month(self): d1 = Date(1976, 6, 30) d2 = d1 + Duration(months=1) + Duration(days=1) - self.assertEqual(d2, Date(1976, 8, 1)) + assert d2 == Date(1976, 8, 1) def test_can_add_days_then_months_for_last_day_of_short_month(self): d1 = Date(1976, 6, 30) d2 = d1 + Duration(days=1) + Duration(months=1) - self.assertEqual(d2, Date(1976, 8, 1)) + assert d2 == Date(1976, 8, 1) def test_can_add_months_and_days_for_last_day_of_long_month(self): d1 = Date(1976, 1, 31) d2 = d1 + Duration(months=1, days=1) - self.assertEqual(d2, Date(1976, 3, 1)) + assert d2 == Date(1976, 3, 1) def test_can_add_months_then_days_for_last_day_of_long_month(self): d1 = Date(1976, 1, 31) d2 = d1 + Duration(months=1) + Duration(days=1) - self.assertEqual(d2, Date(1976, 3, 1)) + assert d2 == Date(1976, 3, 1) def test_can_add_days_then_months_for_last_day_of_long_month(self): d1 = Date(1976, 1, 31) d2 = d1 + Duration(days=1) + Duration(months=1) - self.assertEqual(d2, Date(1976, 3, 1)) + assert d2 == Date(1976, 3, 1) def test_can_add_negative_months_and_days(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(months=-1, days=-1) - self.assertEqual(d2, Date(1976, 5, 12)) + assert d2 == Date(1976, 5, 12) def test_can_add_negative_months_then_days(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(months=-1) + Duration(days=-1) - self.assertEqual(d2, Date(1976, 5, 12)) + assert d2 == Date(1976, 5, 12) def test_can_add_negative_days_then_months(self): d1 = Date(1976, 6, 13) d2 = d1 + Duration(days=-1) + Duration(months=-1) - self.assertEqual(d2, Date(1976, 5, 12)) + assert d2 == Date(1976, 5, 12) def test_can_add_negative_months_and_days_for_first_day_of_month(self): d1 = Date(1976, 6, 1) d2 = d1 + Duration(months=-1, days=-1) - self.assertEqual(d2, Date(1976, 4, 30)) + assert d2 == Date(1976, 4, 30) def test_can_add_negative_months_then_days_for_first_day_of_month(self): d1 = Date(1976, 6, 1) d2 = d1 + Duration(months=-1) + Duration(days=-1) - self.assertEqual(d2, Date(1976, 4, 30)) + assert d2 == Date(1976, 4, 30) def test_can_add_negative_days_then_months_for_last_day_of_month(self): d1 = Date(1976, 6, 1) d2 = d1 + Duration(days=-1) + Duration(months=-1) - self.assertEqual(d2, Date(1976, 4, 30)) + assert d2 == Date(1976, 4, 30) def test_can_add_negative_month_for_last_day_of_long_month(self): d1 = Date(1976, 5, 31) d2 = d1 + Duration(months=-1) - self.assertEqual(d2, Date(1976, 4, 30)) + assert d2 == Date(1976, 4, 30) def test_can_add_negative_month_for_january(self): d1 = Date(1976, 1, 31) d2 = d1 + Duration(months=-1) - self.assertEqual(d2, Date(1975, 12, 31)) + assert d2 == Date(1975, 12, 31) def test_subtract_date(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertEqual(new_year - christmas, Duration(days=7)) + assert new_year - christmas == Duration(days=7) def test_subtract_duration(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertEqual(new_year - Duration(days=7), christmas) + assert new_year - Duration(days=7) == christmas def test_subtract_object(self): new_year = Date(2000, 1, 1) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = new_year - object() def test_date_less_than(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertLess(christmas, new_year) + assert christmas < new_year def test_date_less_than_object(self): d = Date(2000, 1, 1) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = d < object() def test_date_less_than_or_equal_to(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertLessEqual(christmas, new_year) + assert christmas <= new_year def test_date_less_than_or_equal_to_object(self): d = Date(2000, 1, 1) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = d <= object() def test_date_greater_than_or_equal_to(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertGreaterEqual(new_year, christmas) + assert new_year >= christmas def test_date_greater_than_or_equal_to_object(self): d = Date(2000, 1, 1) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = d >= object() def test_date_greater_than(self): new_year = Date(2000, 1, 1) christmas = Date(1999, 12, 25) - self.assertGreater(new_year, christmas) + assert new_year > christmas def test_date_greater_than_object(self): d = Date(2000, 1, 1) - with self.assertRaises(TypeError): + with pytest.raises(TypeError): _ = d > object() def test_date_equal(self): d1 = Date(2000, 1, 1) d2 = Date(2000, 1, 1) - self.assertEqual(d1, d2) + assert d1 == d2 def test_date_not_equal(self): d1 = Date(2000, 1, 1) d2 = Date(2000, 1, 2) - self.assertNotEqual(d1, d2) + assert d1 != d2 def test_date_not_equal_to_object(self): d1 = Date(2000, 1, 1) - self.assertNotEqual(d1, object()) + assert d1 != object() - def test_year_week_day(self): - for ordinal in range(Date(2001, 1, 1).to_ordinal(), Date(2008, 1, 1).to_ordinal()): - self.assertEqual(Date.from_ordinal(ordinal).iso_calendar(), date.fromordinal(ordinal).isocalendar()) + @pytest.mark.parametrize("ordinal", ( + Date(2001, 1, 1).to_ordinal(), + Date(2008, 1, 1).to_ordinal(), + )) + def test_year_week_day(self, ordinal): + assert Date.from_ordinal(ordinal).iso_calendar() \ + == date.fromordinal(ordinal).isocalendar() def test_time_tuple(self): d = Date(2018, 4, 30) - self.assertEqual(d.time_tuple(), struct_time((2018, 4, 30, 0, 0, 0, 0, 120, -1))) + expected = struct_time((2018, 4, 30, 0, 0, 0, 0, 120, -1)) + assert d.time_tuple() == expected def test_to_clock_time(self): d = Date(2018, 4, 30) - self.assertEqual(d.to_clock_time(UnixEpoch), (1525046400, 0)) - self.assertEqual(d.to_clock_time(d), (0, 0)) - with self.assertRaises(TypeError): + assert d.to_clock_time(UnixEpoch) == (1525046400, 0) + assert d.to_clock_time(d) == (0, 0) + with pytest.raises(TypeError): _ = d.to_clock_time(object()) def test_weekday(self): d = Date(2018, 4, 30) - self.assertEqual(d.weekday(), 0) + assert d.weekday() == 0 def test_iso_weekday(self): d = Date(2018, 4, 30) - self.assertEqual(d.iso_weekday(), 1) + assert d.iso_weekday() == 1 def test_str(self): - self.assertEqual(str(Date(2018, 4, 30)), "2018-04-30") - self.assertEqual(str(Date(0, 0, 0)), "0000-00-00") + assert str(Date(2018, 4, 30)) == "2018-04-30" + assert str(Date(0, 0, 0)) == "0000-00-00" def test_repr(self): - self.assertEqual(repr(Date(2018, 4, 30)), "neo4j.time.Date(2018, 4, 30)") - self.assertEqual(repr(Date(0, 0, 0)), "neo4j.time.ZeroDate") + assert repr(Date(2018, 4, 30)) == "neo4j.time.Date(2018, 4, 30)" + assert repr(Date(0, 0, 0)) == "neo4j.time.ZeroDate" def test_format(self): d = Date(2018, 4, 30) - with self.assertRaises(NotImplementedError): + with pytest.raises(NotImplementedError): _ = d.__format__("") def test_from_native(self): native = date(2018, 10, 1) d = Date.from_native(native) - self.assertEqual(d.year, native.year) - self.assertEqual(d.month, native.month) - self.assertEqual(d.day, native.day) + assert d.year == native.year + assert d.month == native.month + assert d.day == native.day def test_to_native(self): d = Date(2018, 10, 1) native = d.to_native() - self.assertEqual(d.year, native.year) - self.assertEqual(d.month, native.month) - self.assertEqual(d.day, native.day) + assert d.year == native.year + assert d.month == native.month + assert d.day == native.day def test_iso_format(self): d = Date(2018, 10, 1) - self.assertEqual("2018-10-01", d.iso_format()) + assert "2018-10-01" == d.iso_format() def test_from_iso_format(self): expected = Date(2018, 10, 1) actual = Date.from_iso_format("2018-10-01") - self.assertEqual(expected, actual) + assert expected == actual def test_date_copy(self): d = Date(2010, 10, 1) d2 = copy.copy(d) - self.assertIsNot(d, d2) - self.assertEqual(d, d2) + assert d is not d2 + assert d == d2 def test_date_deep_copy(self): d = Date(2010, 10, 1) d2 = copy.deepcopy(d) - self.assertIsNot(d, d2) - self.assertEqual(d, d2) + assert d is not d2 + assert d == d2 @pytest.mark.parametrize(("tz", "expected"), (