(self)
| 66 | self.assertEqual(out, '0') |
| 67 | |
| 68 | def test_env_var(self): |
| 69 | code = 'import sys; print(sys.flags.utf8_mode)' |
| 70 | |
| 71 | out = self.get_output('-c', code, PYTHONUTF8='1') |
| 72 | self.assertEqual(out, '1') |
| 73 | |
| 74 | out = self.get_output('-c', code, PYTHONUTF8='0') |
| 75 | self.assertEqual(out, '0') |
| 76 | |
| 77 | # -X utf8 has the priority over PYTHONUTF8 |
| 78 | out = self.get_output('-X', 'utf8=0', '-c', code, PYTHONUTF8='1') |
| 79 | self.assertEqual(out, '0') |
| 80 | |
| 81 | if MS_WINDOWS: |
| 82 | # PYTHONLEGACYWINDOWSFSENCODING disables the UTF-8 mode |
| 83 | # and has the priority over PYTHONUTF8 |
| 84 | out = self.get_output('-X', 'utf8', '-c', code, PYTHONUTF8='1', |
| 85 | PYTHONLEGACYWINDOWSFSENCODING='1') |
| 86 | self.assertEqual(out, '0') |
| 87 | |
| 88 | # Cannot test with the POSIX locale, since the POSIX locale enables |
| 89 | # the UTF-8 mode |
| 90 | if not self.posix_locale(): |
| 91 | # PYTHONUTF8 should be ignored if -E is used |
| 92 | out = self.get_output('-E', '-c', code, PYTHONUTF8='0') |
| 93 | self.assertEqual(out, '1') |
| 94 | |
| 95 | # invalid mode |
| 96 | out = self.get_output('-c', code, PYTHONUTF8='xxx', failure=True) |
| 97 | self.assertIn('invalid PYTHONUTF8 environment variable value', |
| 98 | out.rstrip()) |
| 99 | |
| 100 | def test_filesystemencoding(self): |
| 101 | code = textwrap.dedent(''' |
nothing calls this directly
no test coverage detected