Exemplo n.º 1
0
def test_scripts(datadir_factory, printer):

    datadir = datadir_factory.mkdatadir(f'../_examples/{EXAMPLE}')

    with chdir(datadir):

        run(['python', 'source/make_orchestrator.py', '1', '10', '10', '3'], )
Exemplo n.º 2
0
def test_runs(datadir_factory, printer):

    datadir = datadir_factory.mkdatadir(f'../_examples/{EXAMPLE}')

    with chdir(datadir):
        run([
            'bash',
            '_tangle_source/run0.bash',
        ], )
Exemplo n.º 3
0
def test_run_passes_stdout_and_stderr_if_not_captured():
    with patch('subprocess.Popen') as Popen:
        Popen.return_value.returncode = 0
        Popen.return_value.communicate.return_value = (None, None)
        run.run(sentinel.cmd, capture_stdout=False, capture_stderr=False)
    Popen.assert_called_with(sentinel.cmd,
                             stdin=None,
                             stdout=None,
                             stderr=None)
def test_run_logs_stdout_on_failure():
    cmd = get_python_cmd('sys.stdout.write("stdout")', exit_code=1)

    with mock.patch('pytest_shutil.run.log') as log:
        with pytest.raises(subprocess.CalledProcessError):
            with no_cov():
                run.run(cmd, capture_stdout=True)

    expected = 'Command failed: "%s"\nstdout' % " ".join(cmd)
    log.error.assert_called_with(expected)
def test_run_logs_stdout_on_failure():
    cmd = get_python_cmd('sys.stdout.write("stdout")', exit_code=1)

    with mock.patch('pytest_shutil.run.log') as log:
        with pytest.raises(subprocess.CalledProcessError):
            with no_cov():
                run.run(cmd, capture_stdout=True)

    expected = 'Command failed: "%s"\nstdout' % " ".join(cmd)
    log.error.assert_called_with(expected)
def test_run_passes_stderr_if_not_captured():
    cmd = get_python_cmd('sys.stderr.write("stderr")')
    cmd = ", ".join(['\'%s\'' % s for s in cmd])

    with no_cov():
        p = subprocess.Popen([sys.executable, '-c', """from pytest_shutil import run
run.run([%s], capture_stderr=False)""" % cmd], stderr=subprocess.PIPE)
    _, err = p.communicate()
    assert p.returncode == 0
    assert 'stderr' in err.decode('utf-8')
def test_run_logs_stderr_on_failure():
    cmd = get_python_cmd('sys.stderr.write("stderr")', exit_code=1)

    with mock.patch('pytest_shutil.run.log') as log:
        with pytest.raises(subprocess.CalledProcessError):
            with no_cov():
                run.run(cmd, capture_stderr=True)

    expected = 'Command failed: "%s"\nstderr' % " ".join(cmd)
    assert log.error.call_count == 1
    assert log.error.call_args[0][0].startswith(expected)
def test_run_logs_stderr_on_failure():
    cmd = get_python_cmd('sys.stderr.write("stderr")', exit_code=1)

    with mock.patch('pytest_shutil.run.log') as log:
        with pytest.raises(subprocess.CalledProcessError):
            with no_cov():
                run.run(cmd, capture_stderr=True)

    expected = 'Command failed: "%s"\nstderr' % " ".join(cmd)
    assert log.error.call_count == 1
    assert log.error.call_args[0][0].startswith(expected)
def test_trivial_run(datadir_factory, printer):

    example = "Lennard_Jones_Pair"

    datadir = datadir_factory.mkdatadir(f'../_examples/{example}')

    with chdir(datadir):
        run(['python',
            'source/trivial_run.py',
            ],
        )
def test_run_passes_stdout_if_not_captured():
    cmd = get_python_cmd('sys.stdout.write("stdout")')
    cmd = ", ".join(['\'%s\'' % s for s in cmd])
    with no_cov():
        p = subprocess.Popen([
            sys.executable, '-c',
            """from pytest_shutil import run
run.run([%s], capture_stdout=False)""" % cmd
        ],
                             stdout=subprocess.PIPE)
    out, _ = p.communicate()
    assert p.returncode == 0
    assert out.decode('utf-8') == 'stdout'
Exemplo n.º 11
0
def test_reference(datadir_factory):

    datadir = Path(
        datadir_factory.mkdatadir('../_tangled_docs/info/reference'))
    with chdir(datadir):

        out = run([
            'python',
            'decision_fields_0.py',
        ], )

        out = run([
            'python',
            'record_fields_0.py',
        ], )
Exemplo n.º 12
0
def test_no_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]
    with env.no_env(TEMP_NAME):
        out = run.run('env', capture_stdout=True)
        for o in out.split('\n'):
            if o.startswith(TEMP_NAME):
                assert False, '%s found in os.environ' % TEMP_NAME

    assert TEMP_NAME not in os.environ
def test_no_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]
    with env.no_env(TEMP_NAME):
        out = run.run('env', capture_stdout=True)
        for o in out.split('\n'):
            if o.startswith(TEMP_NAME):
                assert False, '%s found in os.environ' % TEMP_NAME

    assert TEMP_NAME not in os.environ
Exemplo n.º 14
0
def test_readme(datadir_factory):

    datadir = Path(datadir_factory.mkdatadir('../_tangled_docs/README'))

    with chdir(datadir):

        out = run([
            'bash',
            'check_installation.bash',
        ], )
Exemplo n.º 15
0
def test_set_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]
    with env.set_env(TEMP_NAME, 'anything'):
        out = run.run('env', capture_stdout=True)
        for o in out.split('\n'):
            if o.startswith(TEMP_NAME):
                assert o == '%s=anything' % TEMP_NAME
                break
        else:
            assert False, '%s not found in os.environ' % TEMP_NAME
def test_set_env_ok_if_not_exists():
    if TEMP_NAME in os.environ:
        del os.environ[TEMP_NAME]
    with env.set_env(TEMP_NAME, 'anything'):
        out = run.run('env', capture_stdout=True)
        for o in out.split('\n'):
            if o.startswith(TEMP_NAME):
                assert o == '%s=anything' % TEMP_NAME
                break
        else:
            assert False, '%s not found in os.environ' % TEMP_NAME
Exemplo n.º 17
0
def test_quick_start(datadir_factory):

    datadir = Path(
        datadir_factory.mkdatadir('../_tangled_docs/info/quick_start'))

    with chdir(datadir):

        out = run([
            'bash',
            'test_drive.bash',
        ], )

        out = run([
            'python',
            'noresampler_example.py',
        ], )

        out = run([
            'bash',
            'noresampler_example.bash',
        ], )
Exemplo n.º 18
0
def test_we(datadir_factory, printer):

    datadir = datadir_factory.mkdatadir(f'../_examples/{EXAMPLE}')

    with chdir(datadir):

        with check:

            printer("running CPU-NoResampler")
            run([
                'python', 'source/we.py', '2', '2', '10', '1', 'CPU',
                'NoResampler'
            ], )

        printer("running CPU-REVOResampler")
        with check:
            print("CPU-REVOResampler")
            run([
                'python', 'source/we.py', '2', '2', '10', '1', 'CPU',
                'REVOResampler'
            ], )

        printer("running CPU-WExploreResampler")
        with check:
            print("CPU_WExploreResampler")
            run([
                'python', 'source/we.py', '2', '2', '10', '1', 'CPU',
                'WExploreResampler'
            ], )
def test_subprocecmdline():
    ev = os.environ[TEMP_NAME] = 'junk_name'
    try:
        with env.no_env(TEMP_NAME):
            out = run.run('env', capture_stdout=True)
            for o in out.split('\n'):
                if o.startswith(TEMP_NAME):
                    assert False, '%s found in os.environ' % TEMP_NAME

        assert os.environ[TEMP_NAME] == ev
    finally:
        if TEMP_NAME in os.environ:
            del os.environ[TEMP_NAME]
Exemplo n.º 20
0
def test_subprocecmdline():
    ev = os.environ[TEMP_NAME] = 'junk_name'
    try:
        with env.no_env(TEMP_NAME):
            out = run.run('env', capture_stdout=True)
            for o in out.split('\n'):
                if o.startswith(TEMP_NAME):
                    assert False, '%s found in os.environ' % TEMP_NAME

        assert os.environ[TEMP_NAME] == ev
    finally:
        if TEMP_NAME in os.environ:
            del os.environ[TEMP_NAME]
Exemplo n.º 21
0
def test_tutorial(datadir_factory, printer):

    tutorial = "data_analysis"

    datadir = datadir_factory.mkdatadir(f'../_tutorials/{tutorial}')

    assert (datadir / "README.ipynb").is_file()
    assert (datadir / "input").is_dir()

    with chdir(datadir):

        run([
            'python',
            '_tangle_source/README.py',
        ], )

        assert (datadir / '_output/results_run1.wepy.h5').exists()
        assert (datadir / '_output/results_run2.wepy.h5').exists()
        assert (datadir / '_output/results_run3.wepy.h5').exists()

        assert (datadir / '_output/lj-pair.pdb').exists()
        assert (datadir / '_output/lj-pair_walker_lineage').exists()
Exemplo n.º 22
0
def test_scripts(datadir_factory, printer):

    datadir = datadir_factory.mkdatadir(f'../_examples/{EXAMPLE}')

    with chdir(datadir):

        run(['python', 'source/rw_conventional.py', '1', '10', '10', '3'], )

        run(['python', 'source/rw_revo.py', '1', '10', '10', '3'], )

        run(['python', 'source/rw_wexplore.py', '1', '10', '10', '3'], )
def test_run0(datadir_factory, printer):

    tutorial = "extended_test_drive"

    datadir = datadir_factory.mkdatadir(f'../_tutorials/{tutorial}')

    with chdir(datadir):

        # check that the help message runs

        run([
            'bash',
            '_tangle_source/run-help.bash',
        ], )

        # default Run with WExplore

        run0_out = run([
            'bash',
            '_tangle_source/run0.bash',
        ], )

        with check:
            assert (
                datadir /
                '_tangle_source/expected_run0_ls.txt').read_text() == run0_out

        assert (datadir / '_output/run0/root.wepy.h5').exists()
        assert (datadir / '_output/run0/root.dash.org').exists()
        assert (datadir / '_output/run0/root.init_top.pdb').exists()
        assert (datadir / '_output/run0/root.walkers.dcd').exists()

        # REVO run

        run([
            'bash',
            '_tangle_source/revo_run.bash',
        ], )

        assert (datadir / '_output/revo_run/root.wepy.h5').exists()
        assert (datadir / '_output/revo_run/root.dash.org').exists()
        assert (datadir / '_output/revo_run/root.init_top.pdb').exists()
        assert (datadir / '_output/revo_run/root.walkers.dcd').exists()

        # No run

        run([
            'bash',
            '_tangle_source/no_run.bash',
        ], )

        assert (datadir / '_output/no_run/root.wepy.h5').exists()
        assert (datadir / '_output/no_run/root.dash.org').exists()
        assert (datadir / '_output/no_run/root.init_top.pdb').exists()
        assert (datadir / '_output/no_run/root.walkers.dcd').exists()

        ## analysis

        # part 0
        analysis0_out = run([
            'python',
            '_tangle_source/analysis0.py',
        ], )

        assert (datadir / '_output/run0/traj0.dcd').exists()
        assert (datadir / "_output/run0/last_cycle.dcd").exists()

        with check:
            assert (datadir / '_tangle_source/test_analysis_0.txt').read_text() == \
                analysis0_out.strip()
Exemplo n.º 24
0
def test_we_analysis(datadir_factory, printer):

    example = "Lennard_Jones_Pair"

    datadir = datadir_factory.mkdatadir(f'../_examples/{example}')

    printer("Testing from inside test_we_analysis")

    with chdir(datadir):

        printer(f"Datadir: {datadir}")
        printer(f"Current dir: {os.getcwd()}")

        out = run([
            "python",
            "source/we.py",
            "10", '100', "10"])

        printer(out)

        assert (datadir / "_output/we/results.wepy.h5").is_file()
        assert (datadir / "_output/we/wepy.dash.org").is_file()


        out = run([
            "python",
            "source/compute_distance_observable.py",
        ])

        printer(out)

        out = run([
            "python",
            "source/state_network.py",
        ])

        printer(out)

        assert (datadir / "_output/state.dcd").is_file()
        assert (datadir / "_output/random_macrostates.csn.gexf").is_file()



        ### Tangled sources

        out = run([
            "python",
            "_tangle_source/inspect_observable.py",
        ])

        printer(out)

        out = run([
            "bash",
            "./_tangle_source/run0.bash",
        ]
        )

        printer(out)

        out = run([
            "bash",
            "./_tangle_source/run1.bash",
        ]
        )
Exemplo n.º 25
0
def test_run_raises_on_failure():
    cmd = get_python_cmd(exit_code=1)
    with pytest.raises(subprocess.CalledProcessError):
        with no_cov():
            run.run(cmd)
Exemplo n.º 26
0
def test_sim_maker_run(datadir_factory, printer):

    example = "Lennard_Jones_Pair"

    datadir = datadir_factory.mkdatadir(f'../_examples/{example}')

    with chdir(datadir):
        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'Reference', 'NoResampler'],
        )

        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'Reference', 'WExploreResampler'],
        )
        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'Reference', 'REVOResampler'],
        )
        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'CPU', 'NoResampler'],
        )
        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'CPU', 'WExploreResampler'],
        )
        run(['python',
            'source/sim_maker_run.py',
            '2', '100', '10', '1', 'CPU', 'REVOResampler'],
        )
def test_run_raises_on_failure():
    cmd = get_python_cmd(exit_code=1)
    with pytest.raises(subprocess.CalledProcessError):
        with no_cov():
            run.run(cmd)
Exemplo n.º 28
0
def test_run_passes_stdout_and_stderr_if_not_captured():
    with patch('subprocess.Popen') as Popen:
        Popen.return_value.returncode = 0
        Popen.return_value.communicate.return_value = (None, None)
        run.run(sentinel.cmd, capture_stdout=False, capture_stderr=False)
    Popen.assert_called_with(sentinel.cmd, stdin=None, stdout=None, stderr=None)