Browse Source

Setup unit tests

merge-requests/2/head
Lucidiot 3 years ago
parent
commit
6e9dafe516
No known key found for this signature in database GPG Key ID: AE3F7205692FA205
  1. 1
      setup.py
  2. 0
      urbantz/tests/__init__.py
  3. 63
      urbantz/tests/test_coordinates.py
  4. 5
      urbantz/utils.py

1
setup.py

@ -1,3 +1,4 @@
#!/usr/bin/env python3
from setuptools import setup, find_packages

0
urbantz/tests/__init__.py

63
urbantz/tests/test_coordinates.py

@ -0,0 +1,63 @@
from unittest import TestCase
from math import trunc, floor, ceil
from urbantz.utils import Coordinates
class TestCoordinates(TestCase):
"""
Unit tests for :class:`urbantz.utils.Coordinates`
"""
@classmethod
def setUpClass(cls):
cls.coords = Coordinates(lat=12.57, lng=-13.49)
def test_init(self):
self.assertEqual(self.coords.lat, 12.57)
self.assertEqual(self.coords.lng, -13.49)
def test_repr(self):
self.assertEqual(
repr(self.coords),
'Coordinates(lat=12.57, lng=-13.49)',
)
def test_str(self):
self.assertEqual(str(self.coords), '12.57, -13.49')
def test_hash(self):
self.assertEqual(hash(self.coords), hash((12.57, -13.49)))
def test_tuple(self):
self.assertTupleEqual(tuple(self.coords), (12.57, -13.49))
def test_len(self):
self.assertEqual(len(self.coords), 2)
def test_length_hint(self):
self.assertEqual(self.coords.__length_hint__(), 2)
def test_pos(self):
self.assertEqual(+self.coords, self.coords)
def test_neg(self):
self.assertTupleEqual(tuple(-self.coords), (-12.57, 13.49))
def test_abs(self):
self.assertTupleEqual(tuple(abs(self.coords)), (12.57, 13.49))
def test_round(self):
self.assertTupleEqual(tuple(round(self.coords)), (13, -13))
self.assertTupleEqual(tuple(round(self.coords, 1)), (12.6, -13.5))
def test_trunc(self):
self.assertTupleEqual(tuple(trunc(self.coords)), (12, -13))
def test_floor(self):
self.assertTupleEqual(tuple(floor(self.coords)), (12, -14))
def test_ceil(self):
self.assertTupleEqual(tuple(ceil(self.coords)), (13, -13))
def test_toJSON(self):
self.assertListEqual(self.coords.toJSON(), [-13.49, 12.57])

5
urbantz/utils.py

@ -23,7 +23,7 @@ class Coordinates(object):
self.__class__.__name__, self.lat, self.lng)
def __str__(self):
return ', '.join(tuple(self))
return ', '.join(map(str, tuple(self)))
def __hash__(self):
return hash(tuple(self))
@ -37,9 +37,6 @@ class Coordinates(object):
def __iter__(self):
return iter((self.lat, self.lng))
def __dict__(self):
return {'lat': self.lat, 'lng': self.lng}
def __eq__(self, other):
return hasattr(other, 'lat') and hasattr(other, 'lng') and \
tuple(self) == tuple(other)

Loading…
Cancel
Save