Ignore optimized python code as well.
[asure.git] / t_scan.py
blob88cd67e2b600cb6449fbec1b062461520dff051c
1 #! /usr/bin/env python
3 from stat import *
4 import unittest
5 import asure
6 import os
8 def rm_r(path):
9 try:
10 st = os.lstat(path)
11 except OSError:
12 return
13 if S_ISDIR(st.st_mode):
14 for child in os.listdir(path):
15 rm_r(os.path.join(path, child))
16 os.rmdir(path)
17 else:
18 os.unlink(path)
20 def touch(path):
21 if os.path.lexists(path):
22 raise ("Name already exists: %s" % path)
23 fd = open(path, 'w')
24 fd.close()
26 # Test Asure's directory scanning code.
27 class ScanUnitTest(unittest.TestCase):
28 def setUp(self):
29 rm_r("_test")
30 os.mkdir("_test")
32 def tearDown(self):
33 rm_r("_test")
35 def test_empty(self):
36 children = [x for x in asure.walk("_test")]
37 self.assertEqual(children, [('d', '.'), ('u', '.')])
39 def test_single(self):
40 touch("_test/aaaaa")
41 self.assertEqual([x for x in asure.walk("_test")],
42 [('d', '.'),
43 ('-', 'aaaaa'),
44 ('u', '.')])
46 def test_subdirs(self):
47 os.mkdir("_test/dir")
48 os.mkdir("_test/zdir")
49 touch("_test/aaa")
50 touch("_test/eee")
51 touch("_test/dir/aa")
52 children = [x for x in asure.walk("_test")]
53 self.assertEqual(children,
54 [('d', '.'),
55 ('d', 'dir'),
56 ('-', 'aa'),
57 ('u', 'dir'),
58 ('d', 'zdir'),
59 ('u', 'zdir'),
60 ('-', 'aaa'),
61 ('-', 'eee'),
62 ('u', '.')])
64 if __name__ == '__main__':
65 unittest.main()