~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/testhashcache.py

  • Committer: Martin Pool
  • Date: 2005-09-29 05:06:14 UTC
  • mto: (1185.12.2) (1393.1.12)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050929050614-a41e6f72af36bb4c
- better error on failing to import bzrlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import os
18
 
import sys
19
18
import time
20
 
from bzrlib.tests import TestCaseInTempDir
 
19
from bzrlib.selftest import TestCaseInTempDir
21
20
 
22
21
 
23
22
 
29
28
def pause():
30
29
    if False:
31
30
        return
32
 
    if sys.platform in ('win32', 'cygwin'):
 
31
    if os.name == 'nt':
33
32
        time.sleep(3)
34
33
        return
35
34
    # allow it to stabilize
47
46
 
48
47
        # make a dummy bzr directory just to hold the cache
49
48
        os.mkdir('.bzr')
50
 
        hc = HashCache(u'.')
 
49
        hc = HashCache('.')
51
50
 
52
51
        file('foo', 'wb').write('hello')
53
52
        os.mkdir('subdir')
61
60
        # check we hit without re-reading
62
61
        self.assertEquals(hc.get_sha1('foo'),
63
62
                          'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
64
 
        self.assertEquals(hc.miss_count, 1)
65
 
        self.assertEquals(hc.hit_count, 1)
 
63
        ##self.assertEquals(hc.miss_count, 1)
 
64
        ##self.assertEquals(hc.hit_count, 1)
66
65
 
67
66
        # check again without re-reading
68
67
        self.assertEquals(hc.get_sha1('foo'),
69
68
                          'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d')
70
 
        self.assertEquals(hc.miss_count, 1)
71
 
        self.assertEquals(hc.hit_count, 2)
 
69
        ##self.assertEquals(hc.miss_count, 1)
 
70
        ##self.assertEquals(hc.hit_count, 2)
72
71
 
73
72
        # write new file and make sure it is seen
74
73
        file('foo', 'wb').write('goodbye')
75
74
        pause()
76
75
        self.assertEquals(hc.get_sha1('foo'),
77
76
                          '3c8ec4874488f6090a157b014ce3397ca8e06d4f')
78
 
        self.assertEquals(hc.miss_count, 2)
 
77
        ##self.assertEquals(hc.miss_count, 2)
79
78
 
80
79
        # quickly write new file of same size and make sure it is seen
81
80
        # this may rely on detection of timestamps that are too close
101
100
 
102
101
        # should now be safe to cache it if we reread them
103
102
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
104
 
        self.assertEquals(len(hc._cache), 1)
 
103
        ##self.assertEquals(len(hc._cache), 1)
105
104
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
106
 
        self.assertEquals(len(hc._cache), 2)
 
105
        ##self.assertEquals(len(hc._cache), 2)
107
106
 
108
107
        # write out, read back in and check that we don't need to
109
108
        # re-read any files
110
109
        hc.write()
111
110
        del hc
112
111
 
113
 
        hc = HashCache(u'.')
 
112
        hc = HashCache('.')
114
113
        hc.read()
115
114
 
116
 
        self.assertEquals(len(hc._cache), 2)
 
115
        ##self.assertEquals(len(hc._cache), 2)
117
116
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
118
 
        self.assertEquals(hc.hit_count, 1)
119
 
        self.assertEquals(hc.miss_count, 0)
 
117
        ##self.assertEquals(hc.hit_count, 1)
 
118
        ##self.assertEquals(hc.miss_count, 0)
120
119
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))