Пример #1
0
    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])
Пример #2
0
    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])
Пример #3
0
    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)
Пример #4
0
    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)
Пример #5
0
    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}})
Пример #6
0
    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}})
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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})
Пример #10
0
    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})