当前位置: 首页>>代码示例>>Python>>正文


Python test_support.TESTFN_ENCODING属性代码示例

本文整理汇总了Python中test.test_support.TESTFN_ENCODING属性的典型用法代码示例。如果您正苦于以下问题:Python test_support.TESTFN_ENCODING属性的具体用法?Python test_support.TESTFN_ENCODING怎么用?Python test_support.TESTFN_ENCODING使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在test.test_support的用法示例。


在下文中一共展示了test_support.TESTFN_ENCODING属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_path_with_null_unicode

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def test_path_with_null_unicode(self):
        fn = test_support.TESTFN_UNICODE
        try:
            fn.encode(test_support.TESTFN_ENCODING)
        except (UnicodeError, TypeError):
            self.skipTest("Requires unicode filenames support")
        fn_with_NUL = fn + u'\0'
        self.addCleanup(test_support.unlink, fn)
        test_support.unlink(fn)
        fd = None
        try:
            with self.assertRaises(TypeError):
                fd = os.open(fn_with_NUL, os.O_WRONLY | os.O_CREAT) # raises
        finally:
            if fd is not None:
                os.close(fd)
        self.assertFalse(os.path.exists(fn))
        self.assertRaises(TypeError, os.mkdir, fn_with_NUL)
        self.assertFalse(os.path.exists(fn))
        open(fn, 'wb').close()
        self.assertRaises(TypeError, os.stat, fn_with_NUL) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_posix.py

示例2: test_abspath_issue3426

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def test_abspath_issue3426(self):
        # Check that abspath returns unicode when the arg is unicode
        # with both ASCII and non-ASCII cwds.
        abspath = self.pathmodule.abspath
        for path in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
            self.assertIsInstance(abspath(path), unicode)

        unicwd = u'\xe7w\xf0'
        try:
            fsencoding = test_support.TESTFN_ENCODING or "ascii"
            unicwd.encode(fsencoding)
        except (AttributeError, UnicodeEncodeError):
            # FS encoding is probably ASCII
            pass
        else:
            with test_support.temp_cwd(unicwd):
                for path in (u'', u'fuu', u'f\xf9\xf9', u'/fuu', u'U:\\'):
                    self.assertIsInstance(abspath(path), unicode) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_genericpath.py

示例3: _do_directory

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def _do_directory(self, make_name, chdir_name, encoded):
        if os.path.isdir(make_name):
            os.rmdir(make_name)
        os.mkdir(make_name)
        try:
            with change_cwd(chdir_name):
                if not encoded:
                    cwd_result = os.getcwdu()
                    name_result = make_name
                else:
                    cwd_result = os.getcwd().decode(TESTFN_ENCODING)
                    name_result = make_name.decode(TESTFN_ENCODING)

                cwd_result = unicodedata.normalize("NFD", cwd_result)
                name_result = unicodedata.normalize("NFD", name_result)

                self.assertEqual(os.path.basename(cwd_result),name_result)
        finally:
            os.rmdir(make_name)

    # The '_test' functions 'entry points with params' - ie, what the
    # top-level 'test' functions would be if they could take params 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_unicode_file.py

示例4: test_unicode_filename

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def test_unicode_filename(self):
        unicode_filename = test_support.TESTFN_UNICODE
        try:
            unicode_filename.encode(test_support.TESTFN_ENCODING)
        except (UnicodeError, TypeError):
            self.skipTest("Requires unicode filenames support")
        self.filename = unicode_filename
        with gzip.GzipFile(unicode_filename, "wb") as f:
            f.write(data1 * 50)
        with gzip.GzipFile(unicode_filename, "rb") as f:
            self.assertEqual(f.read(), data1 * 50)
        # Sanity check that we are actually operating on the right file.
        with open(unicode_filename, 'rb') as fobj, \
             gzip.GzipFile(fileobj=fobj, mode="rb") as f:
            self.assertEqual(f.read(), data1 * 50) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_gzip.py

示例5: _do_single

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def _do_single(self, filename):
        self.assertTrue(os.path.exists(filename))
        self.assertTrue(os.path.isfile(filename))
        self.assertTrue(os.access(filename, os.R_OK))
        self.assertTrue(os.path.exists(os.path.abspath(filename)))
        self.assertTrue(os.path.isfile(os.path.abspath(filename)))
        self.assertTrue(os.access(os.path.abspath(filename), os.R_OK))
        os.chmod(filename, 0777)
        os.utime(filename, None)
        os.utime(filename, (time.time(), time.time()))
        # Copy/rename etc tests using the same filename
        self._do_copyish(filename, filename)
        # Filename should appear in glob output
        self.assertTrue(
            os.path.abspath(filename)==os.path.abspath(glob.glob(filename)[0]))
        # basename should appear in listdir.
        path, base = os.path.split(os.path.abspath(filename))
        if isinstance(base, str):
            base = base.decode(TESTFN_ENCODING)
        file_list = os.listdir(path)
        # listdir() with a unicode arg may or may not return Unicode
        # objects, depending on the platform.
        if file_list and isinstance(file_list[0], str):
            file_list = [f.decode(TESTFN_ENCODING) for f in file_list]

        # Normalize the unicode strings, as round-tripping the name via the OS
        # may return a different (but equivalent) value.
        base = unicodedata.normalize("NFD", base)
        file_list = [unicodedata.normalize("NFD", f) for f in file_list]

        self.assertIn(base, file_list)

    # Do as many "equivalancy' tests as we can - ie, check that although we
    # have different types for the filename, they refer to the same file. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:36,代码来源:test_unicode_file.py

示例6: _do_directory

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def _do_directory(self, make_name, chdir_name, encoded):
        cwd = os.getcwd()
        if os.path.isdir(make_name):
            os.rmdir(make_name)
        os.mkdir(make_name)
        try:
            os.chdir(chdir_name)
            try:
                if not encoded:
                    cwd_result = os.getcwdu()
                    name_result = make_name
                else:
                    cwd_result = os.getcwd().decode(TESTFN_ENCODING)
                    name_result = make_name.decode(TESTFN_ENCODING)

                cwd_result = unicodedata.normalize("NFD", cwd_result)
                name_result = unicodedata.normalize("NFD", name_result)

                self.assertEqual(os.path.basename(cwd_result),name_result)
            finally:
                os.chdir(cwd)
        finally:
            os.rmdir(make_name)

    # The '_test' functions 'entry points with params' - ie, what the
    # top-level 'test' functions would be if they could take params 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:28,代码来源:test_unicode_file.py

示例7: test_unicode_filename

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def test_unicode_filename(self):
        unicode_filename = test_support.TESTFN_UNICODE
        try:
            unicode_filename.encode(test_support.TESTFN_ENCODING)
        except (UnicodeError, TypeError):
            self.skipTest("Requires unicode filenames support")
        with gzip.GzipFile(unicode_filename, "wb") as f:
            f.write(data1 * 50)
        with gzip.GzipFile(unicode_filename, "rb") as f:
            self.assertEqual(f.read(), data1 * 50)
        # Sanity check that we are actually operating on the right file.
        with open(unicode_filename, 'rb') as fobj, \
             gzip.GzipFile(fileobj=fobj, mode="rb") as f:
            self.assertEqual(f.read(), data1 * 50) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:16,代码来源:test_gzip.py

示例8: _do_single

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def _do_single(self, filename):
        self.failUnless(os.path.exists(filename))
        self.failUnless(os.path.isfile(filename))
        self.failUnless(os.access(filename, os.R_OK))
        self.failUnless(os.path.exists(os.path.abspath(filename)))
        self.failUnless(os.path.isfile(os.path.abspath(filename)))
        self.failUnless(os.access(os.path.abspath(filename), os.R_OK))
        os.chmod(filename, 0777)
        os.utime(filename, None)
        os.utime(filename, (time.time(), time.time()))
        # Copy/rename etc tests using the same filename
        self._do_copyish(filename, filename)
        # Filename should appear in glob output
        self.failUnless(
            os.path.abspath(filename)==os.path.abspath(glob.glob(filename)[0]))
        # basename should appear in listdir.
        path, base = os.path.split(os.path.abspath(filename))
        if isinstance(base, str):
            base = base.decode(TESTFN_ENCODING)
        file_list = os.listdir(path)
        # listdir() with a unicode arg may or may not return Unicode
        # objects, depending on the platform.
        if file_list and isinstance(file_list[0], str):
            file_list = [f.decode(TESTFN_ENCODING) for f in file_list]

        # Normalize the unicode strings, as round-tripping the name via the OS
        # may return a different (but equivalent) value.
        base = unicodedata.normalize("NFD", base)
        file_list = [unicodedata.normalize("NFD", f) for f in file_list]

        self.failUnless(base in file_list)

    # Do as many "equivalancy' tests as we can - ie, check that although we
    # have different types for the filename, they refer to the same file. 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:36,代码来源:test_unicode_file.py

示例9: _do_directory

# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN_ENCODING [as 别名]
def _do_directory(self, make_name, chdir_name, encoded):
        cwd = os.getcwd()
        if os.path.isdir(make_name):
            os.rmdir(make_name)
        os.mkdir(make_name)
        try:
            os.chdir(chdir_name)
            try:
                if not encoded:
                    cwd_result = os.getcwdu()
                    name_result = make_name
                else:
                    cwd_result = os.getcwd().decode(TESTFN_ENCODING)
                    name_result = make_name.decode(TESTFN_ENCODING)

                cwd_result = unicodedata.normalize("NFD", cwd_result)
                name_result = unicodedata.normalize("NFD", name_result)

                self.failUnlessEqual(os.path.basename(cwd_result),name_result)
            finally:
                os.chdir(cwd)
        finally:
            os.rmdir(make_name)

    # The '_test' functions 'entry points with params' - ie, what the
    # top-level 'test' functions would be if they could take params 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:28,代码来源:test_unicode_file.py


注:本文中的test.test_support.TESTFN_ENCODING属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。