-
Notifications
You must be signed in to change notification settings - Fork 45
/
test.py
47 lines (38 loc) · 1.39 KB
/
test.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
45
46
47
# Copyright (C) 2005-2024 IP2Location.com
# All Rights Reserved
#
# This library is free software: you can redistribute it and/or
# modify it under the terms of the MIT license
import os
import sys
import IP2Location
database = IP2Location.IP2Location()
passed = 0
failed = 0
test_num = 0
database.open(os.path.join("data", "IP-COUNTRY.BIN"))
for line in open(os.path.join("data", "country_test_ipv4_data.txt")):
addr, country_short = line.strip().split()
rec = database.get_all(addr)
test_num += 1
if rec is not None:
if rec.country_short != country_short:
failed += 1
print("Test IP Address %s (Test %d) failed. We got %s but expected %s" \
% (addr, test_num, rec and rec.country_short or 'None', country_short))
else:
passed += 1
database.open(os.path.join("data", "IPV6-COUNTRY.BIN"))
for line in open(os.path.join("data", "country_test_ipv6_data.txt")):
addr, country_short = line.strip().split()
rec = database.get_all(addr)
test_num += 1
if rec is not None:
if rec.country_short != country_short:
failed += 1
print("Test IP Address %s (Test %d) failed. We got %s but expected %s" \
% (addr, test_num, rec and rec.country_short or 'None', country_short))
else:
passed += 1
print('PASS: %d' % (passed))
print('FAIL: %d' % (failed))