예제 #1
0
    def test_collection_get(self):
        """Ensure 'get' performs a key based lookup"""
        locations = LocationCollection(self.batch_response["results"])
        self.assertEqual(
            locations.get("3101 patterson ave, richmond, va").coords,
            (37.560890255102, -77.477400571429),
        )

        # Case sensitive on the specific query
        self.assertRaises(KeyError, locations.get, "3101 Patterson Ave, richmond, va")

        locations = LocationCollection(self.batch_reverse_response["results"])

        # The rendred query string value is acceptable
        self.assertEqual(
            locations.get("37.538758,-77.433594").coords, (37.538758, -77.433594)
        )
        # A tuple of floats is acceptable
        self.assertEqual(
            locations.get((37.538758, -77.433594)).coords, (37.538758, -77.433594)
        )
        # If it can be coerced to a float it is acceptable
        self.assertEqual(
            locations.get(("37.538758", "-77.433594")).coords, (37.538758, -77.433594)
        )

        # This is unacceptable
        self.assertRaises(ValueError, locations.get, ("37.538758 N", "-77.433594 W"))
예제 #2
0
    def test_collection_get(self):
        """Ensure 'get' performs a key based lookup"""
        locations = LocationCollection(self.batch_response["results"])
        self.assertEqual(
            locations.get("3101 patterson ave, richmond, va").coords,
            (37.560890255102, -77.477400571429),
        )

        # Case sensitive on the specific query
        self.assertRaises(KeyError, locations.get,
                          "3101 Patterson Ave, richmond, va")

        locations = LocationCollection(self.batch_reverse_response["results"])

        # The rendred query string value is acceptable
        self.assertEqual(
            locations.get("37.538758,-77.433594").coords,
            (37.538758, -77.433594))
        # A tuple of floats is acceptable
        self.assertEqual(
            locations.get((37.538758, -77.433594)).coords,
            (37.538758, -77.433594))
        # If it can be coerced to a float it is acceptable
        self.assertEqual(
            locations.get(("37.538758", "-77.433594")).coords,
            (37.538758, -77.433594))

        # This is unacceptable
        self.assertRaises(ValueError, locations.get,
                          ("37.538758 N", "-77.433594 W"))
예제 #3
0
    def test_collection_get(self):
        """Ensure 'get' performs a key based lookup"""
        locations = LocationCollection(self.batch_response["results"])
        self.assertEqual(
            locations.get("3101 patterson ave, richmond, va").coords,
            (37.560890255102, -77.477400571429),
        )

        locations = LocationCollection(
            self.batch_components_response["results"])
        self.assertEqual(
            locations.get({
                "street": "1109 N Highland St",
                "city": "Arlington",
                "state": "VA"
            }).coords, (38.886672, -77.094735))

        locations = LocationCollection(self.batch_reverse_response["results"])
        # The rendered query string value is acceptable
        self.assertEqual(
            locations.get("37.538758,-77.433594").coords,
            (37.538758, -77.433594))
        # A tuple of floats is acceptable
        self.assertEqual(
            locations.get((37.538758, -77.433594)).coords,
            (37.538758, -77.433594))
        # If it can be coerced to a float it is acceptable
        self.assertEqual(
            locations.get(("37.538758", "-77.433594")).coords,
            (37.538758, -77.433594))

        # This is unacceptable
        self.assertRaises(ValueError, locations.get,
                          ("37.538758 N", "-77.433594 W"))
예제 #4
0
 def test_collection_get(self):
     """Ensure 'get' performs a key based lookup"""
     locations = LocationCollection(self.batch_response)
     self.assertEqual(locations.get("3101 patterson ave, richmond, va").coords,
             (-77.477400571429, 37.560890255102))
     # Case sensitive on the specific query
     self.assertRaises(KeyError, locations.get,
             "3101 Patterson Ave, richmond, va")
예제 #5
0
    def test_collection_get_default(self):
        """Ensure 'get' returns default if key-based lookup fails without an error"""
        locations = LocationCollection(self.batch_response["results"])
        self.assertEqual(locations.get("wrong original query lookup"), None)

        locations = LocationCollection(
            self.batch_components_response["results"])
        self.assertEqual(
            locations.get(
                {
                    "street": "wrong street",
                    "city": "Arlington",
                    "state": "VA"
                }, "test"), "test")

        locations = LocationCollection(self.batch_reverse_response["results"])

        self.assertEqual(locations.get((5, 5), None), None)
        # If it can be coerced to a float it is acceptable
        self.assertEqual(locations.get(("-4", "-5"), 5), 5)

        # This is still unacceptable
        self.assertRaises(ValueError, locations.get,
                          ("37.538758 N", "-77.433594 W"))