@@ -4,63 +4,63 @@ from lightbug_http.address import TCPAddr, NetworkType, join_host_port, parse_ad
44
55def test_split_host_port ():
66 # TCP4
7- var hp = parse_address(NetworkType.tcp4, " 127.0.0.1:8080" )
8- testing.assert_equal(hp[0 ], " 127.0.0.1" )
7+ var hp = parse_address(NetworkType.tcp4, " 127.0.0.1:8080" .as_bytes() )
8+ testing.assert_equal(hp[0 ], " 127.0.0.1" .as_bytes() )
99 testing.assert_equal(hp[1 ], 8080 )
1010
1111 # TCP4 with localhost
12- hp = parse_address(NetworkType.tcp4, " localhost:8080" )
13- testing.assert_equal(hp[0 ], " 127.0.0.1" )
12+ hp = parse_address(NetworkType.tcp4, " localhost:8080" .as_bytes() )
13+ testing.assert_equal(hp[0 ], " 127.0.0.1" .as_bytes() )
1414 testing.assert_equal(hp[1 ], 8080 )
1515
1616 # TCP6
17- hp = parse_address(NetworkType.tcp6, " [::1]:8080" )
18- testing.assert_equal(hp[0 ], " ::1" )
17+ hp = parse_address(NetworkType.tcp6, " [::1]:8080" .as_bytes() )
18+ testing.assert_equal(hp[0 ], " ::1" .as_bytes() )
1919 testing.assert_equal(hp[1 ], 8080 )
2020
2121 # TCP6 with localhost
22- hp = parse_address(NetworkType.tcp6, " localhost:8080" )
23- testing.assert_equal(hp[0 ], " ::1" )
22+ hp = parse_address(NetworkType.tcp6, " localhost:8080" .as_bytes() )
23+ testing.assert_equal(hp[0 ], " ::1" .as_bytes() )
2424 testing.assert_equal(hp[1 ], 8080 )
2525
2626 # UDP4
27- hp = parse_address(NetworkType.udp4, " 192.168.1.1:53" )
28- testing.assert_equal(hp[0 ], " 192.168.1.1" )
27+ hp = parse_address(NetworkType.udp4, " 192.168.1.1:53" .as_bytes() )
28+ testing.assert_equal(hp[0 ], " 192.168.1.1" .as_bytes() )
2929 testing.assert_equal(hp[1 ], 53 )
3030
3131 # UDP4 with localhost
32- hp = parse_address(NetworkType.udp4, " localhost:53" )
33- testing.assert_equal(hp[0 ], " 127.0.0.1" )
32+ hp = parse_address(NetworkType.udp4, " localhost:53" .as_bytes() )
33+ testing.assert_equal(hp[0 ], " 127.0.0.1" .as_bytes() )
3434 testing.assert_equal(hp[1 ], 53 )
3535
3636 # UDP6
37- hp = parse_address(NetworkType.udp6, " [2001:db8::1]:53" )
38- testing.assert_equal(hp[0 ], " 2001:db8::1" )
37+ hp = parse_address(NetworkType.udp6, " [2001:db8::1]:53" .as_bytes() )
38+ testing.assert_equal(hp[0 ], " 2001:db8::1" .as_bytes() )
3939 testing.assert_equal(hp[1 ], 53 )
4040
4141 # UDP6 with localhost
42- hp = parse_address(NetworkType.udp6, " localhost:53" )
43- testing.assert_equal(hp[0 ], " ::1" )
42+ hp = parse_address(NetworkType.udp6, " localhost:53" .as_bytes() )
43+ testing.assert_equal(hp[0 ], " ::1" .as_bytes() )
4444 testing.assert_equal(hp[1 ], 53 )
4545
4646 # IP4 (no port)
47- hp = parse_address(NetworkType.ip4, " 192.168.1.1" )
48- testing.assert_equal(hp[0 ], " 192.168.1.1" )
47+ hp = parse_address(NetworkType.ip4, " 192.168.1.1" .as_bytes() )
48+ testing.assert_equal(hp[0 ], " 192.168.1.1" .as_bytes() )
4949 testing.assert_equal(hp[1 ], 0 )
5050
5151 # IP4 with localhost
52- hp = parse_address(NetworkType.ip4, " localhost" )
53- testing.assert_equal(hp[0 ], " 127.0.0.1" )
52+ hp = parse_address(NetworkType.ip4, " localhost" .as_bytes() )
53+ testing.assert_equal(hp[0 ], " 127.0.0.1" .as_bytes() )
5454 testing.assert_equal(hp[1 ], 0 )
5555
5656 # IP6 (no port)
57- hp = parse_address(NetworkType.ip6, " 2001:db8::1" )
58- testing.assert_equal(hp[0 ], " 2001:db8::1" )
57+ hp = parse_address(NetworkType.ip6, " 2001:db8::1" .as_bytes() )
58+ testing.assert_equal(hp[0 ], " 2001:db8::1" .as_bytes() )
5959 testing.assert_equal(hp[1 ], 0 )
6060
6161 # IP6 with localhost
62- hp = parse_address(NetworkType.ip6, " localhost" )
63- testing.assert_equal(hp[0 ], " ::1" )
62+ hp = parse_address(NetworkType.ip6, " localhost" .as_bytes() )
63+ testing.assert_equal(hp[0 ], " ::1" .as_bytes() )
6464 testing.assert_equal(hp[1 ], 0 )
6565
6666 # TODO : IPv6 long form - Not supported yet.
@@ -71,35 +71,35 @@ def test_split_host_port():
7171 # Error cases
7272 # IP protocol with port
7373 try :
74- _ = parse_address(NetworkType.ip4, " 192.168.1.1:80" )
74+ _ = parse_address(NetworkType.ip4, " 192.168.1.1:80" .as_bytes() )
7575 testing.assert_false(" Should have raised an error for IP protocol with port" )
7676 except Error:
7777 testing.assert_true(True )
7878
7979 # Missing port
8080 try :
81- _ = parse_address(NetworkType.tcp4, " 192.168.1.1" )
81+ _ = parse_address(NetworkType.tcp4, " 192.168.1.1" .as_bytes() )
8282 testing.assert_false(" Should have raised MissingPortError" )
8383 except MissingPortError:
8484 testing.assert_true(True )
8585
8686 # Missing port
8787 try :
88- _ = parse_address(NetworkType.tcp6, " [::1]" )
88+ _ = parse_address(NetworkType.tcp6, " [::1]" .as_bytes() )
8989 testing.assert_false(" Should have raised MissingPortError" )
9090 except MissingPortError:
9191 testing.assert_true(True )
9292
9393 # Port out of range
9494 try :
95- _ = parse_address(NetworkType.tcp4, " 192.168.1.1:70000" )
95+ _ = parse_address(NetworkType.tcp4, " 192.168.1.1:70000" .as_bytes() )
9696 testing.assert_false(" Should have raised error for invalid port" )
9797 except Error:
9898 testing.assert_true(True )
9999
100100 # Missing closing bracket
101101 try :
102- _ = parse_address(NetworkType.tcp6, " [::1:8080" )
102+ _ = parse_address(NetworkType.tcp6, " [::1:8080" .as_bytes() )
103103 testing.assert_false(" Should have raised error for missing bracket" )
104104 except Error:
105105 testing.assert_true(True )
0 commit comments