1 # This program is free software; you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation; either version 2 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU Library General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # See the COPYING file for license information.
17 # Copyright (c) 2006, 2007, 2008 Guillaume Chazarain <guichaz@gmail.com>
20 from pysize
.core
import pysize_fs_node
21 from pysize
.core
.pysize_global_fs_cache
import drop_caches
23 def create_root_node(fullpath
, *args
):
24 return pysize_fs_node
.create_node(None, [fullpath
], [fullpath
], *args
)
27 class fake_options(object):
29 self
.cross_device
= True
32 def value(n
, op
, name
):
35 print type(n
), n
.basename
, name
, '=>', res
39 checksum
+= value(n
, lambda n
: n
.compute_height(), 'height')
40 checksum
+= value(n
, lambda n
: n
.compute_depth(), 'depth')
41 checksum
+= value(n
, lambda n
: n
.minimum_node_size(), 'min_node_size')
42 checksum
+= value(n
, lambda n
: len(n
.get_dirname()), 'dirname')
43 checksum
+= value(n
, lambda n
: n
.is_dir() and 1 or 2, 'is_dir')
44 checksum
+= value(n
, lambda n
: n
.is_real() and 3 or 5, 'is_real')
45 checksum
+= value(n
, lambda n
: len(n
.get_fullname()), 'fullname')
46 checksum
+= value(n
, lambda n
: len(','.join(n
.get_fullpaths())), 'fp')
47 checksum
+= value(n
, lambda n
: len(n
.get_name()), 'get_name')
50 class TestFsNode(unittest
.TestCase
):
53 node
= create_root_node('/tmp/pysize_example_dir', 10, 10000,
55 self
.assertEqual(node
.get_fullname(), '/tmp/pysize_example_dir')
56 self
.assertEqual(node
.compute_height(), 6)
57 self
.assertEqual(node
.compute_depth(), 1)
58 self
.assertEqual(node
.minimum_node_size(), 12288)
59 self
.assertEqual(node
.get_dirname(), '/tmp')
60 self
.assert_(node
.is_dir())
61 self
.assertEqual(checksum(node
), 8866642)
62 child
= node
.children
[0]
63 self
.assertEqual(child
.get_fullname(),
64 '/tmp/pysize_example_dir/UTF-8_dir_\xc3\xa9_\xc3\xa0')
65 self
.assertEqual(child
.get_name(), 'UTF-8_dir_\xc3\xa9_\xc3\xa0/')
69 paths
= ['/tmp/pysize_example_dir/dir_symlink/hardlinks/0/%d' % i
for i
71 node
= pysize_fs_node
.create_node(None, paths
, paths
, 10, 1000,
73 self
.assertEqual(node
.get_fullname(),
74 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/{0,1,2,3,4,5,6,7,8,9}')
75 self
.assertEqual(node
.compute_height(), 3)
76 self
.assertEqual(node
.compute_depth(), 1)
77 self
.assertEqual(node
.minimum_node_size(), 4096)
78 self
.assertEqual(node
.get_dirname(),
79 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0')
80 self
.failIf(node
.is_dir())
81 self
.assertEqual(checksum(node
), 502156)
82 child
= node
.children
[0]
83 self
.assertEqual(child
.get_fullname(),
84 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/0')
85 self
.assertEqual(child
.get_name(), '0/')
89 node
= create_root_node('/tmp/pysize_example_dir/unreadable_file', 10,
90 10000, fake_options())
91 self
.assertEqual(node
.get_name(),
92 '/tmp/pysize_example_dir/unreadable_file')
93 self
.assertEqual(checksum(node
), 12434)
97 node
= pysize_fs_node
.create_node(None, None, None, None, None,
99 self
.assertEqual(node
.get_fullname(), '')
101 TESTS
= (TestFsNode
,)