~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2007-03-02 05:46:38 UTC
  • mto: (517.1.1 bzrtools-0.15)
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: aaron.bentley@utoronto.ca-20070302054638-9wnd7yu0kjv6uvjv
Fix all test suite bugs w/ dirstate

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
"""
34
34
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
35
35
        old_tree = self.tree.basis_tree()
36
 
        old_date = _patch_header_date(old_tree, 
37
 
                                      old_tree.inventory.path2id(filename),
38
 
                                      filename)
39
 
        new_date = _patch_header_date(self.tree, 
40
 
                                      self.tree.inventory.path2id(filename),
41
 
                                      filename)
 
36
        old_tree.lock_read()
 
37
        self.tree.lock_read()
 
38
        try:
 
39
            old_date = _patch_header_date(old_tree,
 
40
                                          old_tree.inventory.path2id(filename),
 
41
                                          filename)
 
42
            new_date = _patch_header_date(self.tree,
 
43
                self.tree.inventory.path2id(filename), filename)
 
44
        finally:
 
45
            old_tree.unlock()
42
46
        keys = { 'filename' : filename , 'old_date': old_date, 
43
47
                 'new_date': new_date}
44
48
        hdr  = self.DIFF_HEADER % keys
48
52
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
49
53
                     new_date=None):
50
54
        old_tree = self.tree.basis_tree()
51
 
        old_date = _patch_header_date(old_tree, 
52
 
                                      old_tree.inventory.path2id(filename),
53
 
                                      filename)
 
55
        old_tree.lock_read()
 
56
        try:
 
57
            old_date = _patch_header_date(old_tree,
 
58
                                          old_tree.inventory.path2id(filename),
 
59
                                          filename)
 
60
        finally:
 
61
            old_tree.unlock()
54
62
        diff = diff % { 'filename' : filename, 'old_date': old_date,
55
63
                        'new_date': new_date}
56
64
        shelf = open(os.path.join(self.tree.basedir,
306
314
 
307
315
    def test_shelf_delete(self):
308
316
        self.tree = self.make_branch_and_tree('.')
309
 
 
310
 
        self.__create_and_add_test_file()
311
 
        self.__create_and_add_test_file(filename='test_file2')
312
 
 
313
 
        # Modify the test files
314
 
        # write in binary mode because on win32 line-endings should be LF
315
 
        f = file('test_file', 'wb')
316
 
        f.write(self.MODIFIED)
317
 
        f.close()
318
 
        f = file('test_file2', 'wb')
319
 
        f.write(self.MODIFIED)
320
 
        f.close()
321
 
        new_date = _patch_header_date(self.tree, 
322
 
            self.tree.inventory.path2id('test_file'), 'test_file')
 
317
        self.tree.lock_write()
 
318
        try:
 
319
            self.__create_and_add_test_file()
 
320
            self.__create_and_add_test_file(filename='test_file2')
 
321
 
 
322
            # Modify the test files
 
323
            # write in binary mode because on win32 line-endings should be LF
 
324
            f = file('test_file', 'wb')
 
325
            f.write(self.MODIFIED)
 
326
            f.close()
 
327
            f = file('test_file2', 'wb')
 
328
            f.write(self.MODIFIED)
 
329
            f.close()
 
330
            new_date = _patch_header_date(self.tree,
 
331
                self.tree.inventory.path2id('test_file'), 'test_file')
 
332
        finally:
 
333
            self.tree.unlock()
323
334
 
324
335
        # Shelve the changes
325
336
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
414
425
        self.run_bzr('shelf', 'ls', retcode=0)
415
426
 
416
427
        old_tree = self.tree.basis_tree()
417
 
        old_date = _patch_header_date(old_tree, 
418
 
                                      old_tree.inventory.path2id('test_file'),
419
 
                                      'test_file')
420
 
        new_date = _patch_header_date(self.tree, 
421
 
                                      self.tree.inventory.path2id('test_file'),
422
 
                                      'test_file')
 
428
        old_tree.lock_read()
 
429
        self.tree.lock_read()
 
430
        try:
 
431
            old_date = _patch_header_date(old_tree,
 
432
                old_tree.inventory.path2id('test_file'),
 
433
                                          'test_file')
 
434
            new_date = _patch_header_date(self.tree,
 
435
                self.tree.inventory.path2id('test_file'), 'test_file')
 
436
        finally:
 
437
            old_tree.unlock()
 
438
            self.tree.unlock()
423
439
        # Fake a -p0 shelved patch
424
440
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
425
441
                               'new_date' : new_date}