How to use uszipcode - 10 common examples

To help you get started, we’ve selected a few uszipcode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_init(self):
        z = Zipcode(Zipcode="10001")
        assert z.Zipcode == "10001"
        assert z.ZipcodeType is None
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_find_city(self):
        with ZipcodeSearchEngine() as search:
            city_result = search._find_city("phonix", best_match=True)
            city_expected = ["Phoenix", ]
            assert city_result == city_expected
             
            city_result = search._find_city("kerson", best_match=False)
            city_result.sort()
            city_expected = ["Dickerson", "Dickerson Run", "Emerson", "Ericson", "Everson", "Nickerson"]
            for city in city_result:
                assert city in city_expected
            
            city_result = search._find_city("kersen", state="kensas", best_match=False) 
            city_expected = ["Nickerson", ]
            assert city_result == city_expected
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_by_density(self):
        with ZipcodeSearchEngine() as search:
            res = search.by_density(lower=10000,
                                    sort_by="Density", ascending=False, returns=0)
            assert len(res) == 631
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_by_landarea(self):
        with ZipcodeSearchEngine() as search:
            res = search.by_landarea(lower=1000,
                                     sort_by="LandArea", ascending=False, returns=0)
            assert len(res) == 181
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_by_house(self):
        with ZipcodeSearchEngine() as search:
            res = search.by_house(lower=20000,
                                  sort_by="HouseOfUnits", ascending=False, returns=0)
            assert len(res) == 741
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_find(self):
        with ZipcodeSearchEngine() as search:
            # Find most people living zipcode in New York
            res = search.find(
                city="new york",
                sort_by="Population", ascending=False,
            )
            is_all_descending([z.Population for z in res])

            # Find all zipcode in California that prefix is "999"
            res = search.find(
                state="califor",
                prefix="95",
                sort_by="HouseOfUnits", ascending=False,
                returns=100,
            )
            assert len(res) == 100
            for z in res:
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_sql_create_lower_upper(self):
        with ZipcodeSearchEngine() as search:
            with pytest.raises(ValueError):
                sql = search._sql_create_lower_upper("Population", None, None)
            with pytest.raises(ValueError):
                sql = search._sql_create_lower_upper(
                    "Population", "SQL", "SQL")

            sql = search._sql_create_lower_upper("Population", 0, None)
            assert sql == "Population >= 0"

            sql = search._sql_create_lower_upper("Population", None, 999999)
            assert sql == "Population <= 999999"

            sql = search._sql_create_lower_upper("Population", 0, 999999)
            assert sql == "Population >= 0 AND Population <= 999999"
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_by_wealthy(self):
        with ZipcodeSearchEngine() as search:
            res = search.by_wealthy(lower=100000,
                                    sort_by="Wealthy", ascending=False, returns=0)
            assert len(res) == 41
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_by_prefix(self):
        """Test sort_by, ascending keyword.
        """
        with ZipcodeSearchEngine() as search:
            prefix = "208"
            sort_key = "Population"
            res = search.by_prefix(prefix,
                                   sort_by=sort_key, ascending=True, returns=0)
            l = list()
            for z in res:
                assert z.Zipcode.startswith(prefix)  # example prefix
                l.append(z[sort_key])
            l_sorted = list(l)
            l_sorted.sort()
            assert l == l_sorted

            res = search.by_prefix("100",
                                   sort_by=["Wealthy", ], ascending=[False, ])
github MacHu-GWU / uszipcode-project / tests / test_searchengine.py View on Github external
def test_sort_by_multiple_keywords(self):
        with ZipcodeSearchEngine() as search:
            res = search.by_state(
                state="CA", sort_by=["City", "Zipcode"], ascending=[True, True], returns=1000)

            stat = OrderedDict()
            for zipcode in res:
                try:
                    stat[zipcode.City].append(zipcode.Zipcode)
                except:
                    stat[zipcode.City] = [zipcode.Zipcode, ]

            city_list = list(stat.keys())
            is_all_ascending(city_list)
            for zipcode_list in stat.values():
                is_all_ascending(list(zipcode_list))