Browse Source

Improved IP generator testing

Stefan Schmidt 5 years ago
parent
commit
0f770f8670
1 changed files with 5 additions and 8 deletions
  1. 5 8
      code/Test/test_ipgenerator.py

+ 5 - 8
code/Test/test_ipgenerator.py

@@ -14,17 +14,14 @@ class IPGeneratorTestCase(unittest.TestCase):
         cls.IP_SAMPLES = [cls.IP_GENERATOR.random_ip() for _ in range(cls.IP_SAMPLES_NUM)]
 
     def test_valid_ips(self):
-        ip = None
-
-        try:
-            for ip in self.IP_SAMPLES:
+        for ip in self.IP_SAMPLES:
+            with self.subTest(ip=ip):
                 parts = ip.split(".")
-                self.assertTrue(len(parts) == 4)
+                self.assertEqual(len(parts), 4)
 
                 numbers = [int(i) for i in parts]
-                self.assertTrue(all(n in range(256) for n in numbers))
-        except:
-            self.fail("%s is not a valid IPv4" % ip)
+                for n in numbers:
+                    self.assertIn(n, range(256))
 
     def test_generates_localhost_ip(self):
         self.assertFalse(any(ip.startswith("127.") for ip in self.IP_SAMPLES))