~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-06-18 01:39:32 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060618013932-0162fdb3edab394b
Update is_clean test, now that commit returns a revision_id

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
1
3
from bzrlib.diff import _patch_header_date
2
4
import bzrlib.tests
3
5
import os.path
4
6
 
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
17
 
 
18
 
 
19
7
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
20
8
    ORIGINAL = '\n\nhello test world\n\n'
21
9
    MODIFIED = '\n\ngoodbye test world\n\n'
79
67
            count -= 1
80
68
 
81
69
            # Modify the test file
82
 
            # write in binary mode because on win32 line-endings should be LF
83
 
            f = file('test_file', 'wb')
84
 
            f.write(self.MODIFIED)
85
 
            f.close()
 
70
            file('test_file', 'w').write(self.MODIFIED)
86
71
 
87
72
            self._check_diff()
88
73
            
124
109
            self.fail("Shelf exists, but it shouldn't")
125
110
 
126
111
    def __create_and_add_test_file(self, filename='test_file'):
127
 
        # write in binary mode because on win32 line-endings should be LF
128
 
        f = open(filename, 'wb')
 
112
        f = open(filename, 'w')
129
113
        f.write(self.ORIGINAL)
130
114
        f.close()
131
115
        self.tree.add(self.tree.relpath(os.path.join(os.getcwd(), filename)))
318
302
        self.__create_and_add_test_file(filename='test_file2')
319
303
 
320
304
        # 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()
 
305
        file('test_file', 'w').write(self.MODIFIED)
 
306
        file('test_file2', 'w').write(self.MODIFIED)
328
307
        new_date = _patch_header_date(self.tree, 
329
308
            self.tree.inventory.path2id('test_file'), 'test_file')
330
309
 
450
429
        self.__create_and_add_test_file()
451
430
 
452
431
        # Modify the test file
453
 
        # write in binary mode because on win32 line-endings should be LF
454
 
        f = file('test_file', 'wb')
455
 
        f.write(self.MODIFIED)
456
 
        f.close()
 
432
        file('test_file', 'w').write(self.MODIFIED)
457
433
 
458
434
        # Shelve the changes
459
435
        self.run_bzr('shelve', '--all', retcode=0)
564
540
        # Hex and is cracky, so it shouldn't work
565
541
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
566
542
        self.assertTrue("Invalid patch name '0x00'" in error)
567
 
 
568
 
    def test_color_hunk_selector(self):
569
 
        """Make sure NoColor is raised iff terminal.has_ansi_colors is False"""
570
 
        hs = ShelveHunkSelector([])
571
 
        hs = UnshelveHunkSelector([])
572
 
        try:
573
 
            from bzrlib.plugins.bzrtools import terminal
574
 
        except ImportError:
575
 
            from bzrtools import terminal
576
 
        old_has_ansi_colors = terminal.has_ansi_colors
577
 
        terminal.has_ansi_colors = lambda: False
578
 
        try:
579
 
            self.assertRaises(NoColor, ShelveHunkSelector, [], True)
580
 
            self.assertRaises(NoColor, UnshelveHunkSelector, [], True)
581
 
            terminal.has_ansi_colors = lambda: True
582
 
            hs = ShelveHunkSelector([], color=True)
583
 
            hs = UnshelveHunkSelector([], color=True)
584
 
        finally:
585
 
            terminal.has_ansi_colors = old_has_ansi_colors
586
 
 
587
 
    def test_no_color(self):
588
 
        """Ensure --no-color switch can be passed"""
589
 
        self.tree = self.make_branch_and_tree('.')
590
 
 
591
 
        subdir = 'subdir'
592
 
        os.mkdir(subdir)
593
 
        self.tree.add(subdir)
594
 
        os.chdir(subdir)
595
 
 
596
 
        self.__create_and_add_test_file()
597
 
 
598
 
        # Modify the test file
599
 
        # write in binary mode because on win32 line-endings should be LF
600
 
        f = file('test_file', 'wb')
601
 
        f.write(self.MODIFIED)
602
 
        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'])