~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testhashcache.py

  • Committer: Martin Pool
  • Date: 2005-07-08 02:49:15 UTC
  • Revision ID: mbp@sourcefrog.net-20050708024914-c942829444e54137
- more hashcache tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
        file('foo', 'wb').write('g00dbye')
76
76
        self.assertEquals(hc.get_sha1('foo'),
77
77
                          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)
82
 
        self.assertEquals(len(hc._cache), 0)
 
78
 
 
79
        file('foo2', 'wb').write('other file')
 
80
        self.assertEquals(hc.get_sha1('foo2'), sha1('other file'))
 
81
 
 
82
        os.remove('foo2')
 
83
        self.assertEquals(hc.get_sha1('foo2'), None)
 
84
 
 
85
        file('foo2', 'wb').write('new content')
 
86
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
83
87
 
84
88
        self.assertEquals(hc.get_sha1('subdir'), None)
85
89
 
 
90
        # it's likely neither are cached at the moment because they 
 
91
        # changed recently, but we can't be sure
86
92
        pause()
87
93
 
88
 
        # should now be safe to cache it
89
 
        self.assertEquals(hc.get_sha1('foo'),
90
 
                          sha1('g00dbye'))
 
94
        # should now be safe to cache it if we reread them
 
95
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
91
96
        self.assertEquals(len(hc._cache), 1)
 
97
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
98
        self.assertEquals(len(hc._cache), 2)
92
99
 
93
100
        # write out, read back in and check that we don't need to
94
101
        # re-read any files
98
105
        hc = HashCache('.')
99
106
        hc.read('stat-cache')
100
107
 
101
 
        self.assertEquals(len(hc._cache), 1)
 
108
        self.assertEquals(len(hc._cache), 2)
102
109
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
103
110
        self.assertEquals(hc.hit_count, 1)
104
111
        self.assertEquals(hc.miss_count, 0)
 
112
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
113
 
105
114
        
106
115
 
107
116