diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index e2622e6..c83bf07 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +#!/usr/bin/env python3 from setuptools import setup, find_packages diff --git a/urbantz/tests/__init__.py b/urbantz/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/urbantz/tests/test_coordinates.py b/urbantz/tests/test_coordinates.py new file mode 100644 index 0000000..50f2712 --- /dev/null +++ b/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]) diff --git a/urbantz/utils.py b/urbantz/utils.py index d994a0e..49888d5 100644 --- a/urbantz/utils.py +++ b/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)