~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test__dirstate_helpers.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-02 19:46:10 UTC
  • mfrom: (3640.2.6 dirstate_segv_186014)
  • Revision ID: pqm@pqm.ubuntu.com-20080902194610-1zzkeem0cm38snju
(jam) Fix bug #186014 by giving a proper exception if the dirstate
        cannot be parsed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
 
22
22
from bzrlib import (
23
23
    dirstate,
 
24
    errors,
24
25
    tests,
25
26
    )
26
27
from bzrlib.tests import test_dirstate
691
692
        self.assertEqual(dirstate.DirState.IN_MEMORY_UNMODIFIED,
692
693
                         state._dirblock_state)
693
694
 
 
695
    def test_trailing_garbage(self):
 
696
        tree, state, expected = self.create_basic_dirstate()
 
697
        # We can modify the file as long as it hasn't been read yet.
 
698
        f = open('dirstate', 'ab')
 
699
        try:
 
700
            # Add bogus trailing garbage
 
701
            f.write('bogus\n')
 
702
        finally:
 
703
            f.close()
 
704
        e = self.assertRaises(errors.DirstateCorrupt,
 
705
                              state._read_dirblocks_if_needed)
 
706
        # Make sure we mention the bogus characters in the error
 
707
        self.assertContainsRe(str(e), 'bogus')
 
708
 
694
709
 
695
710
class TestCompiledReadDirblocks(TestReadDirblocks):
696
711
    """Test the pyrex implementation of _read_dirblocks"""