Python test.test_support.TESTFN_ENCODING Examples

The following are 25 code examples of test.test_support.TESTFN_ENCODING(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module test.test_support , or try the search function .
Example #1
Source File: test_posix.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #2
Source File: test_genericpath.py    From CTFCrackTools with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: test_genericpath.py    From CTFCrackTools-V2 with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #4
Source File: test_genericpath.py    From gcblue with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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) 
Example #5
Source File: test_genericpath.py    From oss-ftp with MIT License 6 votes vote down vote up
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) 
Example #6
Source File: test_unicode_file.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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 
Example #7
Source File: test_genericpath.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
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) 
Example #8
Source File: test_genericpath.py    From BinderFilter with MIT License 6 votes vote down vote up
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) 
Example #9
Source File: test_unicode_file.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
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. 
Example #10
Source File: test_unicode_file.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #11
Source File: test_unicode_file.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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. 
Example #12
Source File: test_gzip.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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) 
Example #13
Source File: test_gzip.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #14
Source File: test_unicode_file.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #15
Source File: test_unicode_file.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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. 
Example #16
Source File: test_gzip.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #17
Source File: test_unicode_file.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
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 
Example #18
Source File: test_unicode_file.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #19
Source File: test_unicode_file.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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. 
Example #20
Source File: test_unicode_file.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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. 
Example #21
Source File: test_unicode_file.py    From oss-ftp with MIT License 5 votes vote down vote up
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 
Example #22
Source File: test_unicode_file.py    From oss-ftp with MIT License 5 votes vote down vote up
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. 
Example #23
Source File: test_gzip.py    From oss-ftp with MIT License 5 votes vote down vote up
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) 
Example #24
Source File: test_unicode_file.py    From BinderFilter with MIT License 5 votes vote down vote up
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 
Example #25
Source File: test_unicode_file.py    From BinderFilter with MIT License 5 votes vote down vote up
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.