Skip to content

Commit

Permalink
speeds up some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed May 22, 2021
1 parent a6af9de commit 428d2d9
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions tests/cli/test_custom.py
Expand Up @@ -14,9 +14,8 @@
from ploomber import DAG
import ploomber.dag.DAG as dag_module

# TODO: refactor all tests that are using subprocess to use CLIRunner
# this is faster and more flexible
# https://click.palletsprojects.com/en/7.x/testing/
# TODO: optimize some of the tests that build dags by mocking and checking
# that the build function is called with the appropriate args


def test_no_options(monkeypatch):
Expand All @@ -30,42 +29,57 @@ def test_no_options(monkeypatch):


@pytest.mark.parametrize('cmd', [
None, 'scaffold', 'build', 'interact', 'plot', 'report', 'status', 'task',
'interact'
None,
'scaffold',
'build',
'interact',
'plot',
'report',
'status',
'task',
'interact',
])
def test_help_commands(cmd):

def test_help(cmd, monkeypatch):
elements = ['ploomber']

if cmd:
elements.append(cmd)

subprocess.run(elements + ['--help'], check=True)
monkeypatch.setattr(sys, 'argv', elements + ['--help'])

with pytest.raises(SystemExit) as excinfo:
cmd_router()

assert not excinfo.value.code


@pytest.mark.parametrize(
'cmd', ['build', 'plot', 'report', 'status', 'task', 'interact'])
def test_help_shows_env_keys(cmd, tmp_nbs):
res = subprocess.run(['ploomber', 'build', '--help'],
stdout=subprocess.PIPE,
check=True)
def test_help_shows_env_keys(cmd, monkeypatch, tmp_nbs, capsys):
monkeypatch.setattr(sys, 'argv', ['ploomber', cmd, '--help'])

out = res.stdout.decode()
with pytest.raises(SystemExit) as excinfo:
cmd_router()

assert '--env--sample' in out
captured = capsys.readouterr()
assert '--env--sample' in captured.out
assert not excinfo.value.code


@pytest.mark.parametrize(
'cmd', ['build', 'plot', 'report', 'status', 'task', 'interact'])
def test_help_shows_env_keys_w_entry_point(cmd, tmp_nbs,
add_current_to_sys_path):
res = subprocess.run(['ploomber', 'build', '-e', 'factory.make', '--help'],
stdout=subprocess.PIPE,
check=True)
add_current_to_sys_path,
monkeypatch, capsys):
monkeypatch.setattr(sys, 'argv',
['ploomber', cmd, '-e', 'factory.make', '--help'])

out = res.stdout.decode()
with pytest.raises(SystemExit) as excinfo:
cmd_router()

assert '--env--sample' in out
captured = capsys.readouterr()
assert '--env--sample' in captured.out
assert not excinfo.value.code


def test_build(monkeypatch, tmp_sample_dir):
Expand Down

0 comments on commit 428d2d9

Please sign in to comment.