forked from appliedsec/pygeoip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_thread.py
44 lines (34 loc) · 1.06 KB
/
test_thread.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import sys
import unittest
import threading
import pygeoip
from tests.config import COUNTRY_DB_PATH
class TestGeoIPThreading(unittest.TestCase):
def setUp(self):
self.gi = pygeoip.GeoIP(COUNTRY_DB_PATH)
def testCountryDatabase(self):
t1 = TestThread('us', '64.17.254.216', 'US', self)
t2 = TestThread('it', '78.26.70.208', 'IT', self)
t1.start()
t2.start()
t1.join()
t2.join()
if t1.exc_info:
raise t1.exc_info[1]
if t2.exc_info:
raise t2.exc_info[1]
class TestThread(threading.Thread):
def __init__(self, name, ip, code, test):
threading.Thread.__init__(self, name=name)
self.ip = ip
self.code = code
self.test = test
self.exc_info = None
def run(self):
try:
for i in range(1000):
code = self.test.gi.country_code_by_addr(self.ip)
self.test.assertEqual(code, self.code)
except AssertionError:
self.exc_info = sys.exc_info()