MCPcopy Index your code
hub / github.com/RustPython/RustPython / setUp

Method setUp

Lib/test/test_httpservers.py:948–1030  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

946 linesep = os.linesep.encode('ascii')
947
948 def setUp(self):
949 self.request_handler._test_case_self = self # practical, but yuck.
950 BaseTestCase.setUp(self)
951 self.cwd = os.getcwd()
952 self.parent_dir = tempfile.mkdtemp()
953 self.cgi_dir = os.path.join(self.parent_dir, 'cgi-bin')
954 self.cgi_child_dir = os.path.join(self.cgi_dir, 'child-dir')
955 self.sub_dir_1 = os.path.join(self.parent_dir, 'sub')
956 self.sub_dir_2 = os.path.join(self.sub_dir_1, 'dir')
957 self.cgi_dir_in_sub_dir = os.path.join(self.sub_dir_2, 'cgi-bin')
958 os.mkdir(self.cgi_dir)
959 os.mkdir(self.cgi_child_dir)
960 os.mkdir(self.sub_dir_1)
961 os.mkdir(self.sub_dir_2)
962 os.mkdir(self.cgi_dir_in_sub_dir)
963 self.nocgi_path = None
964 self.file1_path = None
965 self.file2_path = None
966 self.file3_path = None
967 self.file4_path = None
968 self.file5_path = None
969 self.file6_path = None
970 self.file7_path = None
971
972 # The shebang line should be pure ASCII: use symlink if possible.
973 # See issue #7668.
974 self._pythonexe_symlink = None
975 if os_helper.can_symlink():
976 self.pythonexe = os.path.join(self.parent_dir, 'python')
977 self._pythonexe_symlink = support.PythonSymlink(self.pythonexe).__enter__()
978 else:
979 self.pythonexe = sys.executable
980
981 try:
982 # The python executable path is written as the first line of the
983 # CGI Python script. The encoding cookie cannot be used, and so the
984 # path should be encodable to the default script encoding (utf-8)
985 self.pythonexe.encode('utf-8')
986 except UnicodeEncodeError:
987 self.tearDown()
988 self.skipTest("Python executable path is not encodable to utf-8")
989
990 self.nocgi_path = os.path.join(self.parent_dir, 'nocgi.py')
991 with open(self.nocgi_path, 'w', encoding='utf-8') as fp:
992 fp.write(cgi_file1 % self.pythonexe)
993 os.chmod(self.nocgi_path, 0o777)
994
995 self.file1_path = os.path.join(self.cgi_dir, 'file1.py')
996 with open(self.file1_path, 'w', encoding='utf-8') as file1:
997 file1.write(cgi_file1 % self.pythonexe)
998 os.chmod(self.file1_path, 0o777)
999
1000 self.file2_path = os.path.join(self.cgi_dir, 'file2.py')
1001 with open(self.file2_path, 'w', encoding='utf-8') as file2:
1002 file2.write(cgi_file2 % self.pythonexe)
1003 os.chmod(self.file2_path, 0o777)
1004
1005 self.file3_path = os.path.join(self.cgi_child_dir, 'file3.py')

Callers

nothing calls this directly

Calls 11

tearDownMethod · 0.95
mkdtempMethod · 0.80
skipTestMethod · 0.80
openFunction · 0.50
setUpMethod · 0.45
joinMethod · 0.45
mkdirMethod · 0.45
__enter__Method · 0.45
encodeMethod · 0.45
writeMethod · 0.45
chmodMethod · 0.45

Tested by

no test coverage detected