~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testhashcache.py

  • Committer: Martin Pool
  • Date: 2005-08-25 07:46:11 UTC
  • Revision ID: mbp@sourcefrog.net-20050825074611-98130ea6d05d9d2a
- add functions to enable and disable default logging, so that we can
  turn it off while running the tests

- default logging gets turned on from the bzr main function so that
  other applications using the library can make their own decisions

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
        time.sleep(0.2)
32
32
    
33
33
 
 
34
class TestHashCache(InTempDir):
34
35
 
35
 
class TestStatCache(InTempDir):
36
 
    """Functional tests for statcache"""
37
 
    def runTest(self):
 
36
    def test_hashcache(self):
 
37
        """Functional tests for hashcache"""
38
38
        from bzrlib.hashcache import HashCache
39
39
        import os
40
40
        import time
41
41
 
 
42
        # make a dummy bzr directory just to hold the cache
 
43
        os.mkdir('.bzr')
42
44
        hc = HashCache('.')
43
45
 
44
46
        file('foo', 'wb').write('hello')
75
77
        file('foo', 'wb').write('g00dbye')
76
78
        self.assertEquals(hc.get_sha1('foo'),
77
79
                          sha1('g00dbye'))
78
 
        
79
 
        # this is not quite guaranteed to be true; we might have
80
 
        # crossed a 1s boundary before
81
 
        self.assertEquals(hc.danger_count, 1)
 
80
 
 
81
        file('foo2', 'wb').write('other file')
 
82
        self.assertEquals(hc.get_sha1('foo2'), sha1('other file'))
 
83
 
 
84
        os.remove('foo2')
 
85
        self.assertEquals(hc.get_sha1('foo2'), None)
 
86
 
 
87
        file('foo2', 'wb').write('new content')
 
88
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
82
89
 
83
90
        self.assertEquals(hc.get_sha1('subdir'), None)
84
91
 
85
 
 
86
 
 
87
 
TEST_CLASSES = [
88
 
    TestStatCache,
89
 
    ]
 
92
        # it's likely neither are cached at the moment because they 
 
93
        # changed recently, but we can't be sure
 
94
        pause()
 
95
 
 
96
        # should now be safe to cache it if we reread them
 
97
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
 
98
        self.assertEquals(len(hc._cache), 1)
 
99
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
100
        self.assertEquals(len(hc._cache), 2)
 
101
 
 
102
        # write out, read back in and check that we don't need to
 
103
        # re-read any files
 
104
        hc.write()
 
105
        del hc
 
106
 
 
107
        hc = HashCache('.')
 
108
        hc.read()
 
109
 
 
110
        self.assertEquals(len(hc._cache), 2)
 
111
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
 
112
        self.assertEquals(hc.hit_count, 1)
 
113
        self.assertEquals(hc.miss_count, 0)
 
114
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))