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

Method create_args

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

Source from the content-addressed store, hash-verified

3595 return [f'"{arg}"' if " " in arg.strip() else arg for arg in args]
3596
3597 def create_args(self, *, with_env=False, use_bytes=False):
3598 self.exitcode = 17
3599
3600 filename = os_helper.TESTFN
3601 self.addCleanup(os_helper.unlink, filename)
3602
3603 if not with_env:
3604 code = 'import sys; sys.exit(%s)' % self.exitcode
3605 else:
3606 self.env = dict(os.environ)
3607 # create an unique key
3608 self.key = str(uuid.uuid4())
3609 self.env[self.key] = self.key
3610 # read the variable from os.environ to check that it exists
3611 code = ('import sys, os; magic = os.environ[%r]; sys.exit(%s)'
3612 % (self.key, self.exitcode))
3613
3614 with open(filename, "w", encoding="utf-8") as fp:
3615 fp.write(code)
3616
3617 program = sys.executable
3618 args = self.quote_args([program, filename])
3619 if use_bytes:
3620 program = os.fsencode(program)
3621 args = [os.fsencode(a) for a in args]
3622 self.env = {os.fsencode(k): os.fsencode(v)
3623 for k, v in self.env.items()}
3624
3625 return program, args
3626
3627 @requires_os_func('spawnl')
3628 def test_spawnl(self):

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 7

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

Tested by

no test coverage detected