Exemplo n.º 1
0
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']
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
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']
Exemplo n.º 5
0
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"]
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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')
Exemplo n.º 8
0
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
Exemplo n.º 9
0
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')
Exemplo n.º 10
0
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"
Exemplo n.º 11
0
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")
Exemplo n.º 12
0
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")
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
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
Exemplo n.º 15
0
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,
                )
            ],
        ))
Exemplo n.º 16
0
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")
Exemplo n.º 17
0
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,
        ))
Exemplo n.º 18
0
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_*"))