~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hashcache.py

first cut at merge from integration.

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 sha
19
18
import sys
20
19
import time
 
20
from bzrlib.tests import TestCaseInTempDir
21
21
 
22
 
from bzrlib.errors import BzrError
23
 
from bzrlib.hashcache import HashCache
24
 
from bzrlib.tests import TestCaseInTempDir, TestSkipped
25
22
 
26
23
 
27
24
def sha1(t):
 
25
    import sha
28
26
    return sha.new(t).hexdigest()
29
27
 
30
28
 
48
46
 
49
47
    def test_hashcache(self):
50
48
        """Functional tests for hashcache"""
 
49
        from bzrlib.hashcache import HashCache
 
50
        import os
51
51
 
52
52
        # make a dummy bzr directory just to hold the cache
53
53
        os.mkdir('.bzr')
54
 
        hc = HashCache('.', '.bzr/stat-cache')
 
54
        hc = HashCache(u'.')
55
55
 
56
56
        file('foo', 'wb').write('hello')
57
57
        os.mkdir('subdir')
99
99
 
100
100
        self.assertEquals(hc.get_sha1('subdir'), None)
101
101
 
102
 
        # pause briefly to make sure they're not treated as new uncacheable
103
 
        # files
 
102
        # it's likely neither are cached at the moment because they 
 
103
        # changed recently, but we can't be sure
104
104
        pause()
105
105
 
 
106
        # should now be safe to cache it if we reread them
106
107
        self.assertEquals(hc.get_sha1('foo'), sha1('g00dbye'))
 
108
        self.assertEquals(len(hc._cache), 1)
107
109
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
110
        self.assertEquals(len(hc._cache), 2)
108
111
 
109
112
        # write out, read back in and check that we don't need to
110
113
        # re-read any files
111
114
        hc.write()
112
115
        del hc
113
116
 
114
 
        hc = HashCache('.', '.bzr/stat-cache')
 
117
        hc = HashCache(u'.')
115
118
        hc.read()
116
119
 
117
120
        self.assertEquals(len(hc._cache), 2)
122
125
 
123
126
    def test_hashcache_raise(self):
124
127
        """check that hashcache can raise BzrError"""
 
128
        from bzrlib.hashcache import HashCache
 
129
        import os
125
130
 
126
131
        os.mkdir('.bzr')
127
 
        hc = HashCache('.', '.bzr/stat-cache')
 
132
        hc = HashCache(u'.')
128
133
        ok = False
129
134
 
130
135
        # make a best effort to create a weird kind of file
131
 
        funcs = (getattr(os, 'mkfifo', None), getattr(os, 'mknod', None))
 
136
        funcs = (os.mkfifo, os.mknod)
132
137
        for func in funcs:
133
 
            if func is None:
134
 
                continue
135
138
            try:
136
139
                func('a')
137
140
                ok = True
139
142
            except FixThisError:
140
143
                pass
141
144
 
 
145
        from bzrlib.errors import BzrError
142
146
        if ok:
143
147
            self.assertRaises(BzrError, hc.get_sha1, 'a')
144
148
        else:
145
 
            raise TestSkipped('No weird file type could be created')
 
149
            raise BzrError("no weird file type could be created: extend this test case for your os")