~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-11-23 18:06:43 UTC
  • Revision ID: abentley@panoramicfeedback.com-20061123180643-6ry3xqozdbn4cfhy
Update docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os.path
2
1
from bzrlib.diff import _patch_header_date
3
2
import bzrlib.tests
 
3
import os.path
4
4
 
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
 
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
11
17
 
12
18
 
13
19
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
34
40
"""
35
41
    def _check_diff(self, diff=DIFF_1, filename='test_file'):
36
42
        old_tree = self.tree.basis_tree()
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()
 
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)
48
49
        keys = { 'filename' : filename , 'old_date': old_date, 
49
50
                 'new_date': new_date}
50
51
        hdr  = self.DIFF_HEADER % keys
54
55
    def _check_shelf(self, idx, diff=DIFF_1, filename='test_file',
55
56
                     new_date=None):
56
57
        old_tree = self.tree.basis_tree()
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()
 
58
        old_date = _patch_header_date(old_tree, 
 
59
                                      old_tree.inventory.path2id(filename),
 
60
                                      filename)
64
61
        diff = diff % { 'filename' : filename, 'old_date': old_date,
65
62
                        'new_date': new_date}
66
63
        shelf = open(os.path.join(self.tree.basedir,
77
74
    def __test_loop(self, count):
78
75
        self.tree = self.make_branch_and_tree('.')
79
76
        self.__create_and_add_test_file()
80
 
        for counter in range(count):
 
77
 
 
78
        while count > 0:
 
79
            count -= 1
 
80
 
81
81
            # Modify the test file
82
 
            # write in binary mode because on win32 line-endings should be
83
 
            # LF
 
82
            # write in binary mode because on win32 line-endings should be LF
84
83
            f = file('test_file', 'wb')
85
84
            f.write(self.MODIFIED)
86
85
            f.close()
87
86
 
88
87
            self._check_diff()
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()
 
88
            
 
89
            new_date = _patch_header_date(self.tree, 
 
90
                self.tree.inventory.path2id('test_file'), 'test_file')
96
91
 
97
92
            # Shelve the changes
98
93
            self.run_bzr('shelve', '--all', retcode=0)
318
313
 
319
314
    def test_shelf_delete(self):
320
315
        self.tree = self.make_branch_and_tree('.')
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()
 
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')
338
330
 
339
331
        # Shelve the changes
340
332
        self.run_bzr('shelve', '--all', 'test_file', retcode=0)
429
421
        self.run_bzr('shelf', 'ls', retcode=0)
430
422
 
431
423
        old_tree = self.tree.basis_tree()
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()
 
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')
443
430
        # Fake a -p0 shelved patch
444
431
        diff = self.DIFF_1 % { 'filename' : 'test_file', 'old_date': old_date,
445
432
                               'new_date' : new_date}
617
604
                                               '--no-color'])
618
605
        stdout, error = self.run_bzr_captured(['unshelve', '--all', 
619
606
                                               '--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')