~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Aaron Bentley
  • Date: 2007-01-15 15:19:20 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070115151920-pb4eto22dzk34co2
Add --silent option to patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
1
from bzrlib.diff import _patch_header_date
4
2
import bzrlib.tests
5
3
import os.path
6
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
 
17
 
 
18
 
7
19
class ShelfTests(bzrlib.tests.TestCaseWithTransport):
8
20
    ORIGINAL = '\n\nhello test world\n\n'
9
21
    MODIFIED = '\n\ngoodbye test world\n\n'
552
564
        # Hex and is cracky, so it shouldn't work
553
565
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
554
566
        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'])