/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: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-10 02:49:30 UTC
  • mfrom: (6677.1.4 py3_bootstrap)
  • Revision ID: breezy.the.bot@gmail.com-20170610024930-enw8wdbjy9s4dtnm
Progress on Python 3 to get TestCaseWithTransport working

Merged from https://code.launchpad.net/~gz/brz/py3_bootstrap/+merge/325439

Show diffs side-by-side

added added

removed removed

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