[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [bridgedb/master] Make unit test use ipaddress instead of ipaddr.



commit d035088f8eaa8ac7d0d0616b3e680c808a76e33b
Author: Philipp Winter <phw@xxxxxxxxx>
Date:   Wed Jan 29 18:22:18 2020 -0800

    Make unit test use ipaddress instead of ipaddr.
    
    This should fix the following unit test:
    
    [FAIL]
    Traceback (most recent call last):
      File "/home/travis/build/NullHypothesis/bridgedb/bridgedb/test/test_https.py", line 227, in test_get_vanilla_ipv6
        self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)
      File "/home/travis/virtualenv/python3.7.1/lib/python3.7/site-packages/twisted/trial/_synctest.py", line 649, in assertIsInstance
        instance, classOrTuple, suffix))
    twisted.trial.unittest.FailTest: IPv4Address('98.255.18.132') is not an instance of <class 'ipaddr.IPv6Address'>
---
 bridgedb/test/test_https.py        |  6 +++---
 bridgedb/test/test_https_server.py | 12 ++++++------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/bridgedb/test/test_https.py b/bridgedb/test/test_https.py
index 00a6fd9..2349e28 100644
--- a/bridgedb/test/test_https.py
+++ b/bridgedb/test/test_https.py
@@ -27,7 +27,7 @@ repository.
 from __future__ import print_function
 
 import gettext
-import ipaddr
+import ipaddress
 import mechanize
 import os
 
@@ -199,7 +199,7 @@ class HTTPTests(unittest.TestCase):
         for bridge in bridges:
             self.assertTrue(bridge != None)
             addr = bridge[0].rsplit(':', 1)[0]
-            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv4Address)
+            self.assertIsInstance(ipaddress.ip_address(addr), ipaddress.IPv4Address)
 
     def test_get_vanilla_ipv6(self):
         self.openBrowser()
@@ -212,7 +212,7 @@ class HTTPTests(unittest.TestCase):
         for bridge in bridges:
             self.assertTrue(bridge != None)
             addr = bridge[0].rsplit(':', 1)[0].strip('[]')
-            self.assertIsInstance(ipaddr.IPAddress(addr), ipaddr.IPv6Address)
+            self.assertIsInstance(ipaddress.ip_address(addr), ipaddress.IPv6Address)
 
     def test_get_obfs4_ipv4(self):
         """Try asking for obfs4 bridges, and check that the PT arguments in the
diff --git a/bridgedb/test/test_https_server.py b/bridgedb/test/test_https_server.py
index 8482d9d..a4d6873 100644
--- a/bridgedb/test/test_https_server.py
+++ b/bridgedb/test/test_https_server.py
@@ -17,7 +17,7 @@ import logging
 import os
 import shutil
 
-import ipaddr
+import ipaddress
 
 from bs4 import BeautifulSoup
 
@@ -588,14 +588,14 @@ class ReCaptchaProtectedResourceTests(unittest.TestCase):
         """Check that removing our remoteip setting produces a random IP."""
         self.captchaResource.remoteIP = None
         ip = self.captchaResource.getRemoteIP()
-        realishIP = ipaddr.IPv4Address(ip).compressed
+        realishIP = ipaddress.IPv4Address(ip).compressed
         self.assertTrue(realishIP)
         self.assertNotEquals(realishIP, '111.111.111.111')
 
     def test_getRemoteIP_useConfiguredIP(self):
         """Check that our remoteip setting is used if configured."""
         ip = self.captchaResource.getRemoteIP()
-        realishIP = ipaddr.IPv4Address(ip).compressed
+        realishIP = ipaddress.IPv4Address(ip).compressed
         self.assertTrue(realishIP)
         self.assertEquals(realishIP, '111.111.111.111')
 
@@ -774,7 +774,7 @@ class BridgesResourceTests(unittest.TestCase):
 
             # Check that the IP and port seem okay:
             ip, port = fields[0].rsplit(':')
-            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
+            self.assertIsInstance(ipaddress.ip_address(ip), ipaddress.IPv4Address)
             self.assertIsInstance(int(port), int)
             self.assertGreater(int(port), 0)
             self.assertLessEqual(int(port), 65535)
@@ -858,7 +858,7 @@ class BridgesResourceTests(unittest.TestCase):
 
             # Check that the IP and port seem okay:
             ip, port = bridgeLine[1].rsplit(':')
-            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
+            self.assertIsInstance(ipaddress.ip_address(ip), ipaddress.IPv4Address)
             self.assertIsInstance(int(port), int)
             self.assertGreater(int(port), 0)
             self.assertLessEqual(int(port), 65535)
@@ -892,7 +892,7 @@ class BridgesResourceTests(unittest.TestCase):
 
             # Check that the IP and port seem okay:
             ip, port = bridgeLine[0].rsplit(b':')
-            self.assertIsInstance(ipaddr.IPv4Address(ip), ipaddr.IPv4Address)
+            self.assertIsInstance(ipaddress.ip_address(ip.decode("utf-8")), ipaddress.IPv4Address)
             self.assertIsInstance(int(port), int)
             self.assertGreater(int(port), 0)
             self.assertLessEqual(int(port), 65535)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits