From f5f8ff7b8335cde962067632f088f49f14b30feb Mon Sep 17 00:00:00 2001 From: Christopher Brichford Date: Tue, 30 Jun 2015 16:54:06 -0700 Subject: [PATCH 1/4] Fix unit tests on python 2.6 and 2.7. --- pyzipcode/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyzipcode/__init__.py b/pyzipcode/__init__.py index da3b76b..0e4400e 100644 --- a/pyzipcode/__init__.py +++ b/pyzipcode/__init__.py @@ -16,7 +16,7 @@ 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: From ceb86c99fd24b8be1436d7311179fe6620f7bdda Mon Sep 17 00:00:00 2001 From: Christopher Brichford Date: Tue, 30 Jun 2015 17:19:11 -0700 Subject: [PATCH 2/4] Using relative import for settings. --- pyzipcode/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyzipcode/__init__.py b/pyzipcode/__init__.py index 0e4400e..295d8a8 100644 --- a/pyzipcode/__init__.py +++ b/pyzipcode/__init__.py @@ -1,4 +1,4 @@ -from settings import db_location +from .settings import db_location try: import sqlite3 except ImportError: From 6c9cfe19c5d27531bf89048bd31c1755517381e7 Mon Sep 17 00:00:00 2001 From: Christopher Brichford Date: Tue, 30 Jun 2015 16:43:44 -0700 Subject: [PATCH 3/4] pyhton3 fixes. --- pyzipcode/__init__.py | 2 +- pyzipcode/tests.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pyzipcode/__init__.py b/pyzipcode/__init__.py index 295d8a8..fb52771 100644 --- a/pyzipcode/__init__.py +++ b/pyzipcode/__init__.py @@ -24,7 +24,7 @@ def query(self, sql, args=tuple()): # 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) diff --git a/pyzipcode/tests.py b/pyzipcode/tests.py index bc50831..8f41865 100644 --- a/pyzipcode/tests.py +++ b/pyzipcode/tests.py @@ -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] @@ -24,11 +24,11 @@ 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) @@ -36,7 +36,7 @@ def test_radius(self): 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") From e15c7d0e87537095e3d50f27e60918de56b64e50 Mon Sep 17 00:00:00 2001 From: Luca Invernizzi Date: Thu, 16 Jul 2015 18:20:15 -0700 Subject: [PATCH 4/4] python 3 ready --- pyzipcode/import.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pyzipcode/import.py b/pyzipcode/import.py index f41eb24..757340b 100644 --- a/pyzipcode/import.py +++ b/pyzipcode/import.py @@ -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: