Revision eedbda4b test/ganeti.utils_unittest.py
b/test/ganeti.utils_unittest.py | ||
---|---|---|
28 | 28 |
import os.path |
29 | 29 |
import md5 |
30 | 30 |
import socket |
31 |
|
|
31 |
import shutil |
|
32 | 32 |
|
33 | 33 |
import ganeti |
34 | 34 |
from ganeti.utils import IsProcessAlive, Lock, Unlock, RunCmd, \ |
35 | 35 |
RemoveFile, CheckDict, MatchNameComponent, FormatUnit, \ |
36 | 36 |
ParseUnit, AddAuthorizedKey, RemoveAuthorizedKey, \ |
37 |
ShellQuote, ShellQuoteArgs, _ParseIpOutput, TcpPing |
|
37 |
ShellQuote, ShellQuoteArgs, _ParseIpOutput, TcpPing, \ |
|
38 |
ListVisibleFiles |
|
38 | 39 |
from ganeti.errors import LockError, UnitParseError |
39 | 40 |
|
40 | 41 |
|
... | ... | |
522 | 523 |
"failed to ping alive host on deaf port") |
523 | 524 |
|
524 | 525 |
|
526 |
class TestListVisibleFiles(unittest.TestCase): |
|
527 |
"""Test case for ListVisibleFiles""" |
|
528 |
|
|
529 |
def setUp(self): |
|
530 |
self.path = tempfile.mkdtemp() |
|
531 |
|
|
532 |
def tearDown(self): |
|
533 |
shutil.rmtree(self.path) |
|
534 |
|
|
535 |
def _test(self, files, expected): |
|
536 |
# Sort a copy |
|
537 |
expected = expected[:] |
|
538 |
expected.sort() |
|
539 |
|
|
540 |
for name in files: |
|
541 |
f = open(os.path.join(self.path, name), 'w') |
|
542 |
try: |
|
543 |
f.write("Test\n") |
|
544 |
finally: |
|
545 |
f.close() |
|
546 |
|
|
547 |
found = ListVisibleFiles(self.path) |
|
548 |
found.sort() |
|
549 |
|
|
550 |
self.assertEqual(found, expected) |
|
551 |
|
|
552 |
def testAllVisible(self): |
|
553 |
files = ["a", "b", "c"] |
|
554 |
expected = files |
|
555 |
self._test(files, expected) |
|
556 |
|
|
557 |
def testNoneVisible(self): |
|
558 |
files = [".a", ".b", ".c"] |
|
559 |
expected = [] |
|
560 |
self._test(files, expected) |
|
561 |
|
|
562 |
def testSomeVisible(self): |
|
563 |
files = ["a", "b", ".c"] |
|
564 |
expected = ["a", "b"] |
|
565 |
self._test(files, expected) |
|
566 |
|
|
567 |
|
|
525 | 568 |
if __name__ == '__main__': |
526 | 569 |
unittest.main() |
Also available in: Unified diff