~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_branch.py

(vila) Get rid of randomness in
 blackbox.test_branch.TestBranch.test_branch_broken_pack (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    def test_branch_broken_pack(self):
67
67
        """branching with a corrupted pack file."""
68
68
        self.example_branch('a')
69
 
        #now add some random corruption
70
 
        fname = 'a/.bzr/repository/packs/' + os.listdir('a/.bzr/repository/packs')[0]
 
69
        # add some corruption
 
70
        packs_dir = 'a/.bzr/repository/packs/'
 
71
        fname = packs_dir + os.listdir(packs_dir)[0]
71
72
        with open(fname, 'rb+') as f:
72
 
            f.seek(750)
73
 
            f.write("\xff")
 
73
            # Start from the end of the file to avoid choosing a place bigger
 
74
            # than the file itself.
 
75
            f.seek(-5, os.SEEK_END)
 
76
            c = f.read(1)
 
77
            f.seek(-5, os.SEEK_END)
 
78
            # Make sure we inject a value different than the one we just read
 
79
            if c == '\xFF':
 
80
                corrupt = '\x00'
 
81
            else:
 
82
                corrupt = '\xFF'
 
83
            f.write(corrupt) # make sure we corrupt something
74
84
        self.run_bzr_error(['Corruption while decompressing repository file'], 
75
85
                            'branch a b', retcode=3)
76
86