~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to tests/shelf_tests.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-18 20:37:53 UTC
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: bialix@ukr.net-20060718203753-fa30c2f3cc59316b
don't use curses on win32

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'
564
552
        # Hex and is cracky, so it shouldn't work
565
553
        stdout, error = self.run_bzr_captured(['unshelve', '0x00'], retcode=3)
566
554
        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'])