def test_app_cmd(): app = App(name='App', binary='binary') assert app.cmd == ['binary'] app = App(name='App', pre_args=['a', 'b'], binary='binary') assert app.cmd == ['a', 'b', 'binary'] app = App(name='App', args=['c', 'd'], binary='binary') assert app.cmd == ['binary', 'c', 'd'] app = App(name='App', pre_args=['a', 'b'], args=['c', 'd'], binary='binary') assert app.cmd == ['a', 'b', 'binary', 'c', 'd']
def run_app(cwd): app = App(name='App', binary='echo', args=['%cd%' if platform.system() == 'Windows' else '`pwd`'], shell=True, working_dir=cwd) with app: app.proc.wait() return app
def test_app_env(): app = App(name='App', binary='echo', args=['%KEY%' if platform.system() == 'Windows' else '$KEY'], env={'KEY': 'VALUE'}, shell=True) with app: app.proc.wait() with open(app.std.out_path, 'r') as fobj: assert fobj.read().startswith('VALUE')
def test_app_cmd(runpath): """Test the app command is constructed correctly.""" app = App(name='App', binary='binary', runpath=runpath) assert app.cmd == ['binary'] app = App(name='App', pre_args=['a', 'b'], binary='binary', runpath=runpath) assert app.cmd == ['a', 'b', 'binary'] app = App(name='App', args=['c', 'd'], binary='binary', runpath=runpath) assert app.cmd == ['binary', 'c', 'd'] app = App(name='App', pre_args=['a', 'b'], args=['c', 'd'], binary='binary', runpath=runpath) assert app.cmd == ['a', 'b', 'binary', 'c', 'd']
def test_app_cmd(runpath): """Test the app command is constructed correctly.""" app = App(name="App", binary="binary", runpath=runpath) assert app.cmd == ["binary"] app = App(name="App", pre_args=["a", "b"], binary="binary", runpath=runpath) assert app.cmd == ["a", "b", "binary"] app = App(name="App", args=["c", "d"], binary="binary", runpath=runpath) assert app.cmd == ["binary", "c", "d"] app = App( name="App", pre_args=["a", "b"], args=["c", "d"], binary="binary", runpath=runpath, ) assert app.cmd == ["a", "b", "binary", "c", "d"]
def test_app_unexpected_retcode(runpath): app = App( name="App", binary=sys.executable, args=["-c", "import sys; sys.exit(0)"], expected_retcode=1, runpath=runpath, ) with pytest.raises(RuntimeError): with app: app.proc.wait()
def test_app_env(runpath): """Test that environment variables are correctly passed down.""" app = App(name='App', binary='echo', args=['%KEY%' if platform.system() == 'Windows' else '$KEY'], env={'KEY': 'VALUE'}, shell=True, runpath=runpath) with app: app.proc.wait() with open(app.std.out_path, 'r') as fobj: assert fobj.read().startswith('VALUE')
def run_app(cwd, runpath): """ Utility function that runs an echo process and waits for it to terminate. """ app = App(name='App', binary='echo', args=['%cd%' if platform.system() == 'Windows' else '`pwd`'], shell=True, working_dir=cwd, runpath=runpath) with app: app.proc.wait() return app
def test_app_logfile(): app_dir = 'AppDir' logfile = 'file.log' app = App(name='App', binary='echo', args=['hello', '>', os.path.join('AppDir', logfile)], app_dir_name=app_dir, logfile=logfile, shell=True) with app: app.proc.wait() assert os.path.exists(app.logpath) is True with open(app.logpath, 'r') as fobj: assert fobj.read().startswith('hello')
def test_stdin(runpath): """Test communicating with an App process' stdin.""" app = App(name="Repeater", binary=sys.executable, args=[os.path.join(MYAPP_DIR, "repeater.py")], runpath=runpath) with app: app.proc.communicate(input=b"Repeat me\nEOF") assert app.proc.poll() == 0 with open(app.std.out_path) as f: stdout = f.read() assert stdout == "Repeat me\n"
def test_app_env(runpath): """Test that environment variables are correctly passed down.""" app = App( name="App", binary="echo", args=["%KEY%" if platform.system() == "Windows" else "$KEY"], env={"KEY": "VALUE"}, shell=True, runpath=runpath, ) with app: app.proc.wait() with open(app.std.out_path, "r") as fobj: assert fobj.read().startswith("VALUE")
def test_app_os_environ(runpath): """Test that os.environ is passed down.""" os.environ["KEY"] = "VALUE" app = App( name="App", binary="echo", args=["%KEY%" if platform.system() == "Windows" else "$KEY"], shell=True, runpath=runpath, ) with app: app.proc.wait() with open(app.std.out_path, "r") as fobj: assert fobj.read().startswith("VALUE")
def test_app_fail_fast_with_log_regex(runpath): """Test that app fail fast instead of waiting for logs when app shutdown.""" app = App( name="myapp", binary="echo", args=["yes"], shell=True, stderr_regexps=[re.compile(r".*no*")], status_wait_timeout=2, runpath=runpath, ) with pytest.raises(RuntimeError, match=r"App myapp has unexpectedly stopped with: 0"): app.start() app.wait(app.STATUS.STARTED) app.stop()
def run_app(cwd, runpath): """ Utility function that runs an echo process and waits for it to terminate. """ app = App( name="App", binary="echo", args=["%cd%" if platform.system() == "Windows" else "`pwd`"], shell=True, working_dir=cwd, runpath=runpath, ) with app: app.proc.wait() return app
def main(plan): """ A simple example that demonstrate manually starting and stopping the App driver. """ plan.add( MultiTest( name="TestCat", suites=[MyTestsuite()], environment=[ App( name="cat_app", binary="/bin/cat", auto_start=False, ) ], ))
def test_app_logfile(runpath): """Test running an App that writes to a logfile.""" app_dir = "AppDir" logname = "file.log" app = App( name="App", binary="echo", args=["hello", ">", os.path.join("AppDir", logname)], app_dir_name=app_dir, logname=logname, shell=True, runpath=runpath, ) with app: app.proc.wait() assert os.path.exists(app.logpath) is True with open(app.logpath, "r") as fobj: assert fobj.read().startswith("hello")
def main(plan): """ A simple example that demonstrate App driver usage. App prints 'testplan' to standard output on startup and then waits for a user input simulating a long running app. """ plan.add( MultiTest( name="TestEcho", suites=[MyTestsuite()], environment=[ App( "echo", binary="echo", args=["testplan"], stdout_regexps=[re.compile(r"testplan") ], # argument inherited from Driver class ) ], after_stop=after_stop_fn, ))
def test_restart(runpath): """Test restart of an App""" app = App( name="Restarter", binary="echo", args=["Restarter app ran succesfully"], shell=True, runpath=runpath, ) with app: app.restart() app_path = Path(app.app_path) app_dir_name = app_path.name # we have the moved app_path assert list(app_path.parent.glob(f"{app_dir_name}_*")) app.restart(clean=False) # we have the moved files in app_path assert list(app_path.glob("stdout_*")) assert list(app_path.glob("stderr_*"))