~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2007-06-12 22:09:44 UTC
  • mfrom: (540.1.2 bzrtools-0.17)
  • Revision ID: aaron.bentley@utoronto.ca-20070612220944-5zw4hlzp1ctq6mkl
Merge fixes from 0.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os.path
1
2
from bzrlib.diff import _patch_header_date
2
3
import bzrlib.tests
3
 
import os.path
4
4
 
5
 
try:
6
 
    from bzrlib.plugins.bzrtools.hunk_selector import (
7
 
        ShelveHunkSelector,
8
 
        UnshelveHunkSelector,
9
 
        )
10
 
    from bzrlib.plugins.bzrtools.errors import NoColor
11
 
except ImportError:
12
 
    from bzrtools.hunk_selector import (
13
 
        ShelveHunkSelector,
14
 
        UnshelveHunkSelector,
15
 
        )
16
 
    from bzrtools.errors import NoColor
 
5
from bzrlib.plugins.bzrtools.hunk_selector import (
 
6
    ShelveHunkSelector,
 
7
    UnshelveHunkSelector,
 
8
    )
 
9
from bzrlib.plugins.bzrtools.errors import NoColor
 
10
from bzrlib.plugins.bzrtools import cmd_shelf
17
11
 
18
12
 
19
13
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
40
34
"""
41
35
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
42
36
        old_tree = self.tree.basis_tree()
43
 
        old_date = _patch_header_date(old_tree, 
44
 
                                      old_tree.inventory.path2id(filename),
45
 
                                      filename)
46
 
        new_date = _patch_header_date(self.tree, 
47
 
                                      self.tree.inventory.path2id(filename),
48
 
                                      filename)
49
 
        keys = { 'filename' : filename , 'old_date': old_date, 
 
37
        old_tree.lock_read()
 
38
        self.tree.lock_read()
 
39
        try:
 
40
            old_date = _patch_header_date(old_tree,
 
41
                                          old_tree.inventory.path2id(filename),
 
42
                                          filename)
 
43
            new_date = _patch_header_date(self.tree,
 
44
                self.tree.inventory.path2id(filename), filename)
 
45
        finally:
 
46
            self.tree.unlock()
 
47
            old_tree.unlock()
 
48
        keys = { 'filename' : filename , 'old_date': old_date,
50
49
                 'new_date': new_date}
51
50
        hdr  = self.DIFF_HEADER % keys
52
51
        diff = diff % keys
55
54
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
56
55
                     new_date=None):
57
56
        old_tree = self.tree.basis_tree()
58
 
        old_date = _patch_header_date(old_tree, 
59
 
                                      old_tree.inventory.path2id(filename),
60
 
                                      filename)
 
57
        old_tree.lock_read()
 
58
        try:
 
59
            old_date = _patch_header_date(old_tree,
 
60
                                          old_tree.inventory.path2id(filename),
 
61
                                          filename)
 
62
        finally:
 
63
            old_tree.unlock()
61
64
        diff = diff % { 'filename' : filename, 'old_date': old_date,
62
65
                        'new_date': new_date}
63
66
        shelf = open(os.path.join(self.tree.basedir,
74
77
    def __test_loop(self, count):
75
78
        self.tree = self.make_branch_and_tree('.')
76
79
        self.__create_and_add_test_file()
77
 
 
78
 
        while count > 0:
79
 
            count -= 1
80
 
 
 
80
        for counter in range(count):
81
81
            # Modify the test file
82
 
            # write in binary mode because on win32 line-endings should be LF
 
82
            # write in binary mode because on win32 line-endings should be
 
83
            # LF
83
84
            f = file('test_file', 'wb')
84
85
            f.write(self.MODIFIED)
85
86
            f.close()
86
87
 
87
88
            self._check_diff()
88
 
            
89
 
            new_date = _patch_header_date(self.tree, 
90
 
                self.tree.inventory.path2id('test_file'), 'test_file')
 
89
 
 
90
            self.tree.lock_write()
 
91
            try:
 
92
                new_date = _patch_header_date(self.tree,
 
93
                    self.tree.inventory.path2id('test_file'), 'test_file')
 
94
            finally:
 
95
                self.tree.unlock()
91
96
 
92
97
            # Shelve the changes
93
98
            self.run_bzr('shelve', '--all', retcode=0)
313
318
 
314
319
    def test_shelf_delete(self):
315
320
        self.tree = self.make_branch_and_tree('.')
316
 
 
317
 
        self.__create_and_add_test_file()
318
 
        self.__create_and_add_test_file(filename='test_file2')
319
 
 
320
 
        # Modify the test files
321
 
        # write in binary mode because on win32 line-endings should be LF
322
 
        f = file('test_file', 'wb')
323
 
        f.write(self.MODIFIED)
324
 
        f.close()
325
 
        f = file('test_file2', 'wb')
326
 
        f.write(self.MODIFIED)
327
 
        f.close()
328
 
        new_date = _patch_header_date(self.tree, 
329
 
            self.tree.inventory.path2id('test_file'), 'test_file')
 
321
        self.tree.lock_write()
 
322
        try:
 
323
            self.__create_and_add_test_file()
 
324
            self.__create_and_add_test_file(filename='test_file2')
 
325
 
 
326
            # Modify the test files
 
327
            # write in binary mode because on win32 line-endings should be LF
 
328
            f = file('test_file', 'wb')
 
329
            f.write(self.MODIFIED)
 
330
            f.close()
 
331
            f = file('test_file2', 'wb')
 
332
            f.write(self.MODIFIED)
 
333
            f.close()
 
334
            new_date = _patch_header_date(self.tree,
 
335
                self.tree.inventory.path2id('test_file'), 'test_file')
 
336
        finally:
 
337
            self.tree.unlock()
330
338
 
331
339
        # Shelve the changes
332
340
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
421
429
        self.run_bzr('shelf', 'ls', retcode=0)
422
430
 
423
431
        old_tree = self.tree.basis_tree()
424
 
        old_date = _patch_header_date(old_tree, 
425
 
                                      old_tree.inventory.path2id('test_file'),
426
 
                                      'test_file')
427
 
        new_date = _patch_header_date(self.tree, 
428
 
                                      self.tree.inventory.path2id('test_file'),
429
 
                                      'test_file')
 
432
        old_tree.lock_read()
 
433
        self.tree.lock_read()
 
434
        try:
 
435
            old_date = _patch_header_date(old_tree,
 
436
                old_tree.inventory.path2id('test_file'),
 
437
                                          'test_file')
 
438
            new_date = _patch_header_date(self.tree,
 
439
                self.tree.inventory.path2id('test_file'), 'test_file')
 
440
        finally:
 
441
            old_tree.unlock()
 
442
            self.tree.unlock()
430
443
        # Fake a -p0 shelved patch
431
444
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
432
445
                               'new_date' : new_date}
600
613
        f = file('test_file', 'wb')
601
614
        f.write(self.MODIFIED)
602
615
        f.close()
603
 
        stdout, error = self.run_bzr_captured(['shelve', '--all', 
604
 
                                               '--no-color'])
605
 
        stdout, error = self.run_bzr_captured(['unshelve', '--all', 
606
 
                                               '--no-color'])
 
616
        stdout, error = self.run_bzr_captured(['shelve', '--all',
 
617
                                               '--no-color'])
 
618
        stdout, error = self.run_bzr_captured(['unshelve', '--all',
 
619
                                               '--no-color'])
 
620
 
 
621
    def test_shelf_help(self):
 
622
        self.assertContainsRe(cmd_shelf().help(),
 
623
                              'list\n.*List the patches on the current shelf')