Commit da3be8ac by William Tisäter

Increase test coverage

parent 6015ddaa
...@@ -29,7 +29,7 @@ from threading import Lock ...@@ -29,7 +29,7 @@ from threading import Lock
try: try:
import mmap import mmap
except ImportError: except ImportError: # pragma: no cover
mmap = None mmap = None
try: try:
...@@ -99,7 +99,7 @@ class GeoIP(object): ...@@ -99,7 +99,7 @@ class GeoIP(object):
""" """
self._flags = flags self._flags = flags
if self._flags & const.MMAP_CACHE and mmap is None: if self._flags & const.MMAP_CACHE and mmap is None: # pragma: no cover
import warnings import warnings
warnings.warn("MMAP_CACHE cannot be used without a mmap module") warnings.warn("MMAP_CACHE cannot be used without a mmap module")
self._flags &= ~const.MMAP_CACHE self._flags &= ~const.MMAP_CACHE
......
...@@ -9,3 +9,4 @@ CITY_DB_PATH = path.join(DATA_DIR, 'GeoLiteCity.dat') ...@@ -9,3 +9,4 @@ CITY_DB_PATH = path.join(DATA_DIR, 'GeoLiteCity.dat')
ORG_DB_PATH = path.join(DATA_DIR, 'GeoIPOrg.dat') ORG_DB_PATH = path.join(DATA_DIR, 'GeoIPOrg.dat')
ASNUM_DB_PATH = path.join(DATA_DIR, 'GeoIPASNum.dat') ASNUM_DB_PATH = path.join(DATA_DIR, 'GeoIPASNum.dat')
ISP_DB_PATH = path.join(DATA_DIR, 'GeoIPISP.dat') ISP_DB_PATH = path.join(DATA_DIR, 'GeoIPISP.dat')
CORRUPT_DB_PATH = path.join(DATA_DIR, '../config.py')
...@@ -5,7 +5,7 @@ from nose.tools import raises ...@@ -5,7 +5,7 @@ from nose.tools import raises
import pygeoip import pygeoip
from pygeoip import const from pygeoip import const
from tests.config import COUNTRY_DB_PATH from tests.config import COUNTRY_DB_PATH, CORRUPT_DB_PATH
class TestGenerals(unittest.TestCase): class TestGenerals(unittest.TestCase):
def testContructing(self): def testContructing(self):
...@@ -17,6 +17,16 @@ class TestGenerals(unittest.TestCase): ...@@ -17,6 +17,16 @@ class TestGenerals(unittest.TestCase):
assert len(const.COUNTRY_CODES) == len(const.COUNTRY_NAMES) assert len(const.COUNTRY_CODES) == len(const.COUNTRY_NAMES)
assert len(const.COUNTRY_CODES) == len(const.CONTINENT_NAMES) assert len(const.COUNTRY_CODES) == len(const.CONTINENT_NAMES)
def testMetaclass(self):
a = pygeoip.GeoIP(filename=COUNTRY_DB_PATH)
b = pygeoip.GeoIP(filename=COUNTRY_DB_PATH)
assert a is b
@raises(pygeoip.GeoIPError)
def testCorruptDatabase(self):
gi = pygeoip.GeoIP(filename=CORRUPT_DB_PATH)
gi.country_code_by_name('google.com')
@raises(socket.gaierror) @raises(socket.gaierror)
def testFailedLookup(self): def testFailedLookup(self):
gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH) gi = pygeoip.GeoIP(filename=COUNTRY_DB_PATH)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment