[tor-commits] [flashproxy/master] Add tests for flashproxy.util.format_addr.

dcf at torproject.org dcf at torproject.org
Sun Feb 2 01:34:29 UTC 2014


commit 6cf2eb6266af506d58a0cd4221cb1b94b854d84c
Author: David Fifield <david at bamsoftware.com>
Date:   Sat Feb 1 17:21:16 2014 -0800

    Add tests for flashproxy.util.format_addr.
---
 flashproxy/test/test_util.py |   39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/flashproxy/test/test_util.py b/flashproxy/test/test_util.py
index e095f38..3529d23 100644
--- a/flashproxy/test/test_util.py
+++ b/flashproxy/test/test_util.py
@@ -3,7 +3,7 @@
 import socket
 import unittest
 
-from flashproxy.util import parse_addr_spec, canonical_ip, addr_family
+from flashproxy.util import parse_addr_spec, canonical_ip, addr_family, format_addr
 
 class ParseAddrSpecTest(unittest.TestCase):
     def test_ipv4(self):
@@ -50,5 +50,42 @@ class AddrFamilyTest(unittest.TestCase):
     def test_name(self):
         self.assertRaises(socket.gaierror, addr_family, "localhost")
 
+class FormatAddrTest(unittest.TestCase):
+    def test_none_none(self):
+        self.assertRaises(ValueError, format_addr, (None, None))
+
+    def test_none_port(self):
+        self.assertEqual(format_addr((None, 1234)), ":1234")
+
+    def test_none_invalid(self):
+        self.assertRaises(ValueError, format_addr, (None, "string"))
+
+    def test_ipv4_none(self):
+        self.assertEqual(format_addr(("1.2.3.4", None)), "1.2.3.4")
+
+    def test_ipv4_port(self):
+        self.assertEqual(format_addr(("1.2.3.4", 1234)), "1.2.3.4:1234")
+
+    def test_ipv4_invalid(self):
+        self.assertRaises(ValueError, format_addr, ("1.2.3.4", "string"))
+
+    def test_ipv6_none(self):
+        self.assertEqual(format_addr(("1:2::3:4", None)), "[1:2::3:4]")
+
+    def test_ipv6_port(self):
+        self.assertEqual(format_addr(("1:2::3:4", 1234)), "[1:2::3:4]:1234")
+
+    def test_ipv6_invalid(self):
+        self.assertRaises(ValueError, format_addr, ("1:2::3:4", "string"))
+
+    def test_name_none(self):
+        self.assertEqual(format_addr(("localhost", None)), "localhost")
+
+    def test_name_port(self):
+        self.assertEqual(format_addr(("localhost", 1234)), "localhost:1234")
+
+    def test_name_invalid(self):
+        self.assertRaises(ValueError, format_addr, ("localhost", "string"))
+
 if __name__ == "__main__":
     unittest.main()





More information about the tor-commits mailing list