2 from pysize
.core
import compute_size
3 from pysize
.core
.compute_size
import size_observable
4 from pysize
.core
.pysize_global_fs_cache
import drop_caches
6 class TestComputeSize(unittest
.TestCase
):
9 self
.assertEqual(compute_size
.slow('/tmp/pysize_example_dir'), 4608000)
10 # Retry using cached results
11 self
.assertEqual(compute_size
.slow('/tmp/pysize_example_dir'), 4608000)
13 def testSizeFile(self
):
15 size
= compute_size
.slow('/tmp/pysize_example_dir/unreadable_file')
16 self
.assertEqual(size
, 12288)
18 def testSizeNoSuchPath(self
):
20 self
.assertEqual(compute_size
.slow('/no such/ path'), 0)
22 def testSizeCache(self
):
25 size_observable
.add_observer(inc_nr_calls
)
28 self
.assertEqual(compute_size
.slow('/tmp/pysize_example_dir'), 4608000)
29 self
.assertEqual(self
.nr_calls
, 10132)
30 self
.assertEqual(compute_size
.slow('/tmp/pysize_example_dir'), 4608000)
31 self
.assertEqual(self
.nr_calls
, 10133)
32 size_observable
.del_observer(inc_nr_calls
)
33 self
.assertEqual(compute_size
.slow('/tmp/pysize_example_dir'), 4608000)
34 self
.assertEqual(self
.nr_calls
, 10133)
36 TESTS
= (TestComputeSize
,)