]> gitweb.michael.orlitzky.com - dead/census-tools.git/blob - src/Tests/Unit/FileUtilsTest.py
Update a FileUtils test so that it doesn't depend on the ordering of a list.
[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 # The order of these two is not reliable.
47 self.assertTrue('postgis.sql' in res[0] or 'postgis.sql' in res[1])
48 self.assertTrue('lwpostgis.sql' in res[0] or 'lwpostgis.sql' in res[1])
49
50
51 def testOnlyOneResultReturnedWhenReturnFirstTrue(self):
52 """
53 Make sure that, in a case where we would normally get two
54 results back, the usage of return_first causes us to receive
55 only one.
56 """
57 fixtures_path = Tests.Fixtures.Path() + '/FileUtils'
58
59 target_files = ['lwpostgis.sql', 'postgis.sql']
60
61 res = FileUtils.find_file_paths(fixtures_path, target_files, True)
62 self.assertTrue(len(res) == 1)
63 # Again, "gentoo" comes before "ubuntu" alphabetically, so
64 # this is the expected result.
65 self.assertTrue('postgis.sql' in res[0])
66
67
68 def suite():
69 suite = unittest.TestSuite()
70 suite.addTest(unittest.makeSuite(FindFilePathsTest))
71 return suite