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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
import sys
from unittest import TestCase
from kazoo.protocol import paths
if sys.version_info > (3, ): # pragma: nocover
def u(s):
return s
else: # pragma: nocover
def u(s):
return unicode(s, "unicode_escape")
class NormPathTestCase(TestCase):
def test_normpath(self):
self.assertEqual(paths.normpath('/a/b'), '/a/b')
def test_normpath_empty(self):
self.assertEqual(paths.normpath(''), '')
def test_normpath_unicode(self):
self.assertEqual(paths.normpath(u('/\xe4/b')), u('/\xe4/b'))
def test_normpath_dots(self):
self.assertEqual(paths.normpath('/a./b../c'), '/a./b../c')
def test_normpath_slash(self):
self.assertEqual(paths.normpath('/'), '/')
def test_normpath_multiple_slashes(self):
self.assertEqual(paths.normpath('//'), '/')
self.assertEqual(paths.normpath('//a/b'), '/a/b')
self.assertEqual(paths.normpath('/a//b//'), '/a/b')
self.assertEqual(paths.normpath('//a////b///c/'), '/a/b/c')
def test_normpath_relative(self):
self.assertRaises(ValueError, paths.normpath, './a/b')
self.assertRaises(ValueError, paths.normpath, '/a/../b')
def test_normpath_trailing(self):
self.assertEqual(paths.normpath('/', trailing=True), '/')
class JoinTestCase(TestCase):
def test_join(self):
self.assertEqual(paths.join('/a'), '/a')
self.assertEqual(paths.join('/a', 'b/'), '/a/b/')
self.assertEqual(paths.join('/a', 'b', 'c'), '/a/b/c')
def test_join_empty(self):
self.assertEqual(paths.join(''), '')
self.assertEqual(paths.join('', 'a', 'b'), 'a/b')
self.assertEqual(paths.join('/a', '', 'b/', 'c'), '/a/b/c')
def test_join_absolute(self):
self.assertEqual(paths.join('/a/b', '/c'), '/c')
class IsAbsTestCase(TestCase):
def test_isabs(self):
self.assertTrue(paths.isabs('/'))
self.assertTrue(paths.isabs('/a'))
self.assertTrue(paths.isabs('/a//b/c'))
self.assertTrue(paths.isabs('//a/b'))
def test_isabs_false(self):
self.assertFalse(paths.isabs(''))
self.assertFalse(paths.isabs('a/'))
self.assertFalse(paths.isabs('a/../'))
class BaseNameTestCase(TestCase):
def test_basename(self):
self.assertEquals(paths.basename(''), '')
self.assertEquals(paths.basename('/'), '')
self.assertEquals(paths.basename('//a'), 'a')
self.assertEquals(paths.basename('//a/'), '')
self.assertEquals(paths.basename('/a/b.//c..'), 'c..')
class PrefixRootTestCase(TestCase):
def test_prefix_root(self):
self.assertEquals(paths._prefix_root('/a/', 'b/c'), '/a/b/c')
self.assertEquals(paths._prefix_root('/a/b', 'c/d'), '/a/b/c/d')
self.assertEquals(paths._prefix_root('/a', '/b/c'), '/a/b/c')
self.assertEquals(paths._prefix_root('/a', '//b/c.'), '/a/b/c.')
class NormRootTestCase(TestCase):
def test_norm_root(self):
self.assertEquals(paths._norm_root(''), '/')
self.assertEquals(paths._norm_root('/'), '/')
self.assertEquals(paths._norm_root('//a'), '/a')
self.assertEquals(paths._norm_root('//a./b'), '/a./b')
|