def test_cmds_to_specs_thread_subproc(xession): env = xession.env cmds = [["pwd"]] # XONSH_CAPTURE_ALWAYS=False should disable interactive threaded subprocs env["XONSH_CAPTURE_ALWAYS"] = False env["THREAD_SUBPROCS"] = True specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is Popen # Now for the other situations env["XONSH_CAPTURE_ALWAYS"] = True # First check that threadable subprocs become threadable env["THREAD_SUBPROCS"] = True specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is PopenThread # turn off threading and check we use Popen env["THREAD_SUBPROCS"] = False specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is Popen # now check the threadbility of callable aliases cmds = [[lambda: "Keras Selyrian"]] # check that threadable alias become threadable env["THREAD_SUBPROCS"] = True specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is ProcProxyThread # turn off threading and check we use ProcProxy env["THREAD_SUBPROCS"] = False specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is ProcProxy
def test_cmds_to_specs_capture_stdout_not_stderr(thread_subprocs): env = XSH.env cmds = (["ls", "/root"],) env["THREAD_SUBPROCS"] = thread_subprocs specs = cmds_to_specs(cmds, captured="stdout") assert specs[0].stdout is not None assert specs[0].stderr is None
def test_cmds_to_specs_thread_subproc(xonsh_builtins): env = xonsh_builtins.__xonsh__.env cmds = [["pwd"]] # First check that threadable subprocs become threadable env["THREAD_SUBPROCS"] = True specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is PopenThread # turn off threading and check we use Popen env["THREAD_SUBPROCS"] = False specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is Popen # now check the threadbility of callable aliases cmds = [[lambda: "Keras Selyrian"]] # check that threadable alias become threadable env["THREAD_SUBPROCS"] = True specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is ProcProxyThread # turn off threading and check we use ProcProxy env["THREAD_SUBPROCS"] = False specs = cmds_to_specs(cmds, captured="hiddenobject") assert specs[0].cls is ProcProxy
def test_tracer_help(capsys, xsh_with_aliases): """verify can invoke it, and usage knows about all the options""" spec = cmds_to_specs([("trace", "-h")], captured="stdout")[0] with pytest.raises(SystemExit): tracermain(["-h"], spec=spec) capout = capsys.readouterr().out pat = re.compile(r"^usage:\s*trace[^\n]*{([\w,-]+)}", re.MULTILINE) m = pat.match(capout) assert m[1] verbs = {v.strip().lower() for v in m[1].split(",")} assert verbs == { "rm", "start", "add", "on", "off", "del", "color", "stop", "ls" }
def test_callable_alias_cls(thread_subprocs, xession): class Cls: def __call__(self, *args, **kwargs): print(args, kwargs) obj = Cls() xession.aliases["tst"] = obj env = xession.env cmds = (["tst", "/root"], ) env["THREAD_SUBPROCS"] = thread_subprocs spec = cmds_to_specs(cmds, captured="stdout")[0] proc = spec.run() assert proc.f == obj