def test_polygon_valueerror(self): """Test that `polygon()` raises `ValueError`.""" with self.assertRaises(ValueError): geo.polygon([1, 2], [3]) with self.assertRaises(ValueError): geo.polygon([1, 2], [3, 4, 5])
def test_polygon_typeerror(self): """Test that `polygon()` raises `TypeError`.""" with self.assertRaises(TypeError): geo.polygon() with self.assertRaises(TypeError): geo.polygon(1) with self.assertRaises(TypeError): geo.polygon([1]) with self.assertRaises(TypeError): geo.polygon([1, 2, 3]) with self.assertRaises(TypeError): geo.polygon([1, 2], 3)
def test_polygon_mappings_valueerror(self): """Test that `polygon()` raises `ValueError` with mappings.""" with self.assertRaises(ValueError): geo.polygon({'a': 1}) with self.assertRaises(ValueError): geo.polygon({'a': {'b': 1}}) with self.assertRaises(ValueError): geo.polygon({'a': {'b': 1, 'c': 2}}) with self.assertRaises(ValueError): geo.polygon({'a': {'b': 1, 'c': 2}, 'd': {'e': 3}})
def test_polygon(self): """Test the `polygon()` method.""" with mock.patch('simon.geo.within') as within: geo.polygon([1, 2], [3, 4], [5, 6]) within.assert_called_with('polygon', [1, 2], [3, 4], [5, 6]) geo.polygon({'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}}) within.assert_called_with('polygon', a={'x': 1, 'y': 2}, b={'x': 3, 'y': 4}) expected = {'$within': {'$polygon': [[1, 2], [3, 4], [5, 6]]}} actual = geo.polygon([1, 2], [3, 4], [5, 6]) self.assertEqual(actual, expected) expected = {'$within': {'$polygon': {'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}}}} actual = geo.polygon({'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}}) self.assertEqual(actual, expected)
def test_polygon(self): """Test the `polygon()` method.""" with mock.patch('simon.geo.within') as within: geo.polygon([1, 2], [3, 4], [5, 6]) within.assert_called_with('polygon', [1, 2], [3, 4], [5, 6]) geo.polygon({'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}}) within.assert_called_with('polygon', a={ 'x': 1, 'y': 2 }, b={ 'x': 3, 'y': 4 }) expected = {'$within': {'$polygon': [[1, 2], [3, 4], [5, 6]]}} actual = geo.polygon([1, 2], [3, 4], [5, 6]) self.assertEqual(actual, expected) expected = { '$within': { '$polygon': { 'a': { 'x': 1, 'y': 2 }, 'b': { 'x': 3, 'y': 4 } } } } actual = geo.polygon({'a': {'x': 1, 'y': 2}, 'b': {'x': 3, 'y': 4}}) self.assertEqual(actual, expected)
def test_polygon_mappings_typeerror(self): """Test that `polygon()` raises `TypeError` with mappings.""" with self.assertRaises(TypeError): geo.polygon({'a': {'b': 1, 'c': 2}, 'd': 3})