Use setuptools instead of distutils for setup.py and allow to build working RPM
[pysize.git] / tests / tests / fs_node.py
blobebd5ad77238b06c404e3326947ade96f9a424c3e
1 import unittest
2 from pysize.core import pysize_fs_node
3 from pysize.core.pysize_global_fs_cache import drop_caches
5 def checksum(node):
6 def value(n, op, name):
7 res = op(n)
8 if False:
9 print type(n), n.basename, name, "=>", res
10 return res
11 checksum = 0
12 for n in node:
13 checksum += value(n, lambda n: n.compute_height(), 'height')
14 checksum += value(n, lambda n: n.compute_depth(), 'depth')
15 checksum += value(n, lambda n: n.minimum_real_size(), 'min_real_size')
16 checksum += value(n, lambda n: len(n.get_dirname()), 'dirname')
17 checksum += value(n, lambda n: n.is_dir() and 1 or 2, 'is_dir')
18 checksum += value(n, lambda n: n.is_real() and 3 or 5, 'is_real')
19 checksum += value(n, lambda n: len(n.get_fullname()), 'fullname')
20 checksum += value(n, lambda n: len(",".join(n.get_fullpaths())), 'fp')
21 checksum += value(n, lambda n: len(n.get_name()), 'get_name')
22 return checksum
24 class TestFsNode(unittest.TestCase):
25 def testTree(self):
26 drop_caches()
27 node = pysize_fs_node.create_node(None, '/tmp/pysize_example_dir', 10,
28 10000)
29 self.assertEqual(node.get_fullname(), '/tmp/pysize_example_dir')
30 self.assertEqual(node.compute_height(), 6)
31 self.assertEqual(node.compute_depth(), 1)
32 self.assertEqual(node.minimum_real_size(), 12288)
33 self.assertEqual(node.get_dirname(), '/tmp')
34 self.assert_(node.is_dir())
35 self.assertEqual(checksum(node), 5221101)
36 child = node.children[0]
37 self.assertEqual(child.get_fullname(),
38 '/tmp/pysize_example_dir/UTF-8_dir_\xc3\xa9_\xc3\xa0')
39 self.assertEqual(child.get_name(), 'UTF-8_dir_\xc3\xa9_\xc3\xa0/')
41 def testForest(self):
42 drop_caches()
43 paths = ['/tmp/pysize_example_dir/dir_symlink/hardlinks/0/%d' % i for i
44 in xrange(10)]
45 node = pysize_fs_node.create_node(None, paths, 10, 1000)
46 self.assertEqual(node.get_fullname(),
47 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/{0,1,2,3,4,5,6,7,8,9}')
48 self.assertEqual(node.compute_height(), 3)
49 self.assertEqual(node.compute_depth(), 1)
50 self.assertEqual(node.minimum_real_size(), 4096)
51 self.assertEqual(node.get_dirname(),
52 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0')
53 self.failIf(node.is_dir())
54 self.assertEqual(checksum(node), 502156)
55 child = node.children[0]
56 self.assertEqual(child.get_fullname(),
57 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/0')
58 self.assertEqual(child.get_name(), '0/')
60 def testFile(self):
61 drop_caches()
62 node = pysize_fs_node.create_node(None,
63 ['/tmp/pysize_example_dir/unreadable_file'], 10, 10000)
64 self.assertEqual(node.get_name(),
65 '/tmp/pysize_example_dir/unreadable_file')
66 self.assertEqual(checksum(node), 12434)
68 def testInit(self):
69 drop_caches()
70 node = pysize_fs_node.create_node(None, None, None, None)
71 self.assertEqual(node.get_fullname(), '')
73 TESTS = (TestFsNode,)