Revision 57d56130 test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
1334 | 1334 |
def tearDown(self): |
1335 | 1335 |
shutil.rmtree(self.path) |
1336 | 1336 |
|
1337 |
def _test(self, files, expected): |
|
1338 |
# Sort a copy |
|
1339 |
expected = expected[:] |
|
1340 |
expected.sort() |
|
1341 |
|
|
1337 |
def _CreateFiles(self, files): |
|
1342 | 1338 |
for name in files: |
1343 |
f = open(os.path.join(self.path, name), 'w') |
|
1344 |
try: |
|
1345 |
f.write("Test\n") |
|
1346 |
finally: |
|
1347 |
f.close() |
|
1339 |
utils.WriteFile(os.path.join(self.path, name), data="test") |
|
1348 | 1340 |
|
1341 |
def _test(self, files, expected): |
|
1342 |
self._CreateFiles(files) |
|
1349 | 1343 |
found = ListVisibleFiles(self.path) |
1350 |
found.sort() |
|
1351 |
|
|
1352 |
self.assertEqual(found, expected) |
|
1344 |
# by default ListVisibleFiles sorts its output |
|
1345 |
self.assertEqual(found, sorted(expected)) |
|
1353 | 1346 |
|
1354 | 1347 |
def testAllVisible(self): |
1355 | 1348 |
files = ["a", "b", "c"] |
... | ... | |
1366 | 1359 |
expected = ["a", "b"] |
1367 | 1360 |
self._test(files, expected) |
1368 | 1361 |
|
1362 |
def testForceSort(self): |
|
1363 |
files = ["c", "b", "a"] |
|
1364 |
self._CreateFiles(files) |
|
1365 |
found = ListVisibleFiles(self.path, sort=True) |
|
1366 |
self.assertEqual(found, sorted(files)) |
|
1367 |
|
|
1368 |
def testForceNonSort(self): |
|
1369 |
files = ["c", "b", "a"] |
|
1370 |
self._CreateFiles(files) |
|
1371 |
found = ListVisibleFiles(self.path, sort=False) |
|
1372 |
# We can't actually check that they weren't sorted, because they might come |
|
1373 |
# out sorted by chance |
|
1374 |
self.assertEqual(set(found), set(files)) |
|
1375 |
|
|
1369 | 1376 |
def testNonAbsolutePath(self): |
1370 | 1377 |
self.failUnlessRaises(errors.ProgrammerError, ListVisibleFiles, "abc") |
1371 | 1378 |
|
Also available in: Unified diff