示例#1
0
 def test_rejoin(I):
     'Test that dirname(x) + filename(x) is always x.'
     d = uripath.UPath('.')[:-1]
     f = uripath.UPath('.')[-1]
     j = d / f
     I.assertEmptyString(d)
     I.assertIsDot(j)
示例#2
0
 def test_abs_rel_join(I):
     'Join absolute and relative paths.'
     abso = uripath.UPath('/usr/local/lib')
     rel = uripath.UPath('python2.7/site-packages')
     # check joining Absolute, Relative and string
     pth = abso / rel / 'jazzy'
     I.assertUPath(pth, '/usr/local/lib/python2.7/site-packages/jazzy', 7)
     # string + relative
     pth = '/tmp' / rel
     I.assertUPath(pth, '/tmp/python2.7/site-packages', 4)
示例#3
0
 def test_join_abs_abs(I):
     "Test that we can't join absolute path on the rhs."
     p = uripath.UPath('/usr/local')
     q = uripath.UPath('/bin/python')
     with I.assertRaises(RuntimeError):
         bad = p / q
     with I.assertRaises(RuntimeError):
         bad = p / '/lib/std'
     with I.assertRaises(RuntimeError):
         bad = '/usr' / q
     j = p / q[1:]
     I.assertUPath(j, '/usr/local/bin/python')
示例#4
0
 def test_unicode_3(I):
     'Test joining a unicode path.'
     top = uripath.UPath('/tmp/xxa55')
     u = u'utf\u20128'
     p = top / u
     I.assertUPath(p, b'/tmp/xxa55/utf\xe2\x80\x928', 4)
     I.assertTrue(p[-1] == u'utf\u20128')
示例#5
0
 def test_abs_join2(I):
     'Test joining a path to change one component.'
     p = uripath.UPath('/var/tmp')
     # we can't assign via subscription
     with I.assertRaises(TypeError):
         p[1] = 'local'
     # but we can do it using path joining
     q = p[:1] / 'local' / p[2:]
     I.assertUPath(q, '/local/tmp')
示例#6
0
 def test_iter_to_list(I):
     'Test UPath as an iter by converting to list.'
     p = uripath.UPath('/usr/local/lib/python2.7/site-packages/jazzy')
     # convert UPath to list
     a = list(p)
     I.assertTrue(len(a) == len(p))
     I.assertTrue(isinstance(a[0], uripath.RootUPath))
     I.assertTrue(all(uripath.isUPath(i) for i in a))
     I.assertTrue(all(a[i] == p[i] for i in range(7)))
     I.assertTrue(all(i == j for i, j in zip(a, p)))
示例#7
0
 def test_iter_append(I):
     'Test UPath as an iter using list append.'
     p = uripath.UPath('/usr/local/lib/python2.7/site-packages/jazzy')
     # old-fashioned append
     a = []
     for part in p:
         a.append(part)
     I.assertTrue(len(a) == len(p))
     I.assertTrue(isinstance(a[0], uripath.RootUPath))
     I.assertTrue(all(uripath.isUPath(i) for i in a))
     I.assertTrue(all(a[i] == p[i] for i in range(7)))
     I.assertTrue(all(i == j for i, j in zip(a, p)))
示例#8
0
 def test_rel_join(I):
     'Test joining relative paths.'
     pyt = uripath.UPath('python2.7')
     lib = uripath.UPath('lib')
     # => python2.7/lib
     pytlib = pyt / lib
     I.assertUPath(pytlib, 'python2.7/lib', 2)
     # => lib/python2.7
     libpyt = lib / pyt
     I.assertUPath(libpyt, 'lib/python2.7', 2)
     # check we can prepend a string
     ulp = 'usr' / libpyt
     I.assertUPath(ulp, 'usr/lib/python2.7', 3)
     # check we can append strings
     pkg = 'jazzy'
     ulpsj = ulp / 'site-packages' / pkg
     I.assertUPath(ulpsj, 'usr/lib/python2.7/site-packages/jazzy', 5)
     # check we can append string paths
     u = uripath.UPath('usr')
     pth = u / 'local/lib' / pyt / 'site-packages/jazzy/jazzy.py'
     I.assertUPath(pth,
                   'usr/local/lib/python2.7/site-packages/jazzy/jazzy.py',
                   7)
示例#9
0
 def test_rel_one(I):
     'Test a single-part relative path.'
     p = uripath.UPath('.ssh')
     I.assertUPath(p, '.ssh', 1)
     # checks for subscription
     I.assertUPath(p[0], '.ssh')
     I.assertUPath(p[-1], '.ssh')
     with I.assertRaises(IndexError):
         p[1]
     # checks for slicing
     I.assertUPath(p[:], '.ssh')
     I.assertUPath(p[0:], '.ssh')
     I.assertEmptyString(p[:-1])
     I.assertEmptyString(p[0:-1])
     I.assertEmptyString(p[1:])
示例#10
0
 def test_abs_toplevel(I):
     'Test a top-level absolute path.'
     p = uripath.UPath('/tmp')
     I.assertUPath(p, '/tmp', 2)
     # checks for subscription
     I.assertUPath(p[0], '/')
     I.assertUPath(p[1], 'tmp')
     I.assertUPath(p[-1], 'tmp')
     with I.assertRaises(IndexError):
         p[2]
     # checks for slicing
     I.assertUPath(p[:], '/tmp')
     I.assertUPath(p[0:], '/tmp')
     I.assertIsRoot(p[:-1])
     I.assertIsRoot(p[0:-1])
     I.assertUPath(p[1:], 'tmp')
     I.assertEmptyString(p[2:])
示例#11
0
 def test_abs_multi(I):
     'Test a multi-part absolute path.'
     p = uripath.UPath('/var/tmp')
     I.assertUPath(p, '/var/tmp', 3)
     # checks for subscription
     I.assertUPath(p[0], '/')
     I.assertUPath(p[1], 'var')
     I.assertUPath(p[2], 'tmp')
     I.assertUPath(p[-1], 'tmp')
     I.assertUPath(p[-2], 'var')
     I.assertUPath(p[-3], '/')
     with I.assertRaises(IndexError):
         p[3]
     # checks for slicing
     I.assertUPath(p[:], '/var/tmp')
     I.assertUPath(p[0:], '/var/tmp')
     I.assertUPath(p[:-1], '/var')
     I.assertUPath(p[0:-1], '/var')
     I.assertUPath(p[1:], 'var/tmp')
     I.assertUPath(p[2:], 'tmp')
示例#12
0
 def test_rel_long(I):
     'Test a multi-part relative path.'
     p = uripath.UPath('lib/python2.7/site-packages')
     I.assertUPath(p, 'lib/python2.7/site-packages', 3)
     # checks for subscription
     I.assertUPath(p[0], 'lib')
     I.assertUPath(p[1], 'python2.7')
     I.assertUPath(p[2], 'site-packages')
     I.assertUPath(p[-1], 'site-packages')
     I.assertUPath(p[-2], 'python2.7')
     I.assertUPath(p[-3], 'lib')
     with I.assertRaises(IndexError):
         p[3]
     # checks for slicing
     I.assertUPath(p[:], 'lib/python2.7/site-packages')
     I.assertUPath(p[0:], 'lib/python2.7/site-packages')
     I.assertUPath(p[:-1], 'lib/python2.7')
     I.assertUPath(p[0:-1], 'lib/python2.7')
     I.assertUPath(p[1:], 'python2.7/site-packages')
     I.assertUPath(p[2:], 'site-packages')
示例#13
0
 def test_whole0(I):
     'Test that a full slice [0:] of "/" is "/" .'
     p = uripath.UPath('/')[0:]
     I.assertIsRoot(p)
示例#14
0
 def test_dirname(I):
     'Test that the dirname of "/" is "/" .'
     p = uripath.UPath('/')[:-1]
     I.assertIsRoot(p)
示例#15
0
 def test_dirname0(I):
     'Test that the dirname of "/" is "/" using explicit slice[0:-1].'
     p = uripath.UPath('/')[0:-1]
     I.assertIsRoot(p)
示例#16
0
 def test_slashslash(I):
     'Test UPath("//").'
     p = uripath.UPath('//')
     I.assertIsRoot(p)
示例#17
0
 def test_eq(I):
     'Test that we __cmp__ against strings'
     p = uripath.UPath('/')
     I.assertTrue(p == '/')
示例#18
0
 def test_unicode_2(I):
     'Test a path with unicode separators.'
     u = u'/top/\u002e\u002e\u002fevil'
     p = uripath.UPath(u)
     I.assertUPath(p, '/evil', 2)
示例#19
0
 def test_item0(I):
     'Test that the 0th item of "." is "." .'
     p = uripath.UPath('.')
     I.assertIsDot(p[0])
示例#20
0
 def test_filename(I):
     'Test that the filename part of "." is "." .'
     p = uripath.UPath('.')[-1]
     I.assertIsDot(p)
示例#21
0
 def test_unicode_1(I):
     'Test a unicode path.'
     u = u'utf\u20128'
     p = uripath.UPath(u)
     I.assertUPath(p, b'utf\xe2\x80\x928', 1)
     I.assertTrue(p == u'utf\u20128')
示例#22
0
 def test_parent(I):
     'Test that the parent of . is ..'
     p = uripath.UPath('.') / '..'
     I.assertTrue(isinstance(p, uripath._RelativeUPath))
     I.assertTrue(p == '..')
示例#23
0
 def test_length(I):
     'Length is the number of components, so is 1.'
     p = uripath.UPath('.')
     I.assertTrue(len(p) == 1)
示例#24
0
 def test_join_dot(I):
     'Test that "./." is still "." .'
     p = uripath.UPath('.') / '.'
     I.assertIsDot(p)
     p = '.' / uripath.UPath('.')
     I.assertIsDot(p)
示例#25
0
 def test_whole(I):
     'Test that a full slice [:] of "." is "." .'
     p = uripath.UPath('.')
     I.assertIsDot(p[:])
     I.assertIsDot(p[0:])
示例#26
0
 def test_item0(I):
     'Test that the 0th item of "/" is "/" .'
     p = uripath.UPath('/')[0]
     I.assertIsRoot(p)
示例#27
0
 def test_join_dotslash(I):
     'Test that /. is /'
     p = uripath.UPath('/') / uripath.UPath('.')
     I.assertIsRoot(p)
     p = '/' / uripath.UPath('.')
     I.assertIsRoot(p)
示例#28
0
 def test_abs_join1(I):
     'Test joining absolute path with string.'
     p = uripath.UPath('/var/tmp') / 'daff0d1'
     I.assertUPath(p, '/var/tmp/daff0d1', 4)
     I.assertUPath(p[0], '/')
     I.assertUPath(p[-1], 'daff0d1')
示例#29
0
 def test_filename(I):
     'Test that the basename of "/" is the empty string.'
     f = uripath.UPath('/')[-1]
     I.assertEmptyString(f)
示例#30
0
 def test_dirname(I):
     'Test that the dirname of "." is the empty string.'
     p = uripath.UPath('.')
     I.assertEmptyString(p[:-1])
     I.assertEmptyString(p[0:-1])