def test_wait_stdout(self): # we can get the stdout output when wait()-ing path = os.path.join(self.path_dir, 'myscript') pysrc = 'print("Hello from myscript")' create_python_script(path, pysrc) cmd = BackgroundCommand(path) cmd.run() ret_code, stdout, stderr = cmd.wait() assert stdout == b'Hello from myscript\n'
def test_wait_returncode(self): # we get the returncode path = os.path.join(self.path_dir, 'myscript') pysrc = 'sys.exit(42)' create_python_script(path, pysrc) cmd = BackgroundCommand(path) cmd.run() ret_code, stdout, stderr = cmd.wait() assert ret_code == 42
def test_args(self): # we can pass in arguments path = os.path.join(self.path_dir, 'myscript') stamp_file = os.path.join(self.path_dir, 'i_was_here') pysrc = 'open("%s", "w").write(sys.argv[1])' % stamp_file create_python_script(path, pysrc) cmd = BackgroundCommand([path, 'myarg']) cmd.run() cmd.wait() assert open(stamp_file, 'r').read() == 'myarg'
def test_startable(self): # we can start executables path = os.path.join(self.path_dir, 'myscript') stamp_file = os.path.join(self.path_dir, 'i_was_here') pysrc = 'open("%s", "w").write("I was here")' % stamp_file create_python_script(path, pysrc) cmd = BackgroundCommand(path) cmd.run() cmd.wait() assert os.path.isfile(stamp_file)