MCPcopy Index your code
hub / github.com/python/cpython / create_args

Method create_args

Lib/test/test_os/test_os.py:3282–3310  ·  view source on GitHub ↗
(self, *, with_env=False, use_bytes=False)

Source from the content-addressed store, hash-verified

3280 return [f'"{arg}"' if " " in arg.strip() else arg for arg in args]
3281
3282 def create_args(self, *, with_env=False, use_bytes=False):
3283 self.exitcode = 17
3284
3285 filename = os_helper.TESTFN
3286 self.addCleanup(os_helper.unlink, filename)
3287
3288 if not with_env:
3289 code = 'import sys; sys.exit(%s)' % self.exitcode
3290 else:
3291 self.env = dict(os.environ)
3292 # create an unique key
3293 self.key = str(uuid.uuid4())
3294 self.env[self.key] = self.key
3295 # read the variable from os.environ to check that it exists
3296 code = ('import sys, os; magic = os.environ[%r]; sys.exit(%s)'
3297 % (self.key, self.exitcode))
3298
3299 with open(filename, "w", encoding="utf-8") as fp:
3300 fp.write(code)
3301
3302 program = sys.executable
3303 args = self.quote_args([program, filename])
3304 if use_bytes:
3305 program = os.fsencode(program)
3306 args = [os.fsencode(a) for a in args]
3307 self.env = {os.fsencode(k): os.fsencode(v)
3308 for k, v in self.env.items()}
3309
3310 return program, args
3311
3312 @warnings_helper.ignore_fork_in_thread_deprecation_warnings()
3313 @requires_os_func('spawnl')

Callers 14

test_spawnlMethod · 0.95
test_spawnleMethod · 0.95
test_spawnlpMethod · 0.95
test_spawnlpeMethod · 0.95
test_spawnvMethod · 0.95
test_spawnveMethod · 0.95
test_spawnvpMethod · 0.95
test_spawnvpeMethod · 0.95
test_nowaitMethod · 0.95
test_spawnve_bytesMethod · 0.95
test_spawnl_noargsMethod · 0.95
test_spawnle_noargsMethod · 0.95

Calls 6

quote_argsMethod · 0.95
strFunction · 0.85
addCleanupMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected