OILS / pylib / os_path_test.py View on Github | oilshell.org

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