1 """Tests the cola.utils module."""
9 """Test the utils.basename function."""
10 assert utils
.basename('bar') == 'bar'
11 assert utils
.basename('/bar') == 'bar'
12 assert utils
.basename('/bar ') == 'bar '
13 assert utils
.basename('foo/bar') == 'bar'
14 assert utils
.basename('/foo/bar') == 'bar'
15 assert utils
.basename('foo/foo/bar') == 'bar'
16 assert utils
.basename('/foo/foo/bar') == 'bar'
17 assert utils
.basename('/foo/foo//bar') == 'bar'
18 assert utils
.basename('////foo //foo//bar') == 'bar'
22 """Test the utils.dirname function."""
23 assert utils
.dirname('bar') == ''
24 assert utils
.dirname('/bar') == ''
25 assert utils
.dirname('//bar') == ''
26 assert utils
.dirname('///bar') == ''
27 assert utils
.dirname('foo/bar') == 'foo'
28 assert utils
.dirname('foo//bar') == 'foo'
29 assert utils
.dirname('foo /bar') == 'foo '
30 assert utils
.dirname('/foo//bar') == '/foo'
31 assert utils
.dirname('/foo /bar') == '/foo '
32 assert utils
.dirname('//foo//bar') == '/foo'
33 assert utils
.dirname('///foo///bar') == '/foo'
36 def test_add_parents():
37 """Test the utils.add_parents() function."""
38 paths
= {'foo///bar///baz'}
39 path_set
= utils
.add_parents(paths
)
41 assert 'foo/bar/baz' in path_set
42 assert 'foo/bar' in path_set
43 assert 'foo' in path_set
44 assert 'foo///bar///baz' not in path_set
46 # Ensure that the original set is unchanged
47 expect
= {'foo///bar///baz'}
48 assert expect
== paths
51 def test_tmp_filename_gives_good_file():
53 first
= utils
.tmp_filename('test')
54 assert core
.exists(first
)
55 assert os
.path
.basename(first
).startswith('git-cola-test')
60 second
= utils
.tmp_filename('test')
61 assert core
.exists(second
)
62 assert os
.path
.basename(second
).startswith('git-cola-test')
66 assert first
!= second
69 def test_strip_one_abspath():
71 actual
= utils
.strip_one('/usr/bin/git')
72 assert expect
== actual
75 def test_strip_one_relpath():
77 actual
= utils
.strip_one('bin/git')
78 assert expect
== actual
81 def test_strip_one_nested_relpath():
83 actual
= utils
.strip_one('local/bin/git')
84 assert expect
== actual
87 def test_strip_one_basename():
89 actual
= utils
.strip_one('git')
90 assert expect
== actual
93 def test_select_directory():
94 filename
= utils
.tmp_filename('test')
96 expect
= os
.path
.dirname(filename
)
97 actual
= utils
.select_directory([filename
])
98 assert expect
== actual
103 def test_select_directory_prefers_directories():
104 filename
= utils
.tmp_filename('test')
107 actual
= utils
.select_directory([filename
, '.'])
108 assert expect
== actual