~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Andrew Bennetts
  • Date: 2008-07-28 06:53:44 UTC
  • mfrom: (3581 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3583.
  • Revision ID: andrew.bennetts@canonical.com-20080728065344-ocndjoycs903q6fz
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
218
218
        elif isinstance(err[1], UnavailableFeature):
219
219
            return self.addNotSupported(test, err[1].args[0])
220
220
        else:
221
 
            self._cleanupLogFile(test)
222
221
            unittest.TestResult.addError(self, test, err)
223
222
            self.error_count += 1
224
223
            self.report_error(test, err)
225
224
            if self.stop_early:
226
225
                self.stop()
 
226
            self._cleanupLogFile(test)
227
227
 
228
228
    def addFailure(self, test, err):
229
229
        """Tell result that test failed.
235
235
        if isinstance(err[1], KnownFailure):
236
236
            return self._addKnownFailure(test, err)
237
237
        else:
238
 
            self._cleanupLogFile(test)
239
238
            unittest.TestResult.addFailure(self, test, err)
240
239
            self.failure_count += 1
241
240
            self.report_failure(test, err)
242
241
            if self.stop_early:
243
242
                self.stop()
 
243
            self._cleanupLogFile(test)
244
244
 
245
245
    def addSuccess(self, test):
246
246
        """Tell result that test completed successfully.
923
923
        """
924
924
        try:
925
925
            list(func(*args, **kwargs))
926
 
        except excClass:
927
 
            return
 
926
        except excClass, e:
 
927
            return e
928
928
        else:
929
929
            if getattr(excClass,'__name__', None) is not None:
930
930
                excName = excClass.__name__
2041
2041
            self.log("actually: %r" % contents)
2042
2042
            self.fail("contents of %s not as expected" % filename)
2043
2043
 
 
2044
    def _getTestDirPrefix(self):
 
2045
        # create a directory within the top level test directory
 
2046
        if sys.platform == 'win32':
 
2047
            name_prefix = re.sub('[<>*=+",:;_/\\-]', '_', self.id())
 
2048
            # windows is likely to have path-length limits so use a short name
 
2049
            name_prefix = name_prefix[-30:]
 
2050
        else:
 
2051
            name_prefix = re.sub('[/]', '_', self.id())
 
2052
        return name_prefix
 
2053
 
2044
2054
    def makeAndChdirToTestDir(self):
2045
2055
        """See TestCaseWithMemoryTransport.makeAndChdirToTestDir().
2046
2056
        
2047
2057
        For TestCaseInTempDir we create a temporary directory based on the test
2048
2058
        name and then create two subdirs - test and home under it.
2049
2059
        """
2050
 
        # create a directory within the top level test directory
2051
 
        candidate_dir = osutils.mkdtemp(dir=self.TEST_ROOT)
 
2060
        name_prefix = os.path.join(self.TEST_ROOT, self._getTestDirPrefix())
 
2061
        name = name_prefix
 
2062
        for i in range(100):
 
2063
            if os.path.exists(name):
 
2064
                name = name_prefix + '_' + str(i)
 
2065
            else:
 
2066
                os.mkdir(name)
 
2067
                break
2052
2068
        # now create test and home directories within this dir
2053
 
        self.test_base_dir = candidate_dir
 
2069
        self.test_base_dir = name
2054
2070
        self.test_home_dir = self.test_base_dir + '/home'
2055
2071
        os.mkdir(self.test_home_dir)
2056
2072
        self.test_dir = self.test_base_dir + '/work'
2758
2774
                   'bzrlib.tests.test_revisionspec',
2759
2775
                   'bzrlib.tests.test_revisiontree',
2760
2776
                   'bzrlib.tests.test_rio',
 
2777
                   'bzrlib.tests.test_rules',
2761
2778
                   'bzrlib.tests.test_sampler',
2762
2779
                   'bzrlib.tests.test_selftest',
2763
2780
                   'bzrlib.tests.test_setup',
2795
2812
                   'bzrlib.tests.test_versionedfile',
2796
2813
                   'bzrlib.tests.test_version',
2797
2814
                   'bzrlib.tests.test_version_info',
 
2815
                   'bzrlib.tests.test__walkdirs_win32',
2798
2816
                   'bzrlib.tests.test_weave',
2799
2817
                   'bzrlib.tests.test_whitebox',
2800
2818
                   'bzrlib.tests.test_win32utils',
3072
3090
 
3073
3091
    def _probe(self):
3074
3092
        try:
3075
 
            os.stat(u'\u03b1')
 
3093
            # Check for character combinations unlikely to be covered by any
 
3094
            # single non-unicode encoding. We use the characters
 
3095
            # - greek small letter alpha (U+03B1) and
 
3096
            # - braille pattern dots-123456 (U+283F).
 
3097
            os.stat(u'\u03b1\u283f')
3076
3098
        except UnicodeEncodeError:
3077
3099
            return False
3078
3100
        except (IOError, OSError):
3169
3191
FTPServerFeature = _FTPServerFeature()
3170
3192
 
3171
3193
 
 
3194
class _UnicodeFilename(Feature):
 
3195
    """Does the filesystem support Unicode filenames?"""
 
3196
 
 
3197
    def _probe(self):
 
3198
        try:
 
3199
            os.stat(u'\u03b1')
 
3200
        except UnicodeEncodeError:
 
3201
            return False
 
3202
        except (IOError, OSError):
 
3203
            # The filesystem allows the Unicode filename but the file doesn't
 
3204
            # exist.
 
3205
            return True
 
3206
        else:
 
3207
            # The filesystem allows the Unicode filename and the file exists,
 
3208
            # for some reason.
 
3209
            return True
 
3210
 
 
3211
UnicodeFilename = _UnicodeFilename()
 
3212
 
 
3213
 
 
3214
class _UTF8Filesystem(Feature):
 
3215
    """Is the filesystem UTF-8?"""
 
3216
 
 
3217
    def _probe(self):
 
3218
        if osutils._fs_enc.upper() in ('UTF-8', 'UTF8'):
 
3219
            return True
 
3220
        return False
 
3221
 
 
3222
UTF8Filesystem = _UTF8Filesystem()
 
3223
 
 
3224
 
3172
3225
class _CaseInsensitiveFilesystemFeature(Feature):
3173
3226
    """Check if underlined filesystem is case-insensitive
3174
3227
    (e.g. on Windows, Cygwin, MacOS)