def test_near_valueerror(self): """Test that `near()` raises `ValueError`.""" with self.assertRaises(ValueError): geo.near([1]) with self.assertRaises(ValueError): geo.near([1, 2, 3])
def test_near(self): """Test the `near()` method.""" expected = {'$near': [1, 2]} actual = geo.near([1, 2]) self.assertEqual(actual, expected) expected = {'$near': [1, 2], '$maxDistance': 3} actual = geo.near([1, 2], max_distance=3) self.assertEqual(actual, expected) expected = {'$near': [1, 2], '$uniqueDocs': True} actual = geo.near([1, 2], unique_docs=True) self.assertEqual(actual, expected) expected = {'$near': [1, 2], '$maxDistance': 3, '$uniqueDocs': True} actual = geo.near([1, 2], max_distance=3, unique_docs=True) self.assertEqual(actual, expected) # near() supports point as a tuple expected = {'$near': (1, 2)} actual = geo.near((1, 2)) self.assertEqual(actual, expected)
def test_near_typeerror(self): """Test that `near()` raises `TypeError`.""" with self.assertRaises(TypeError): geo.near(1)