Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_comparison(self):
assert Zipcode(zipcode="10001") < Zipcode(zipcode="10002")
assert Zipcode(zipcode="10002") <= Zipcode(zipcode="10002")
assert Zipcode(zipcode="10002") > Zipcode(zipcode="10001")
assert Zipcode(zipcode="10002") >= Zipcode(zipcode="10002")
assert Zipcode(zipcode="10001") == Zipcode(zipcode="10001")
assert Zipcode(zipcode="10001") != Zipcode(zipcode="10002")
with raises(ValueError):
Zipcode(zipcode="10001") < Zipcode()
with raises(ValueError):
Zipcode() < Zipcode(zipcode="10001")
def test_bool(self):
assert bool(Zipcode()) is False
assert bool(Zipcode(zipcode="10001")) is True
def test_comparison(self):
assert Zipcode(zipcode="10001") < Zipcode(zipcode="10002")
assert Zipcode(zipcode="10002") <= Zipcode(zipcode="10002")
assert Zipcode(zipcode="10002") > Zipcode(zipcode="10001")
assert Zipcode(zipcode="10002") >= Zipcode(zipcode="10002")
assert Zipcode(zipcode="10001") == Zipcode(zipcode="10001")
assert Zipcode(zipcode="10001") != Zipcode(zipcode="10002")
with raises(ValueError):
Zipcode(zipcode="10001") < Zipcode()
with raises(ValueError):
Zipcode() < Zipcode(zipcode="10001")
def test_hash(self):
assert hash(Zipcode()) != hash(Zipcode(zipcode="10001"))
def test_city(self):
z = Zipcode(major_city="New York")
assert z.major_city == z.city
def test_glance(self):
z = Zipcode(zipcode="10001")
z.glance()
def test_bool(self):
assert bool(Zipcode()) is False
assert bool(Zipcode(zipcode="10001")) is True
def test_state_attr(self):
z = Zipcode(state="ca")
assert z.state_abbr == "CA"
assert z.state_long == STATE_ABBR_SHORT_TO_LONG["CA"]
"""
Create simple_zipcode database from full data zipcode database.
"""
from sqlalchemy.orm import sessionmaker
from uszipcode.model import Base, Zipcode, SimpleZipcode, _simple_zipcode_columns
from uszipcode.db import connect_to_simple_zipcode_db, connect_to_zipcode_db
simple_zipcode_engine = connect_to_simple_zipcode_db()
Base.metadata.create_all(simple_zipcode_engine)
zipcode_engine = connect_to_zipcode_db()
zipcode_ses = sessionmaker(bind=zipcode_engine)()
selected_columns = [
getattr(Zipcode, name)
for name in _simple_zipcode_columns
]
simple_zipcode_data = list()
for data_tuple in zipcode_ses.query(*selected_columns):
simple_zipcode = SimpleZipcode(**dict(list(zip(_simple_zipcode_columns, data_tuple))))
simple_zipcode_data.append(simple_zipcode)
SimpleZipcode.smart_insert(simple_zipcode_engine, simple_zipcode_data)