1import macurl2path
2import unittest
3
4class 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
30if __name__ == "__main__":
31    unittest.main()
32