Skip to content
This repository was archived by the owner on Oct 14, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pyzipcode/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from settings import db_location
from .settings import db_location
try:
import sqlite3
except ImportError:
Expand All @@ -16,15 +16,15 @@ def __init__(self):
conn = sqlite3.connect(db_location)
conn.close()

def query(self, sql, args):
def query(self, sql, args=tuple()):
conn = None
retry_count = 0
while not conn and retry_count <= 10:
# If there is trouble reading the file, retry for 10 attempts
# then just give up...
try:
conn = sqlite3.connect(db_location)
except sqlite3.OperationalError, x:
except sqlite3.OperationalError as x:
retry_count += 1
time.sleep(0.001)

Expand Down
6 changes: 4 additions & 2 deletions pyzipcode/import.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

from pysqlite2 import dbapi2 as sqlite3
try:
import sqlite3
except ImportError:
from pysqlite2 import dbapi2 as sqlite3
import os
import csv
try:
Expand Down
12 changes: 6 additions & 6 deletions pyzipcode/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def setUp(self):

def test_retrieves_zip_code_information(self):
zip = self.db['54115']
self.assertEquals(zip.zip, '54115')
self.assertEquals(zip.city, "De Pere")
self.assertEquals(zip.state, "WI")
self.assertEqual(zip.zip, '54115')
self.assertEqual(zip.city, "De Pere")
self.assertEqual(zip.state, "WI")

def test_correct_longitude_value(self):
zip = self.db[54115]
Expand All @@ -24,19 +24,19 @@ def test_correct_latitude_value(self):

def test_correct_timezone(self):
zip = self.db[54115]
self.assertEquals(zip.timezone, -6)
self.assertEqual(zip.timezone, -6)

def test_correct_dst(self):
zip = self.db[54115]
self.assertEquals(zip.dst, 1)
self.assertEqual(zip.dst, 1)

def test_radius(self):
zips = self.db.get_zipcodes_around_radius('54115', 30)
self.assertTrue('54304' in [zip.zip for zip in zips])

def test_find_zip_by_city(self):
zip = self.db.find_zip(city="De Pere")[0]
self.assertEquals('54115', zip.zip)
self.assertEqual('54115', zip.zip)

def test_find_zip_by_city_with_multiple_zips(self):
zips = self.db.find_zip(city="Green Bay")
Expand Down