1
from twisted.trial import unittest
7
def fake_import(orig, name, *args, **kw):
8
##print "IMPORTING", name
10
raise ImportError('testing!')
11
return orig(*((name,) + args), **kw)
14
class TestImports(unittest.TestCase):
16
def test_no_GeoIP(self):
18
make sure the code we run if there's no GeoIP installed
19
doesn't do anything horrific
25
# attempt to ensure we've unimportted txtorcon.util
26
del sys.modules['txtorcon.util']
30
# replace global import with our test import, which will
31
# throw on GeoIP import no matter what
33
__builtins__['__import__'] = functools.partial(fake_import, orig)
35
# now ensure we set up all the databases as "None" when we
36
# import w/o the GeoIP thing available.
38
self.assertEqual(None, txtorcon.util.city)
39
self.assertEqual(None, txtorcon.util.asn)
40
self.assertEqual(None, txtorcon.util.country)