Add Tests for nturl2path module. Make it part of test_urllib per suggestion from Brett Cannon - Code Review (original) (raw)
OLD
NEW
1 """Regresssion tests for urllib"""
1 """Regresssion tests for urllib"""
2
2
3 import urllib.parse
3 import urllib.parse
4 import urllib.request
4 import urllib.request
5 import http.client
5 import http.client
6 import email.message
6 import email.message
7 import io
7 import io
8 import unittest
8 import unittest
9 from test import support
9 from test import support
10 import os
10 import os
11 import tempfile
11 import tempfile
12 from nturl2path import url2pathname, pathname2url
13
12
14
13 def hexescape(char):
15 def hexescape(char):
14 """Escape char as RFC 2396 specifies"""
16 """Escape char as RFC 2396 specifies"""
15 hex_repr = hex(ord(char))[2:].upper()
17 hex_repr = hex(ord(char))[2:].upper()
16 if len(hex_repr) == 1:
18 if len(hex_repr) == 1:
17 hex_repr = "0%s" % hex_repr
19 hex_repr = "0%s" % hex_repr
18 return "%" + hex_repr
20 return "%" + hex_repr
19
21
20 # Shortcut for testing FancyURLopener
22 # Shortcut for testing FancyURLopener
21 _urlopener = None
23 _urlopener = None
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading...
901 # socket.setdefaulttimeout(None)
903 # socket.setdefaulttimeout(None)
902 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
904 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
903 # ftp.close()
905 # ftp.close()
904 #
906 #
905 # def testTimeoutValue(self):
907 # def testTimeoutValue(self):
906 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
908 # ftp = urllib.ftpwrapper("myuser", "mypass", "localhost", 9093, [],
907 # timeout=30)
909 # timeout=30)
908 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
910 # self.assertEqual(ftp.ftp.sock.gettimeout(), 30)
909 # ftp.close()
911 # ftp.close()
910
912
913 if os.name == 'nt':
914 ····
915 class URL2PathNameTests(unittest.TestCase):
916 ········
917 def test_converting_drive_letter(self):
918 self.assertEquals('C:', url2pathname("///C|"))
919 self.assertEquals('C:', url2pathname("///C:"))
920 self.assertEquals('C:', url2pathname("///C|/"))
921 ····
922 def test_converting_when_no_drive_letter(self):
923 self.assertEquals('\\\\\\C\\test\\', url2pathname("///C/test/"))
924 self.assertEquals('\\\\C\\test\\', url2pathname("////C/test/"))
925 ············
926 def test_simple_compare(self):
927 self.assertEquals('C:\\foo\\bar\\spam.foo', url2pathname("///C|/foo/ bar/spam.foo"))
928 ····
929 def test_assert_raises_io_error_when_non_ascii__drive_letter(self):
930 self.assertRaises( IOError, url2pathname, "///\u0099|/" )
931 ············
932 class PathName2URLTests(unittest.TestCase):
933 ········
934 def test_converting_drive_letter(self):
935 self.assertEquals('///C|', pathname2url("C:"))
936 self.assertEquals('///C|', pathname2url("C:\\"))
937 ····
938 def test_converting_when_no_drive_letter(self):
939 self.assertEquals('/////folder/test/', pathname2url("\\\\\\folder\\t est\\"))
940 self.assertEquals('////folder/test/', pathname2url("\\\\folder\\test \\"))
941 self.assertEquals('/folder/test/', pathname2url("\\folder\\test\\"))
942 ············
943 def test_simple_compare(self):
944 self.assertEquals("///C|/foo/bar/spam.foo", pathname2url('C:\\foo\\b ar\\spam.foo'))
945 ····
946 def test_assert_raises_io_error_when_long_drive_letter(self):
947 self.assertRaises( IOError, pathname2url, "XX:\\" )
948
949 else:
950 class URL2PathNameTests(unittest.TestCase): pass··········
951 class PathName2URLTests(unittest.TestCase): pass
911
952
912
953
913 def test_main():
954 def test_main():
914 support.run_unittest(
955 support.run_unittest(
915 urlopen_FileTests,
956 urlopen_FileTests,
916 urlopen_HttpTests,
957 urlopen_HttpTests,
917 urlretrieve_FileTests,
958 urlretrieve_FileTests,
918 ProxyTests,
959 ProxyTests,
919 QuotingTests,
960 QuotingTests,
920 UnquotingTests,
961 UnquotingTests,
921 urlencode_Tests,
962 urlencode_Tests,
922 Pathname_Tests,
963 Pathname_Tests,
964 URL2PathNameTests,
965 PathName2URLTests,
923 #FTPWrapperTests,
966 #FTPWrapperTests,
924 )
967 )
925
968
926
969
927
970
928 if __name__ == '__main__':
971 if __name__ == '__main__':
929 test_main()
972 test_main()
OLD
NEW