From 96fb2c5a8e5424acbbbd25a6fc74e3fdb87b1882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Thu, 4 Feb 2016 20:39:50 +0100 Subject: [PATCH] Add 1000 random tests --- tests/test_ip_to_geo.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/test_ip_to_geo.py b/tests/test_ip_to_geo.py index 2232fe6..f8604c2 100755 --- a/tests/test_ip_to_geo.py +++ b/tests/test_ip_to_geo.py @@ -1,12 +1,17 @@ #!/usr/bin/env python # -*- coding: utf-8 -from iptogeo import IPToGeo +import os +from iptogeo import IPToGeo, IPToGeoException iptogeo = IPToGeo() def test_ip(ip): - (ipres, country_code) = iptogeo.ip_to_geo(ip) + try: + (ipres, country_code) = iptogeo.ip_to_geo(ip) + except IPToGeoException, e: + print e + return if not country_code: print 'Country code for %s (%08x) not found' % (ip, ipres) @@ -22,3 +27,7 @@ test_ip('1.55.3.12') test_ip('1.57.0.0') +for i in range(0, 1000): + ip = '%d.%d.%d.%d' % \ + (ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1)), ord(os.urandom(1))) + test_ip(ip)