Andrew Svetlov avatar Andrew Svetlov committed 56df0d4

Issue #16218: Fix test for issue again

Comments (0)

Files changed (1)

Lib/test/test_cmd_line_script.py

             self.assertTrue(text[1].startswith('  File '))
             self.assertTrue(text[3].startswith('NameError'))
 
-    def test_non_utf8(self):
+    def test_non_ascii(self):
         # Issue #16218
-        with temp_dir() as script_dir:
-            script_basename = '\u0441\u043a\u0440\u0438\u043f\u0442'
-            try:
-                script_basename.encode(sys.getfilesystemencoding())
-            except UnicodeEncodeError:
-                raise unittest.SkipTest("Filesystem doesn't support "
-                                        "unicode names")
-            source = 'print("test output")\n'
-            script_name = _make_test_script(script_dir, script_basename, source)
-            if not __debug__:
-                run_args = ('-' + 'O' * sys.flags.optimize, script_name)
-            else:
-                run_args = (script_name,)
-            rc, out, _ = assert_python_ok(*run_args)
-            self.assertEqual(0, rc)
-            expected = ("test output" + os.linesep).encode('ascii')
-            self.assertEqual(expected, out)
+        # non-ascii filename encodable to cp1252, cp932, latin1 and utf8
+        filename = support.TESTFN + '\xa3.py'
+        try:
+            os.fsencode(filename)
+        except UnicodeEncodeError:
+            self.skipTest(
+                "Filesystem encoding %r cannot encode "
+                "the filename: %a"
+                % (sys.getfilesystemencoding(), filename))
+        source = 'print(ascii(__file__))\n'
+        script_name = _make_test_script(os.curdir, filename, source)
+        self.addCleanup(support.unlink, script_name)
+        rc, stdout, stderr = assert_python_ok(script_name)
+        self.assertEqual(
+            ascii(script_name),
+            stdout.rstrip().decode('ascii'),
+            'stdout=%r stderr=%r' % (stdout, stderr))
+        self.assertEqual(0, rc)
 
 
 def test_main():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.