def test__max_weight__empty(self):
     """
     Tests max_weight with an empty LocationHits
     """
     hits = LocationHits(name='hits', locations=[])
     expected = -1
     actual = hits.max_weight()
     assert expected == actual
 def init(self, locations=[]):
     self.hits = LocationHits(name='testHits', locations=locations)
     return
class LocationHitsTestCase(unittest.TestCase):
    """
    Tests for app.geolocator.LocationHits
    """

    # ----------------------- Before/After ----------------------- #
    def setUp(self):
        """
        Executed at the start of every test
        """
        self.hits = None
        return

    def tearDown(self):
        """
        Executed at the end of every test
        """
        self.hits = None
        return

    # ----------------------- Helpers ----------------------- #
    def init(self, locations=[]):
        self.hits = LocationHits(name='testHits', locations=locations)
        return

    # ----------------------- Tests ----------------------- #
    def test__init__pass(self):
        """
        Ensures that the app.geolocator.LocationHits successfully initializes
        """
        LOCATIONS = ['apple', 'banana', 'orange']
        self.init(LOCATIONS)
        assert isinstance(self.hits, LocationHits)
        assert self.hits.index == -1
        assert self.hits.locations == LOCATIONS

    def test__iter__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.__iter__`
        """
        LOCATIONS = [1, 2, 3]
        self.init(LOCATIONS)
        self.hits.index = 7
        iterator = self.hits.__iter__()
        assert isinstance(iterator, LocationHits)
        assert iterator.index == -1
        assert iterator.locations == LOCATIONS

    def test__next__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.next`
        """
        LOCATIONS = [1, 2, 3]
        self.init(LOCATIONS)
        count = 0
        for i, l in enumerate(self.hits):
            assert l == LOCATIONS[i]
            count += 1
        assert count == len(LOCATIONS)

    def test__increment_weight_on_match__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.increment_weight_on_match`
        """
        loc = Location('Phoenix', 82.546, 36.111, 'phx')
        locwrap = LocationWrap(loc)
        s1 = LocationAdminNames(
            countryname='Jang',
            admin1name='Bob',
            admin2name=None,
            admin3name=None,
            admin4name=None)
        locwrap.set_adminnames(s1)
        loc2 = Location('Denver', 18.546, 44.111, 'den')
        locwrap2 = LocationWrap(loc2)
        s2 = s1
        locwrap2.set_adminnames(s2)
        l1 = [locwrap, locwrap2]
        self.init(l1)
        self.hits.increment_weight_on_match('Phoenix')

        f1 = self.hits.max_weight
        assert f1 != 1

    def test__len__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.__len__`
        """
        LOCATIONS = ['yes', 'no', 'maybe']
        expected = len(LOCATIONS)
        self.init(LOCATIONS)
        actual = len(self.hits)
        assert expected == actual

    def test__eq__fail_on_hits(self):
        """
        Tests __eq__ - fails on isinstance(other, LocationHits)
        """
        hits1 = LocationHits(name='hits1', locations=['l1', 'l2'])
        hits2 = 'not a LocationHits'
        assert hits1 != hits2

    def test__eq__fail_on_name(self):
        """
        Tests __eq__ - fails on name
        """
        hits1 = LocationHits(name='hits1', locations=['l1', 'l2'])
        hits2 = LocationHits(name='not hits1', locations=['l1', 'l2'])
        assert hits1 != hits2

    def test__eq__fail_on_locations(self):
        """
        Tests __eq__ - fails on locations
        """
        hits1 = LocationHits(name='hits1', locations=['l1', 'l2'])
        hits2 = LocationHits(name='hits1', locations=['l1', 'not l2'])
        assert hits1 != hits2

    def test__eq__pass(self):
        """
        Tests __eq__ expected to pass
        """
        hits1 = LocationHits(name='hits1', locations=['l1', 'l2'])
        hits2 = LocationHits(name='hits1', locations=['l1', 'l2'])
        assert hits1 == hits2

    def test__max_weight__empty(self):
        """
        Tests max_weight with an empty LocationHits
        """
        hits = LocationHits(name='hits', locations=[])
        expected = -1
        actual = hits.max_weight()
        assert expected == actual

    def test__repr__pass(self):
        """
        Tests :func:`app.geolocator.LocationHits.__repr__`
        """
        LOCATIONS = ['yes', 'no', 'maybe']
        self.init(LOCATIONS)
        s = str(self.hits)
        # any raised errors will cause test to fail
        assert s is not None
        assert len(s) > 10