]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/FileUtilsTest.py
Moved the multiple-filename logic inside the find_file_paths function.
[dead/census-tools.git] / src / Tests / Unit / FileUtilsTest.py
1 import unittest
2
3 import Tests.Fixtures
4 import FileUtils
5
6
7 class FindFilePathsTest(unittest.TestCase):
8
9 def testPostgisFixturesFound(self):
10 """
11 There are two dummy files in the fixtures directory,
12 lwpostgis.sql and postgis.sql. They have been placed in two
13 subfolders named after two distros who include the SQL file with
14 different names.
15
16 If we search a distro subdirectory for *both* names, we should
17 get back only one result: the correct one to use on that
18 distro.
19 """
20 gentoo_fixtures_path = Tests.Fixtures.Path() + '/FileUtils/gentoo'
21 ubuntu_fixtures_path = Tests.Fixtures.Path() + '/FileUtils/ubuntu'
22
23 target_files = ['lwpostgis.sql', 'postgis.sql']
24
25 res = FileUtils.find_file_paths(gentoo_fixtures_path, target_files)
26 self.assertTrue(len(res) == 1)
27 self.assertTrue('postgis.sql' in res[0])
28
29 res = FileUtils.find_file_paths(ubuntu_fixtures_path, target_files)
30 print res[0]
31 self.assertTrue(len(res) == 1)
32 self.assertTrue('lwpostgis.sql' in res[0])
33
34
35 def testBothFixturesFoundFromRoot(self):
36 """
37 If we search for the (lw)postgis.sql files from the fixtures
38 root, we should find both of them.
39 """
40 fixtures_path = Tests.Fixtures.Path() + '/FileUtils'
41
42 target_files = ['lwpostgis.sql', 'postgis.sql']
43
44 res = FileUtils.find_file_paths(fixtures_path, target_files)
45 self.assertTrue(len(res) == 2)
46 # "gentoo" comes first alphabetically, and so we'll traverse
47 # it first. Thus, postgis.sql should be found before
48 # lwpostgis.sql.
49 self.assertTrue('postgis.sql' in res[0])
50 self.assertTrue('lwpostgis.sql' in res[1])
51
52
53 def testOnlyOneResultReturnedWhenReturnFirstTrue(self):
54 """
55 Make sure that, in a case where we would normally get two
56 results back, the usage of return_first causes us to receive
57 only one.
58 """
59 fixtures_path = Tests.Fixtures.Path() + '/FileUtils'
60
61 target_files = ['lwpostgis.sql', 'postgis.sql']
62
63 res = FileUtils.find_file_paths(fixtures_path, target_files, True)
64 self.assertTrue(len(res) == 1)
65 # Again, "gentoo" comes before "ubuntu" alphabetically, so
66 # this is the expected result.
67 self.assertTrue('postgis.sql' in res[0])
68
69
70 def suite():
71 suite = unittest.TestSuite()
72 suite.addTest(unittest.makeSuite(FindFilePathsTest))
73 return suite