/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/__init__.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 12:50:32 UTC
  • mfrom: (6679 work)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610125032-xb5rd5fjskjallos
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
92
92
    pass
93
93
from ..sixish import (
94
94
    BytesIO,
 
95
    PY3,
95
96
    string_types,
96
97
    text_type,
97
98
    )
1536
1537
    def assertFileEqual(self, content, path):
1537
1538
        """Fail if path does not contain 'content'."""
1538
1539
        self.assertPathExists(path)
1539
 
        f = file(path, 'rb')
1540
 
        try:
 
1540
        with open(path, 'rb') as f:
1541
1541
            s = f.read()
1542
 
        finally:
1543
 
            f.close()
1544
1542
        self.assertEqualDiff(content, s)
1545
1543
 
1546
1544
    def assertDocstring(self, expected_docstring, obj):
1553
1551
 
1554
1552
    def assertPathExists(self, path):
1555
1553
        """Fail unless path or paths, which may be abs or relative, exist."""
1556
 
        if not isinstance(path, basestring):
 
1554
        if not isinstance(path, (str, text_type)):
1557
1555
            for p in path:
1558
1556
                self.assertPathExists(p)
1559
1557
        else:
2663
2661
        """
2664
2662
        if format is None:
2665
2663
            format = self.get_default_format()
2666
 
        if isinstance(format, basestring):
 
2664
        if isinstance(format, str):
2667
2665
            format = controldir.format_registry.make_bzrdir(format)
2668
2666
        return format
2669
2667
 
2712
2710
 
2713
2711
    def overrideEnvironmentForTesting(self):
2714
2712
        test_home_dir = self.test_home_dir
2715
 
        if isinstance(test_home_dir, text_type):
 
2713
        if not PY3 and isinstance(test_home_dir, text_type):
2716
2714
            test_home_dir = test_home_dir.encode(sys.getfilesystemencoding())
2717
2715
        self.overrideEnv('HOME', test_home_dir)
2718
2716
        self.overrideEnv('BRZ_HOME', test_home_dir)
2771
2769
 
2772
2770
    def check_file_contents(self, filename, expect):
2773
2771
        self.log("check contents of file %s" % filename)
2774
 
        f = file(filename)
2775
 
        try:
 
2772
        with open(filename) as f:
2776
2773
            contents = f.read()
2777
 
        finally:
2778
 
            f.close()
2779
2774
        if contents != expect:
2780
2775
            self.log("expected: %r" % expect)
2781
2776
            self.log("actually: %r" % contents)
2822
2817
        os.mkdir(self.test_dir)
2823
2818
        os.chdir(self.test_dir)
2824
2819
        # put name of test inside
2825
 
        f = file(self.test_base_dir + '/name', 'w')
2826
 
        try:
 
2820
        with open(self.test_base_dir + '/name', 'w') as f:
2827
2821
            f.write(self.id())
2828
 
        finally:
2829
 
            f.close()
2830
2822
 
2831
2823
    def deleteTestDir(self):
2832
2824
        os.chdir(TestCaseWithMemoryTransport.TEST_ROOT)
4378
4370
    # except on win32, where rmtree(str) will fail
4379
4371
    # since it doesn't have the property of byte-stream paths
4380
4372
    # (they are either ascii or mbcs)
4381
 
    if sys.platform == 'win32':
 
4373
    if sys.platform == 'win32' and isinstance(dirname, bytes):
4382
4374
        # make sure we are using the unicode win32 api
4383
 
        dirname = text_type(dirname)
 
4375
        dirname = dirname.decode('mbcs')
4384
4376
    else:
4385
4377
        dirname = dirname.encode(sys.getfilesystemencoding())
4386
4378
    try: