diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -23,6 +23,16 @@ warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__) warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) +supports_unicode_filenames = True +if not os.path.supports_unicode_filenames: + try: + test_support.TESTFN_UNICODE.encode(test_support.TESTFN_ENCODING) + except (AttributeError, UnicodeError, TypeError): + # Either the file system encoding is None, or the file name + # cannot be encoded in the file system encoding. + supports_unicode_filenames = False + + # Tests creating TESTFN class FileTests(unittest.TestCase): def setUp(self): @@ -295,6 +305,16 @@ except TypeError: pass + @unittest.skipUnless(hasattr(os, 'statvfs'), 'test needs os.statvfs()') + @unittest.skipUnless(supports_unicode_filenames, + "unicode file names are not supported") + def test_statvfs_unicode(self): + fname = test_support.TESTFN_UNICODE + test_support.unlink(fname) + with open(fname, 'w'): + self.addCleanup(test_support.unlink, fname) + os.statvfs(fname) + def test_utime_dir(self): delta = 1000000 st = os.stat(test_support.TESTFN) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7447,7 +7447,8 @@ char *path; int res; struct statvfs st; - if (!PyArg_ParseTuple(args, "s:statvfs", &path)) + if (!PyArg_ParseTuple(args, "et:statvfs", + Py_FileSystemDefaultEncoding, &path)) return NULL; Py_BEGIN_ALLOW_THREADS res = statvfs(path, &st);