2 from pysize
.core
import pysize_fs_node
3 from pysize
.core
.pysize_global_fs_cache
import drop_caches
6 def value(n
, op
, name
):
9 print type(n
), n
.basename
, name
, "=>", res
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')
24 class TestFsNode(unittest
.TestCase
):
27 node
= pysize_fs_node
.create_node(None, '/tmp/pysize_example_dir', 10,
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/')
43 paths
= ['/tmp/pysize_example_dir/dir_symlink/hardlinks/0/%d' % i
for i
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/')
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)
70 node
= pysize_fs_node
.create_node(None, None, None, None)
71 self
.assertEqual(node
.get_fullname(), '')