Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions tests/unit/common/spatial/test_cartesian_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 14 additions & 16 deletions tests/unit/common/spatial/test_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,35 @@
# limitations under the License.


from unittest import TestCase
import pytest

from neo4j._spatial import (
Point,
point_type,
)


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
48 changes: 24 additions & 24 deletions tests/unit/common/spatial/test_wgs84_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions tests/unit/common/time/test_clock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,56 @@
# limitations under the License.


from unittest import TestCase
import pytest

from neo4j.time._clock_implementations import (
Clock,
ClockTime,
)


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)
58 changes: 29 additions & 29 deletions tests/unit/common/time/test_clocktime.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,87 +16,87 @@
# limitations under the License.


from unittest import TestCase
import pytest

from neo4j.time import (
ClockTime,
Duration,
)


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")
Loading