|
| 1 | +"""Testing Module Methods |
| 2 | +""" |
| 3 | +import pytest |
| 4 | +import subprocess |
| 5 | + |
| 6 | +from input.input_data import InputData |
| 7 | +from treescriptify.tree_runner import _check_arguments, get_tree_json |
| 8 | + |
| 9 | + |
| 10 | +def get_cmd_result(*args, **kwargs): |
| 11 | + result = type('MyObject', (object,), {'stdout': '[{"type":"directory","name":".","contents":[{"type":"file","name":"test_script_writer.py"},{"type":"file","name":"test_tree_reader.py"},{"type":"file","name":"test_tree_runner.py"}]}]'}) |
| 12 | + return result |
| 13 | + |
| 14 | + |
| 15 | +def test_get_tree_json_(): |
| 16 | + input_data = InputData() |
| 17 | + with pytest.MonkeyPatch().context() as c: |
| 18 | + c.setattr(subprocess, 'run', lambda *args, **kwargs: get_cmd_result(*args, **kwargs)) |
| 19 | + result = get_tree_json(input_data) |
| 20 | + expected_files = [ |
| 21 | + "test_script_writer.py", |
| 22 | + "test_tree_reader.py", |
| 23 | + "test_tree_runner.py", |
| 24 | + ] |
| 25 | + for filename in expected_files: |
| 26 | + assert filename in result |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.parametrize( |
| 30 | + 'test_input,expected', |
| 31 | + [ |
| 32 | + (InputData(include_hidden=False, git_ignore=False), ''), |
| 33 | + (InputData(git_ignore=False), '-a'), |
| 34 | + (InputData(), '-a --gitignore'), |
| 35 | + (InputData(directories_only=True), '-d -a --gitignore'), |
| 36 | + (InputData(prune_dirs=True), '--prune -a --gitignore'), |
| 37 | + (InputData(directories_only=True, prune_dirs=True), '-d --prune -a --gitignore'), |
| 38 | + ] |
| 39 | +) |
| 40 | +def test_check_arguments(test_input, expected): |
| 41 | + assert _check_arguments(test_input) == expected |
0 commit comments