base_test.py 943 B

1234567891011121314151617181920212223242526272829303132
  1. from shlex import shlex
  2. import pytest
  3. from baker import run_batch, load_cli
  4. def test_all_conf(test_cfg, log_buff):
  5. verbose = pytest.config.getoption('verbose', 0) > 0
  6. args = []
  7. if test_cfg.cli:
  8. lexer = shlex(test_cfg.cli)
  9. lexer.wordchars += '.!=<>:{}-/'
  10. args = list(lexer)
  11. cli = load_cli(args)
  12. for task in cli.tasks:
  13. run_batch(task, cli.hosts, cli, cli.env)
  14. actual_lines = log_buff.getvalue().splitlines()
  15. actual_lines = [l.strip() for l in filter(None, actual_lines)]
  16. expected_output = test_cfg.output or ''
  17. expected_lines = expected_output.splitlines()
  18. expected_lines = [l.strip() for l in filter(None, expected_lines)]
  19. # Join and makes path independant of OS
  20. act = '\n'.join(actual_lines).replace('\\', '/')
  21. exp = '\n'.join(expected_lines).replace('\\', '/')
  22. if verbose:
  23. print(act)
  24. assert act == exp