Skip to content

Commit e29e042

Browse files
Finish migration from unittest to pytest (#766)
1 parent a6c8765 commit e29e042

File tree

6 files changed

+274
-272
lines changed

6 files changed

+274
-272
lines changed

tests/unit/common/spatial/test_cartesian_point.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@
1616
# limitations under the License.
1717

1818

19-
from unittest import TestCase
19+
import pytest
2020

2121
from neo4j.spatial import CartesianPoint
2222

2323

24-
class CartesianPointTestCase(TestCase):
24+
class CartesianPointTestCase:
2525

2626
def test_alias_3d(self):
2727
x, y, z = 3.2, 4.0, -1.2
2828
p = CartesianPoint((x, y, z))
29-
self.assertTrue(hasattr(p, "x"))
30-
self.assertEqual(p.x, x)
31-
self.assertTrue(hasattr(p, "y"))
32-
self.assertEqual(p.y, y)
33-
self.assertTrue(hasattr(p, "z"))
34-
self.assertEqual(p.z, z)
29+
assert hasattr(p, "x")
30+
assert p.x == x
31+
assert hasattr(p, "y")
32+
assert p.y == y
33+
assert hasattr(p, "z")
34+
assert p.z == z
3535

3636
def test_alias_2d(self):
3737
x, y = 3.2, 4.0
3838
p = CartesianPoint((x, y))
39-
self.assertTrue(hasattr(p, "x"))
40-
self.assertEqual(p.x, x)
41-
self.assertTrue(hasattr(p, "y"))
42-
self.assertEqual(p.y, y)
43-
with self.assertRaises(AttributeError):
39+
assert hasattr(p, "x")
40+
assert p.x == x
41+
assert hasattr(p, "y")
42+
assert p.y == y
43+
with pytest.raises(AttributeError):
4444
p.z

tests/unit/common/spatial/test_point.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,35 @@
1616
# limitations under the License.
1717

1818

19-
from unittest import TestCase
19+
import pytest
2020

2121
from neo4j._spatial import (
2222
Point,
2323
point_type,
2424
)
2525

2626

27-
class PointTestCase(TestCase):
27+
class PointTestCase:
2828

29-
def test_wrong_type_arguments(self):
30-
for argument in (("a", "b"), ({"x": 1.0, "y": 2.0})):
31-
with self.subTest():
32-
with self.assertRaises(ValueError):
33-
Point(argument)
29+
@pytest.mark.parametrize("argument", ("a", "b"), ({"x": 1.0, "y": 2.0}))
30+
def test_wrong_type_arguments(self, argument):
31+
with pytest.raises(ValueError):
32+
Point(argument)
3433

35-
def test_number_arguments(self):
36-
for argument in ((1, 2), (1.2, 2.1)):
37-
with self.subTest():
38-
p = Point(argument)
39-
assert tuple(p) == argument
34+
@pytest.mark.parametrize("argument", (1, 2), (1.2, 2.1))
35+
def test_number_arguments(self, argument):
36+
p = Point(argument)
37+
assert tuple(p) == argument
4038

4139
def test_immutable_coordinates(self):
4240
MyPoint = point_type("MyPoint", ["x", "y"], {2: 1234})
4341
coordinates = (.1, 0)
4442
p = MyPoint(coordinates)
45-
with self.assertRaises(AttributeError):
43+
with pytest.raises(AttributeError):
4644
p.x = 2.0
47-
with self.assertRaises(AttributeError):
45+
with pytest.raises(AttributeError):
4846
p.y = 2.0
49-
with self.assertRaises(TypeError):
47+
with pytest.raises(TypeError):
5048
p[0] = 2.0
51-
with self.assertRaises(TypeError):
49+
with pytest.raises(TypeError):
5250
p[1] = 2.0

tests/unit/common/spatial/test_wgs84_point.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,47 @@
1616
# limitations under the License.
1717

1818

19-
from unittest import TestCase
19+
import pytest
2020

2121
from neo4j.spatial import WGS84Point
2222

2323

24-
class WGS84PointTestCase(TestCase):
24+
class WGS84PointTestCase:
2525

2626
def test_alias_3d(self):
2727
x, y, z = 3.2, 4.0, -1.2
2828
p = WGS84Point((x, y, z))
2929

30-
self.assertTrue(hasattr(p, "longitude"))
31-
self.assertEqual(p.longitude, x)
32-
self.assertTrue(hasattr(p, "x"))
33-
self.assertEqual(p.x, x)
30+
assert hasattr(p, "longitude")
31+
assert p.longitude == x
32+
assert hasattr(p, "x")
33+
assert p.x == x
3434

35-
self.assertTrue(hasattr(p, "latitude"))
36-
self.assertEqual(p.latitude, y)
37-
self.assertTrue(hasattr(p, "y"))
38-
self.assertEqual(p.y, y)
35+
assert hasattr(p, "latitude")
36+
assert p.latitude == y
37+
assert hasattr(p, "y")
38+
assert p.y == y
3939

40-
self.assertTrue(hasattr(p, "height"))
41-
self.assertEqual(p.height, z)
42-
self.assertTrue(hasattr(p, "z"))
43-
self.assertEqual(p.z, z)
40+
assert hasattr(p, "height")
41+
assert p.height == z
42+
assert hasattr(p, "z")
43+
assert p.z == z
4444

4545
def test_alias_2d(self):
4646
x, y = 3.2, 4.0
4747
p = WGS84Point((x, y))
4848

49-
self.assertTrue(hasattr(p, "longitude"))
50-
self.assertEqual(p.longitude, x)
51-
self.assertTrue(hasattr(p, "x"))
52-
self.assertEqual(p.x, x)
49+
assert hasattr(p, "longitude")
50+
assert p.longitude == x
51+
assert hasattr(p, "x")
52+
assert p.x == x
5353

54-
self.assertTrue(hasattr(p, "latitude"))
55-
self.assertEqual(p.latitude, y)
56-
self.assertTrue(hasattr(p, "y"))
57-
self.assertEqual(p.y, y)
54+
assert hasattr(p, "latitude")
55+
assert p.latitude == y
56+
assert hasattr(p, "y")
57+
assert p.y == y
5858

59-
with self.assertRaises(AttributeError):
59+
with pytest.raises(AttributeError):
6060
p.height
61-
with self.assertRaises(AttributeError):
61+
with pytest.raises(AttributeError):
6262
p.z

tests/unit/common/time/test_clock.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,56 @@
1616
# limitations under the License.
1717

1818

19-
from unittest import TestCase
19+
import pytest
2020

2121
from neo4j.time._clock_implementations import (
2222
Clock,
2323
ClockTime,
2424
)
2525

2626

27-
class TestClock(TestCase):
27+
class TestClock:
2828

2929
def test_no_clock_implementations(self):
3030
try:
3131
Clock._Clock__implementations = []
32-
with self.assertRaises(RuntimeError):
32+
with pytest.raises(RuntimeError):
3333
_ = Clock()
3434
finally:
3535
Clock._Clock__implementations = None
3636

3737
def test_base_clock_precision(self):
3838
clock = object.__new__(Clock)
39-
with self.assertRaises(NotImplementedError):
39+
with pytest.raises(NotImplementedError):
4040
_ = clock.precision()
4141

4242
def test_base_clock_available(self):
4343
clock = object.__new__(Clock)
44-
with self.assertRaises(NotImplementedError):
44+
with pytest.raises(NotImplementedError):
4545
_ = clock.available()
4646

4747
def test_base_clock_utc_time(self):
4848
clock = object.__new__(Clock)
49-
with self.assertRaises(NotImplementedError):
49+
with pytest.raises(NotImplementedError):
5050
_ = clock.utc_time()
5151

5252
def test_local_offset(self):
5353
clock = object.__new__(Clock)
5454
offset = clock.local_offset()
55-
self.assertIsInstance(offset, ClockTime)
55+
assert isinstance(offset, ClockTime)
5656

5757
def test_local_time(self):
5858
_ = Clock()
5959
for impl in Clock._Clock__implementations:
60-
self.assertTrue(issubclass(impl, Clock))
60+
assert issubclass(impl, Clock)
6161
clock = object.__new__(impl)
6262
time = clock.local_time()
63-
self.assertIsInstance(time, ClockTime)
63+
assert isinstance(time, ClockTime)
6464

6565
def test_utc_time(self):
6666
_ = Clock()
6767
for impl in Clock._Clock__implementations:
68-
self.assertTrue(issubclass(impl, Clock))
68+
assert issubclass(impl, Clock)
6969
clock = object.__new__(impl)
7070
time = clock.utc_time()
71-
self.assertIsInstance(time, ClockTime)
71+
assert isinstance(time, ClockTime)

tests/unit/common/time/test_clocktime.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,87 +16,87 @@
1616
# limitations under the License.
1717

1818

19-
from unittest import TestCase
19+
import pytest
2020

2121
from neo4j.time import (
2222
ClockTime,
2323
Duration,
2424
)
2525

2626

27-
class TestClockTime(TestCase):
27+
class TestClockTime:
2828

2929
def test_zero_(self):
3030
ct = ClockTime()
31-
self.assertEqual(ct.seconds, 0)
32-
self.assertEqual(ct.nanoseconds, 0)
31+
assert ct.seconds == 0
32+
assert ct.nanoseconds == 0
3333

3434
def test_only_seconds(self):
3535
ct = ClockTime(123456)
36-
self.assertEqual(ct.seconds, 123456)
37-
self.assertEqual(ct.nanoseconds, 0)
36+
assert ct.seconds == 123456
37+
assert ct.nanoseconds == 0
3838

3939
def test_float(self):
4040
ct = ClockTime(123456.789)
41-
self.assertEqual(ct.seconds, 123456)
42-
self.assertEqual(ct.nanoseconds, 789000000)
41+
assert ct.seconds == 123456
42+
assert ct.nanoseconds == 789000000
4343

4444
def test_only_nanoseconds(self):
4545
ct = ClockTime(0, 123456789)
46-
self.assertEqual(ct.seconds, 0)
47-
self.assertEqual(ct.nanoseconds, 123456789)
46+
assert ct.seconds == 0
47+
assert ct.nanoseconds == 123456789
4848

4949
def test_nanoseconds_overflow(self):
5050
ct = ClockTime(0, 2123456789)
51-
self.assertEqual(ct.seconds, 2)
52-
self.assertEqual(ct.nanoseconds, 123456789)
51+
assert ct.seconds == 2
52+
assert ct.nanoseconds == 123456789
5353

5454
def test_positive_nanoseconds(self):
5555
ct = ClockTime(1, 1)
56-
self.assertEqual(ct.seconds, 1)
57-
self.assertEqual(ct.nanoseconds, 1)
56+
assert ct.seconds == 1
57+
assert ct.nanoseconds == 1
5858

5959
def test_negative_nanoseconds(self):
6060
ct = ClockTime(1, -1)
61-
self.assertEqual(ct.seconds, 0)
62-
self.assertEqual(ct.nanoseconds, 999999999)
61+
assert ct.seconds == 0
62+
assert ct.nanoseconds == 999999999
6363

6464
def test_add_float(self):
6565
ct = ClockTime(123456.789) + 0.1
66-
self.assertEqual(ct.seconds, 123456)
67-
self.assertEqual(ct.nanoseconds, 889000000)
66+
assert ct.seconds == 123456
67+
assert ct.nanoseconds == 889000000
6868

6969
def test_add_duration(self):
7070
ct = ClockTime(123456.789) + Duration(seconds=1)
71-
self.assertEqual(ct.seconds, 123457)
72-
self.assertEqual(ct.nanoseconds, 789000000)
71+
assert ct.seconds == 123457
72+
assert ct.nanoseconds == 789000000
7373

7474
def test_add_duration_with_months(self):
75-
with self.assertRaises(ValueError):
75+
with pytest.raises(ValueError):
7676
_ = ClockTime(123456.789) + Duration(months=1)
7777

7878
def test_add_object(self):
79-
with self.assertRaises(TypeError):
79+
with pytest.raises(TypeError):
8080
_ = ClockTime(123456.789) + object()
8181

8282
def test_sub_float(self):
8383
ct = ClockTime(123456.789) - 0.1
84-
self.assertEqual(ct.seconds, 123456)
85-
self.assertEqual(ct.nanoseconds, 689000000)
84+
assert ct.seconds == 123456
85+
assert ct.nanoseconds == 689000000
8686

8787
def test_sub_duration(self):
8888
ct = ClockTime(123456.789) - Duration(seconds=1)
89-
self.assertEqual(ct.seconds, 123455)
90-
self.assertEqual(ct.nanoseconds, 789000000)
89+
assert ct.seconds == 123455
90+
assert ct.nanoseconds == 789000000
9191

9292
def test_sub_duration_with_months(self):
93-
with self.assertRaises(ValueError):
93+
with pytest.raises(ValueError):
9494
_ = ClockTime(123456.789) - Duration(months=1)
9595

9696
def test_sub_object(self):
97-
with self.assertRaises(TypeError):
97+
with pytest.raises(TypeError):
9898
_ = ClockTime(123456.789) - object()
9999

100100
def test_repr(self):
101101
ct = ClockTime(123456.789)
102-
self.assertTrue(repr(ct).startswith("ClockTime"))
102+
assert repr(ct).startswith("ClockTime")

0 commit comments

Comments
 (0)