~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hashcache.py

  • Committer: John Arbash Meinel
  • Date: 2006-02-15 15:18:44 UTC
  • mto: (1185.79.1 bzr-jam-pending)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: john@arbash-meinel.com-20060215151844-ce3e3efccd19da3f
Reverting gpg changes, should not be mainline, see gpg_uses_tempfile plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
from bzrlib.selftest import InTempDir
 
17
import os
 
18
import sys
 
19
import time
 
20
from bzrlib.tests import TestCaseInTempDir
18
21
 
19
22
 
20
23
 
24
27
 
25
28
 
26
29
def pause():
27
 
    import time
 
30
    if False:
 
31
        return
 
32
    if sys.platform in ('win32', 'cygwin'):
 
33
        time.sleep(3)
 
34
        return
28
35
    # allow it to stabilize
29
36
    start = int(time.time())
30
37
    while int(time.time()) == start:
31
38
        time.sleep(0.2)
 
39
 
 
40
 
 
41
class FixThisError(Exception):
 
42
    pass
32
43
    
33
44
 
34
 
class TestHashCache(InTempDir):
 
45
class TestHashCache(TestCaseInTempDir):
35
46
 
36
47
    def test_hashcache(self):
37
48
        """Functional tests for hashcache"""
38
49
        from bzrlib.hashcache import HashCache
39
50
        import os
40
 
        import time
41
51
 
42
52
        # make a dummy bzr directory just to hold the cache
43
53
        os.mkdir('.bzr')
44
 
        hc = HashCache('.')
 
54
        hc = HashCache(u'.')
45
55
 
46
56
        file('foo', 'wb').write('hello')
47
57
        os.mkdir('subdir')
104
114
        hc.write()
105
115
        del hc
106
116
 
107
 
        hc = HashCache('.')
 
117
        hc = HashCache(u'.')
108
118
        hc.read()
109
119
 
110
120
        self.assertEquals(len(hc._cache), 2)
112
122
        self.assertEquals(hc.hit_count, 1)
113
123
        self.assertEquals(hc.miss_count, 0)
114
124
        self.assertEquals(hc.get_sha1('foo2'), sha1('new content'))
 
125
 
 
126
    def test_hashcache_raise(self):
 
127
        """check that hashcache can raise BzrError"""
 
128
        from bzrlib.hashcache import HashCache
 
129
        import os
 
130
 
 
131
        os.mkdir('.bzr')
 
132
        hc = HashCache(u'.')
 
133
        ok = False
 
134
 
 
135
        # make a best effort to create a weird kind of file
 
136
        funcs = (os.mkfifo, os.mknod)
 
137
        for func in funcs:
 
138
            try:
 
139
                func('a')
 
140
                ok = True
 
141
                break
 
142
            except FixThisError:
 
143
                pass
 
144
 
 
145
        from bzrlib.errors import BzrError
 
146
        if ok:
 
147
            self.assertRaises(BzrError, hc.get_sha1, 'a')
 
148
        else:
 
149
            raise BzrError("no weird file type could be created: extend this test case for your os")