|
15 | 15 | from test.support.os_helper import TESTFN, EnvironmentVarGuard
|
16 | 16 | import ast
|
17 | 17 | import builtins
|
18 |
| -import fnmatch |
19 | 18 | import glob
|
20 | 19 | import io
|
21 | 20 | import os
|
@@ -806,35 +805,23 @@ def test_underpth_dll_file(self):
|
806 | 805 | )], env=env)
|
807 | 806 | self.assertTrue(rc, "sys.path is incorrect")
|
808 | 807 |
|
809 |
| - |
810 | 808 | class CommandLineTests(unittest.TestCase):
|
811 |
| - def get_sys_path(self): |
812 |
| - proc = subprocess.Popen([sys.executable, '-c', |
813 |
| - 'import sys; print(repr(sys.path))'], |
814 |
| - stdout=subprocess.PIPE, |
815 |
| - stderr=subprocess.STDOUT, |
816 |
| - text=True) |
817 |
| - proc.wait() |
818 |
| - ls = ast.literal_eval(proc.stdout.read()) |
819 |
| - ls[0] = '*' |
820 |
| - proc.stdout.close() |
821 |
| - return ls |
| 809 | + def exists(self, path): |
| 810 | + if path is not None and os.path.isdir(path): |
| 811 | + return "exists" |
| 812 | + else: |
| 813 | + return "doesn't exist" |
822 | 814 |
|
823 | 815 | def get_excepted_output(self, *args):
|
824 | 816 | if len(args) == 0:
|
825 | 817 | user_base = site.getuserbase()
|
826 | 818 | user_site = site.getusersitepackages()
|
827 | 819 | output = "sys.path = [\n"
|
828 |
| - for dir in self.get_sys_path(): |
| 820 | + for dir in sys.path: |
829 | 821 | output += " %r,\n" % (dir,)
|
830 | 822 | output += "]\n"
|
831 |
| - def exists(path): |
832 |
| - if path is not None and os.path.isdir(path): |
833 |
| - return "exists" |
834 |
| - else: |
835 |
| - return "doesn't exist" |
836 |
| - output += f"USER_BASE: {user_base!r} ({exists(user_base)})\n" |
837 |
| - output += f"USER_SITE: {user_site!r} ({exists(user_site)})\n" |
| 823 | + output += f"USER_BASE: {user_base!r} ({self.exists(user_base)})\n" |
| 824 | + output += f"USER_SITE: {user_site!r} ({self.exists(user_site)})\n" |
838 | 825 | output += f"ENABLE_USER_SITE: {site.ENABLE_USER_SITE!r}\n"
|
839 | 826 | return 0, dedent(output).strip()
|
840 | 827 |
|
@@ -874,30 +861,40 @@ def test_no_args(self):
|
874 | 861 | excepted_return_code, excepted_output = self.get_excepted_output()
|
875 | 862 | self.assertEqual(return_code, excepted_return_code)
|
876 | 863 | # self.assertEqual(output, excepted_output)
|
877 |
| - #print(output) |
878 |
| - #print(excepted_output) |
879 |
| - #self.assertTrue(fnmatch.fnmatch(output, excepted_output)) |
880 |
| - |
| 864 | + output_lines = output.splitlines() |
| 865 | + self.assertEqual(output_lines[-1], |
| 866 | + f'ENABLE_USER_SITE: {site.ENABLE_USER_SITE}') |
| 867 | + user_site = f"USER_SITE: '{site.getusersitepackages()}' ({self.exists(site.getusersitepackages())})" |
| 868 | + self.assertEqual(output_lines[-2], user_site) |
| 869 | + user_base = f"USER_BASE: '{site.getuserbase()}' ({self.exists(site.getuserbase())})" |
| 870 | + self.assertEqual(output_lines[-3], user_base) |
| 871 | + self.assertEqual(output_lines[0], "sys.path = [") |
| 872 | + self.assertEqual(output_lines[-4], "]") |
| 873 | + |
| 874 | + @unittest.skipIf(sys.platform == 'wasi', 'subprocess not supported on WASI') |
881 | 875 | def test_unknown_args(self):
|
882 | 876 | return_code, output = self.invoke_command_line("--unknown-arg")
|
883 | 877 | excepted_return_code, _ = self.get_excepted_output("--unknown-arg")
|
884 | 878 | self.assertEqual(return_code, excepted_return_code)
|
885 | 879 | self.assertIn('[--user-base] [--user-site]', output)
|
886 | 880 |
|
| 881 | + @unittest.skipIf(sys.platform == 'wasi', 'subprocess not supported on WASI') |
887 | 882 | def test_base_arg(self):
|
888 | 883 | return_code, output = self.invoke_command_line("--user-base")
|
889 | 884 | excepted = self.get_excepted_output("--user-base")
|
890 | 885 | excepted_return_code, excepted_output = excepted
|
891 | 886 | self.assertEqual(return_code, excepted_return_code)
|
892 | 887 | self.assertEqual(output, excepted_output)
|
893 | 888 |
|
| 889 | + @unittest.skipIf(sys.platform == 'wasi', 'subprocess not supported on WASI') |
894 | 890 | def test_site_arg(self):
|
895 | 891 | return_code, output = self.invoke_command_line("--user-site")
|
896 | 892 | excepted = self.get_excepted_output("--user-site")
|
897 | 893 | excepted_return_code, excepted_output = excepted
|
898 | 894 | self.assertEqual(return_code, excepted_return_code)
|
899 | 895 | self.assertEqual(output, excepted_output)
|
900 | 896 |
|
| 897 | + @unittest.skipIf(sys.platform == 'wasi', 'subprocess not supported on WASI') |
901 | 898 | def test_both_args(self):
|
902 | 899 | return_code, output = self.invoke_command_line("--user-base",
|
903 | 900 | "--user-site")
|
|
0 commit comments