"Fossies" - the Fresh Open Source Software Archive 
Member "pysize-0.2/tests/tests/fs_node.py" (11 Mar 2007, 4342 Bytes) of package /linux/privat/old/pysize-0.2.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
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.
5 #
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.
10 #
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.
14 #
15 # See the COPYING file for license information.
16 #
17 # Copyright (c) 2006, 2007 Guillaume Chazarain <guichaz@yahoo.fr>
18
19 import unittest
20 from pysize.core import pysize_fs_node
21 from pysize.core.pysize_global_fs_cache import drop_caches
22
23 class fake_options(object):
24 def __init__(self):
25 self.cross_device = True
26
27 def checksum(node):
28 def value(n, op, name):
29 res = op(n)
30 if False:
31 print type(n), n.basename, name, '=>', res
32 return res
33 checksum = 0
34 for n in node:
35 checksum += value(n, lambda n: n.compute_height(), 'height')
36 checksum += value(n, lambda n: n.compute_depth(), 'depth')
37 checksum += value(n, lambda n: n.minimum_node_size(), 'min_node_size')
38 checksum += value(n, lambda n: len(n.get_dirname()), 'dirname')
39 checksum += value(n, lambda n: n.is_dir() and 1 or 2, 'is_dir')
40 checksum += value(n, lambda n: n.is_real() and 3 or 5, 'is_real')
41 checksum += value(n, lambda n: len(n.get_fullname()), 'fullname')
42 checksum += value(n, lambda n: len(','.join(n.get_fullpaths())), 'fp')
43 checksum += value(n, lambda n: len(n.get_name()), 'get_name')
44 return checksum
45
46 class TestFsNode(unittest.TestCase):
47 def testTree(self):
48 drop_caches()
49 node = pysize_fs_node.create_node(None, '/tmp/pysize_example_dir', 10,
50 10000, fake_options())
51 self.assertEqual(node.get_fullname(), '/tmp/pysize_example_dir')
52 self.assertEqual(node.compute_height(), 6)
53 self.assertEqual(node.compute_depth(), 1)
54 self.assertEqual(node.minimum_node_size(), 12288)
55 self.assertEqual(node.get_dirname(), '/tmp')
56 self.assert_(node.is_dir())
57 self.assertEqual(checksum(node), 8866642)
58 child = node.children[0]
59 self.assertEqual(child.get_fullname(),
60 '/tmp/pysize_example_dir/UTF-8_dir_\xc3\xa9_\xc3\xa0')
61 self.assertEqual(child.get_name(), 'UTF-8_dir_\xc3\xa9_\xc3\xa0/')
62
63 def testForest(self):
64 drop_caches()
65 paths = ['/tmp/pysize_example_dir/dir_symlink/hardlinks/0/%d' % i for i
66 in xrange(10)]
67 node = pysize_fs_node.create_node(None, paths, 10, 1000, fake_options())
68 self.assertEqual(node.get_fullname(),
69 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/{0,1,2,3,4,5,6,7,8,9}')
70 self.assertEqual(node.compute_height(), 3)
71 self.assertEqual(node.compute_depth(), 1)
72 self.assertEqual(node.minimum_node_size(), 4096)
73 self.assertEqual(node.get_dirname(),
74 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0')
75 self.failIf(node.is_dir())
76 self.assertEqual(checksum(node), 502156)
77 child = node.children[0]
78 self.assertEqual(child.get_fullname(),
79 '/tmp/pysize_example_dir/dir_symlink/hardlinks/0/0')
80 self.assertEqual(child.get_name(), '0/')
81
82 def testFile(self):
83 drop_caches()
84 node = pysize_fs_node.create_node(None,
85 ['/tmp/pysize_example_dir/unreadable_file'], 10, 10000,
86 fake_options())
87 self.assertEqual(node.get_name(),
88 '/tmp/pysize_example_dir/unreadable_file')
89 self.assertEqual(checksum(node), 12434)
90
91 def testInit(self):
92 drop_caches()
93 node = pysize_fs_node.create_node(None, None, None, None,
94 fake_options())
95 self.assertEqual(node.get_fullname(), '')
96
97 TESTS = (TestFsNode,)