forked from oils-for-unix/oils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathos_path_test.py
executable file
·59 lines (49 loc) · 1.46 KB
/
os_path_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python2
"""
os_path_test.py: Tests for os_path.py
"""
from __future__ import print_function
import os
import unittest
from pylib import os_path # module under test
class OsPathTest(unittest.TestCase):
def testDirname(self):
CASES = [
('', 'foo'),
('dir', 'dir/'),
('bin', 'bin/foo'),
('bin', 'bin//foo'), # double slashes
('/usr//local//bin', '/usr//local//bin//foo'),
('///', '///foo'), # special case of not stripping slashes
]
for expected, d in CASES:
self.assertEqual(expected, os_path.dirname(d))
def testSplit(self):
CASES = [
(('bin', 'foo'), 'bin/foo'),
(('bin', 'foo'), 'bin//foo'), # double slashes
(('/usr//local//bin', 'foo'), '/usr//local//bin//foo'),
(('///', 'foo'), '///foo'), # special case of not stripping slashes
]
for expected, d in CASES:
self.assertEqual(expected, os_path.split(d))
def testBasename(self):
self.assertEqual('bar', os_path.basename('foo/bar'))
def testJoin(self):
CASES = [
('foo', 'bar'),
('foo/', 'bar'),
('foo', '/bar'),
('', 'bar'),
('foo', ''),
('', ''),
('/', ''),
('', '/'),
]
for s1, s2 in CASES:
# test against the Python stdlib version
expected = os.path.join(s1, s2)
print(expected)
self.assertEqual(expected, os_path.join(s1, s2))
if __name__ == '__main__':
unittest.main()