Skip to content

Commit a46079e

Browse files
committed
merge from 3.3: Increase the test coverage of macurl2path module. Patch by Colin Williams.
2 parents dfea312 + b82a3dc commit a46079e

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

Lib/macurl2path.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,3 @@ def pathname2url(pathname):
7575
def _pncomp2url(component):
7676
# We want to quote slashes
7777
return urllib.parse.quote(component[:31], safe='')
78-
79-
def test():
80-
for url in ["index.html",
81-
"bar/index.html",
82-
"/foo/bar/index.html",
83-
"/foo/bar/",
84-
"/"]:
85-
print('%r -> %r' % (url, url2pathname(url)))
86-
for path in ["drive:",
87-
"drive:dir:",
88-
"drive:dir:file",
89-
"drive:file",
90-
"file",
91-
":file",
92-
":dir:",
93-
":dir:file"]:
94-
print('%r -> %r' % (path, pathname2url(path)))
95-
96-
if __name__ == '__main__':
97-
test()

Lib/test/test_macurl2path.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import macurl2path
2+
import unittest
3+
4+
class MacUrl2PathTestCase(unittest.TestCase):
5+
def test_url2pathname(self):
6+
self.assertEqual(":index.html", macurl2path.url2pathname("index.html"))
7+
self.assertEqual(":bar:index.html", macurl2path.url2pathname("bar/index.html"))
8+
self.assertEqual("foo:bar:index.html", macurl2path.url2pathname("/foo/bar/index.html"))
9+
self.assertEqual("foo:bar", macurl2path.url2pathname("/foo/bar/"))
10+
self.assertEqual("", macurl2path.url2pathname("/"))
11+
self.assertRaises(RuntimeError, macurl2path.url2pathname, "http://foo.com")
12+
self.assertEqual("index.html", macurl2path.url2pathname("///index.html"))
13+
self.assertRaises(RuntimeError, macurl2path.url2pathname, "//index.html")
14+
self.assertEqual(":index.html", macurl2path.url2pathname("./index.html"))
15+
self.assertEqual(":index.html", macurl2path.url2pathname("foo/../index.html"))
16+
self.assertEqual("::index.html", macurl2path.url2pathname("../index.html"))
17+
18+
def test_pathname2url(self):
19+
self.assertEqual("drive", macurl2path.pathname2url("drive:"))
20+
self.assertEqual("drive/dir", macurl2path.pathname2url("drive:dir:"))
21+
self.assertEqual("drive/dir/file", macurl2path.pathname2url("drive:dir:file"))
22+
self.assertEqual("drive/file", macurl2path.pathname2url("drive:file"))
23+
self.assertEqual("file", macurl2path.pathname2url("file"))
24+
self.assertEqual("file", macurl2path.pathname2url(":file"))
25+
self.assertEqual("dir", macurl2path.pathname2url(":dir:"))
26+
self.assertEqual("dir/file", macurl2path.pathname2url(":dir:file"))
27+
self.assertRaises(RuntimeError, macurl2path.pathname2url, "/")
28+
self.assertEqual("dir/../file", macurl2path.pathname2url("dir::file"))
29+
30+
if __name__ == "__main__":
31+
unittest.main()

Lib/test/test_sundry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class TestUntestedModules(unittest.TestCase):
88
def test_untested_modules_can_be_imported(self):
99
untested = ('bdb', 'encodings', 'formatter', 'imghdr',
10-
'macurl2path', 'nturl2path', 'tabnanny')
10+
'nturl2path', 'tabnanny')
1111
with support.check_warnings(quiet=True):
1212
for name in untested:
1313
try:
@@ -47,6 +47,7 @@ def test_untested_modules_can_be_imported(self):
4747
import distutils.command.upload
4848

4949
import html.entities
50+
5051
try:
5152
import tty # Not available on Windows
5253
except ImportError:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Core and Builtins
1919
Library
2020
-------
2121

22+
- Issue #19350: Increasing the test coverage of macurl2path. Patch by Colin
23+
Williams.
24+
2225
- Issue #19365: Optimized the parsing of long replacement string in re.sub*()
2326
functions.
2427

0 commit comments

Comments
 (0)