test_macpath.py 6.2 KB
Newer Older
1
from test import test_genericpath
2
import unittest
3 4 5 6 7 8 9
import warnings


with warnings.catch_warnings():
    warnings.filterwarnings("ignore", "the macpath module is deprecated",
                            DeprecationWarning)
    import macpath
10 11 12 13 14


class MacPathTestCase(unittest.TestCase):

    def test_abspath(self):
15
        self.assertEqual(macpath.abspath("xx:yy"), "xx:yy")
16 17 18

    def test_isabs(self):
        isabs = macpath.isabs
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
        self.assertTrue(isabs("xx:yy"))
        self.assertTrue(isabs("xx:yy:"))
        self.assertTrue(isabs("xx:"))
        self.assertFalse(isabs("foo"))
        self.assertFalse(isabs(":foo"))
        self.assertFalse(isabs(":foo:bar"))
        self.assertFalse(isabs(":foo:bar:"))

        self.assertTrue(isabs(b"xx:yy"))
        self.assertTrue(isabs(b"xx:yy:"))
        self.assertTrue(isabs(b"xx:"))
        self.assertFalse(isabs(b"foo"))
        self.assertFalse(isabs(b":foo"))
        self.assertFalse(isabs(b":foo:bar"))
        self.assertFalse(isabs(b":foo:bar:"))
34

35 36
    def test_split(self):
        split = macpath.split
37
        self.assertEqual(split("foo:bar"),
38
                          ('foo:', 'bar'))
39
        self.assertEqual(split("conky:mountpoint:foo:bar"),
40 41
                          ('conky:mountpoint:foo', 'bar'))

42 43
        self.assertEqual(split(":"), ('', ''))
        self.assertEqual(split(":conky:mountpoint:"),
44 45
                          (':conky:mountpoint', ''))

46
        self.assertEqual(split(b"foo:bar"),
47
                          (b'foo:', b'bar'))
48
        self.assertEqual(split(b"conky:mountpoint:foo:bar"),
49 50
                          (b'conky:mountpoint:foo', b'bar'))

51 52
        self.assertEqual(split(b":"), (b'', b''))
        self.assertEqual(split(b":conky:mountpoint:"),
53 54 55 56
                          (b':conky:mountpoint', b''))

    def test_join(self):
        join = macpath.join
57
        self.assertEqual(join('a', 'b'), ':a:b')
58 59 60 61 62 63 64 65 66
        self.assertEqual(join(':a', 'b'), ':a:b')
        self.assertEqual(join(':a:', 'b'), ':a:b')
        self.assertEqual(join(':a::', 'b'), ':a::b')
        self.assertEqual(join(':a', '::b'), ':a::b')
        self.assertEqual(join('a', ':'), ':a:')
        self.assertEqual(join('a:', ':'), 'a:')
        self.assertEqual(join('a', ''), ':a:')
        self.assertEqual(join('a:', ''), 'a:')
        self.assertEqual(join('', ''), '')
67
        self.assertEqual(join('', 'a:b'), 'a:b')
68
        self.assertEqual(join('', 'a', 'b'), ':a:b')
69 70 71
        self.assertEqual(join('a:b', 'c'), 'a:b:c')
        self.assertEqual(join('a:b', ':c'), 'a:b:c')
        self.assertEqual(join('a', ':b', ':c'), ':a:b:c')
72 73
        self.assertEqual(join('a', 'b:'), 'b:')
        self.assertEqual(join('a:', 'b:'), 'b:')
74 75

        self.assertEqual(join(b'a', b'b'), b':a:b')
76 77 78 79 80 81 82 83 84
        self.assertEqual(join(b':a', b'b'), b':a:b')
        self.assertEqual(join(b':a:', b'b'), b':a:b')
        self.assertEqual(join(b':a::', b'b'), b':a::b')
        self.assertEqual(join(b':a', b'::b'), b':a::b')
        self.assertEqual(join(b'a', b':'), b':a:')
        self.assertEqual(join(b'a:', b':'), b'a:')
        self.assertEqual(join(b'a', b''), b':a:')
        self.assertEqual(join(b'a:', b''), b'a:')
        self.assertEqual(join(b'', b''), b'')
85
        self.assertEqual(join(b'', b'a:b'), b'a:b')
86
        self.assertEqual(join(b'', b'a', b'b'), b':a:b')
87 88 89
        self.assertEqual(join(b'a:b', b'c'), b'a:b:c')
        self.assertEqual(join(b'a:b', b':c'), b'a:b:c')
        self.assertEqual(join(b'a', b':b', b':c'), b':a:b:c')
90 91
        self.assertEqual(join(b'a', b'b:'), b'b:')
        self.assertEqual(join(b'a:', b'b:'), b'b:')
92

93 94
    def test_splitext(self):
        splitext = macpath.splitext
95 96 97 98 99 100 101
        self.assertEqual(splitext(":foo.ext"), (':foo', '.ext'))
        self.assertEqual(splitext("foo:foo.ext"), ('foo:foo', '.ext'))
        self.assertEqual(splitext(".ext"), ('.ext', ''))
        self.assertEqual(splitext("foo.ext:foo"), ('foo.ext:foo', ''))
        self.assertEqual(splitext(":foo.ext:"), (':foo.ext:', ''))
        self.assertEqual(splitext(""), ('', ''))
        self.assertEqual(splitext("foo.bar.ext"), ('foo.bar', '.ext'))
102

103 104 105 106 107 108 109
        self.assertEqual(splitext(b":foo.ext"), (b':foo', b'.ext'))
        self.assertEqual(splitext(b"foo:foo.ext"), (b'foo:foo', b'.ext'))
        self.assertEqual(splitext(b".ext"), (b'.ext', b''))
        self.assertEqual(splitext(b"foo.ext:foo"), (b'foo.ext:foo', b''))
        self.assertEqual(splitext(b":foo.ext:"), (b':foo.ext:', b''))
        self.assertEqual(splitext(b""), (b'', b''))
        self.assertEqual(splitext(b"foo.bar.ext"), (b'foo.bar', b'.ext'))
110 111 112

    def test_ismount(self):
        ismount = macpath.ismount
113 114 115 116 117 118 119 120 121 122 123
        self.assertEqual(ismount("a:"), True)
        self.assertEqual(ismount("a:b"), False)
        self.assertEqual(ismount("a:b:"), True)
        self.assertEqual(ismount(""), False)
        self.assertEqual(ismount(":"), False)

        self.assertEqual(ismount(b"a:"), True)
        self.assertEqual(ismount(b"a:b"), False)
        self.assertEqual(ismount(b"a:b:"), True)
        self.assertEqual(ismount(b""), False)
        self.assertEqual(ismount(b":"), False)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145

    def test_normpath(self):
        normpath = macpath.normpath
        self.assertEqual(normpath("a:b"), "a:b")
        self.assertEqual(normpath("a"), ":a")
        self.assertEqual(normpath("a:b::c"), "a:c")
        self.assertEqual(normpath("a:b:c:::d"), "a:d")
        self.assertRaises(macpath.norm_error, normpath, "a::b")
        self.assertRaises(macpath.norm_error, normpath, "a:b:::c")
        self.assertEqual(normpath(":"), ":")
        self.assertEqual(normpath("a:"), "a:")
        self.assertEqual(normpath("a:b:"), "a:b")

        self.assertEqual(normpath(b"a:b"), b"a:b")
        self.assertEqual(normpath(b"a"), b":a")
        self.assertEqual(normpath(b"a:b::c"), b"a:c")
        self.assertEqual(normpath(b"a:b:c:::d"), b"a:d")
        self.assertRaises(macpath.norm_error, normpath, b"a::b")
        self.assertRaises(macpath.norm_error, normpath, b"a:b:::c")
        self.assertEqual(normpath(b":"), b":")
        self.assertEqual(normpath(b"a:"), b"a:")
        self.assertEqual(normpath(b"a:b:"), b"a:b")
146

147

148
class MacCommonTest(test_genericpath.CommonTest, unittest.TestCase):
149 150
    pathmodule = macpath

151 152
    test_relpath_errors = None

153

154
if __name__ == "__main__":
155
    unittest.main()