commands: Fix a bug in the amend interaction
[git-cola.git] / test / test_cola_utils.py
blobab01cff8dafbe1b4f5298d613f07f0e95fb81a4a
1 #!/usr/bin/env python
3 import unittest
5 from cola import utils
7 class ColaUtilsTestCase(unittest.TestCase):
8 """Tests the cola.utils module."""
10 def test_basename(self):
11 """Test the utils.basename function."""
12 self.assertEqual(utils.basename('bar'), 'bar')
13 self.assertEqual(utils.basename('/bar'), 'bar')
14 self.assertEqual(utils.basename('/bar '), 'bar ')
15 self.assertEqual(utils.basename('foo/bar'), 'bar')
16 self.assertEqual(utils.basename('/foo/bar'), 'bar')
17 self.assertEqual(utils.basename('foo/foo/bar'), 'bar')
18 self.assertEqual(utils.basename('/foo/foo/bar'), 'bar')
19 self.assertEqual(utils.basename('/foo/foo//bar'), 'bar')
20 self.assertEqual(utils.basename('////foo //foo//bar'), 'bar')
22 def test_dirname(self):
23 """Test the utils.dirname function."""
24 self.assertEqual(utils.dirname('bar'), '')
25 self.assertEqual(utils.dirname('/bar'), '')
26 self.assertEqual(utils.dirname('//bar'), '')
27 self.assertEqual(utils.dirname('///bar'), '')
28 self.assertEqual(utils.dirname('foo/bar'), 'foo')
29 self.assertEqual(utils.dirname('foo//bar'), 'foo')
30 self.assertEqual(utils.dirname('foo /bar'), 'foo ')
31 self.assertEqual(utils.dirname('/foo//bar'), '/foo')
32 self.assertEqual(utils.dirname('/foo /bar'), '/foo ')
33 self.assertEqual(utils.dirname('//foo//bar'), '/foo')
34 self.assertEqual(utils.dirname('///foo///bar'), '/foo')
36 def test_add_parents(self):
37 """Test the utils.add_parents() function."""
38 path_set = set(['foo///bar///baz'])
39 utils.add_parents(path_set)
41 self.assertTrue('foo/bar/baz' in path_set)
42 self.assertTrue('foo/bar' in path_set)
43 self.assertTrue('foo' in path_set)
46 if __name__ == '__main__':
47 unittest.main()