~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2006-08-07 03:07:35 UTC
  • mto: This revision was merged to the branch mainline in revision 425.
  • Revision ID: aaron.bentley@utoronto.ca-20060807030735-0a9f8330ce1a836a
Add --no-color option to shelf

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
import bzrlib.tests
3
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
 
5
11
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
6
12
    ORIGINAL = '\n\nhello test world\n\n'
7
13
    MODIFIED = '\n\ngoodbye test world\n\n'
550
556
        # Hex and is cracky, so it shouldn't work
551
557
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
552
558
        self.assertTrue("Invalid patch name '0x00'" in error)
 
559
 
 
560
    def test_color_hunk_selector(self):
 
561
        """Make sure NoColor is raised iff terminal.has_ansi_colors is False"""
 
562
        hs = ShelveHunkSelector([])
 
563
        hs = UnshelveHunkSelector([])
 
564
        from bzrlib.plugins.bzrtools import terminal
 
565
        old_has_ansi_colors = terminal.has_ansi_colors
 
566
        terminal.has_ansi_colors = lambda: False
 
567
        try:
 
568
            self.assertRaises(NoColor, ShelveHunkSelector, [], True)
 
569
            self.assertRaises(NoColor, UnshelveHunkSelector, [], True)
 
570
            terminal.has_ansi_colors = lambda: True
 
571
            hs = ShelveHunkSelector([], color=True)
 
572
            hs = UnshelveHunkSelector([], color=True)
 
573
        finally:
 
574
            terminal.has_ansi_colors = old_has_ansi_colors
 
575
 
 
576
    def test_no_color(self):
 
577
        """Ensure --no-color switch can be passed"""
 
578
        self.tree = self.make_branch_and_tree('.')
 
579
 
 
580
        subdir = 'subdir'
 
581
        os.mkdir(subdir)
 
582
        self.tree.add(subdir)
 
583
        os.chdir(subdir)
 
584
 
 
585
        self.__create_and_add_test_file()
 
586
 
 
587
        # Modify the test file
 
588
        # write in binary mode because on win32 line-endings should be LF
 
589
        f = file('test_file', 'wb')
 
590
        f.write(self.MODIFIED)
 
591
        f.close()
 
592
        stdout, error = self.run_bzr_captured(['shelve', '--all', 
 
593
                                               '--no-color'])
 
594
        stdout, error = self.run_bzr_captured(['unshelve', '--all', 
 
595
                                               '--no-color'])