|
86
|
1 # Copyright (C) 2009 Canonical Ltd |
|
|
2 # |
|
|
3 # This program is free software; you can redistribute it and/or modify |
|
|
4 # it under the terms of the GNU General Public License as published by |
|
|
5 # the Free Software Foundation; either version 2 of the License, or |
|
|
6 # (at your option) any later version. |
|
|
7 # |
|
|
8 # This program is distributed in the hope that it will be useful, |
|
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
11 # GNU General Public License for more details. |
|
|
12 # |
|
|
13 # You should have received a copy of the GNU General Public License |
|
|
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
15 |
|
|
16 """Test the helper functions.""" |
|
|
17 |
|
|
18 import unittest |
|
|
19 |
|
|
20 from fastimport import ( |
|
|
21 helpers, |
|
|
22 ) |
|
|
23 |
|
|
24 |
|
|
25 class TestCommonDirectory(unittest.TestCase): |
|
|
26 |
|
|
27 def test_no_paths(self): |
|
|
28 c = helpers.common_directory(None) |
|
|
29 self.assertEqual(c, None) |
|
|
30 c = helpers.common_directory([]) |
|
|
31 self.assertEqual(c, None) |
|
|
32 |
|
|
33 def test_one_path(self): |
|
|
34 c = helpers.common_directory([b'foo']) |
|
|
35 self.assertEqual(c, b'') |
|
|
36 c = helpers.common_directory([b'foo/']) |
|
|
37 self.assertEqual(c, b'foo/') |
|
|
38 c = helpers.common_directory([b'foo/bar']) |
|
|
39 self.assertEqual(c, b'foo/') |
|
|
40 |
|
|
41 def test_two_paths(self): |
|
|
42 c = helpers.common_directory([b'foo', b'bar']) |
|
|
43 self.assertEqual(c, b'') |
|
|
44 c = helpers.common_directory([b'foo/', b'bar']) |
|
|
45 self.assertEqual(c, b'') |
|
|
46 c = helpers.common_directory([b'foo/', b'foo/bar']) |
|
|
47 self.assertEqual(c, b'foo/') |
|
|
48 c = helpers.common_directory([b'foo/bar/x', b'foo/bar/y']) |
|
|
49 self.assertEqual(c, b'foo/bar/') |
|
|
50 c = helpers.common_directory([b'foo/bar/aa_x', b'foo/bar/aa_y']) |
|
|
51 self.assertEqual(c, b'foo/bar/') |
|
|
52 |
|
|
53 def test_lots_of_paths(self): |
|
|
54 c = helpers.common_directory([b'foo/bar/x', b'foo/bar/y', b'foo/bar/z']) |
|
|
55 self.assertEqual(c, b'foo/bar/') |