|
4 | 4 | # SPDX-License-Identifier: Apache-2.0 |
5 | 5 | import os |
6 | 6 | import pytest |
7 | | - |
8 | | -UBUNTU_COMMANDS = [ |
9 | | - "fosslight_dependency -p tests/test_pub -o tests/result/pub", |
10 | | - "fosslight_dependency -p tests/test_exclude -e requirements.txt -o tests/result/exclude" |
11 | | -] |
| 7 | +import subprocess |
12 | 8 |
|
13 | 9 | DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe") |
14 | | -INPUT_PATH = os.path.join("tests", "test_pub") |
15 | | -OUTPUT_PATH = os.path.join("tests", "result", "pub") |
16 | | -INPUT_PATH2 = os.path.join("tests", "test_exclude") |
17 | | -OUTPUT_PATH2 = os.path.join("tests", "result", "exclude") |
18 | | - |
19 | | -WINDOW_COMMANDS = [ |
20 | | - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH}", |
21 | | - f"{DIST_PATH} -p {INPUT_PATH} -o {OUTPUT_PATH} -f opossum", |
22 | | - f"{DIST_PATH} -p {INPUT_PATH} -e requirements.txt -o {OUTPUT_PATH}" |
23 | | -] |
24 | 10 |
|
25 | 11 |
|
| 12 | +@pytest.mark.parametrize("input_path, output_path", [ |
| 13 | + ("tests/test_pub", "tests/result/pub"), |
| 14 | + ("tests/test_exclude -e requirements.txt", "tests/result/exclude") |
| 15 | +]) |
26 | 16 | @pytest.mark.ubuntu |
27 | | -def test_ubuntu(run_command): |
28 | | - for command in UBUNTU_COMMANDS: |
29 | | - return_code, stdout, stderr = run_command(command) |
30 | | - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" |
| 17 | +def test_ubuntu(input_path, output_path): |
| 18 | + command = f"fosslight_dependency -p {input_path} -o {output_path}" |
| 19 | + result = subprocess.run(command, shell=True, capture_output=True, text=True) |
| 20 | + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" |
| 21 | + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" |
31 | 22 |
|
32 | 23 |
|
| 24 | +@pytest.mark.parametrize("input_path, output_path, extra_args", [ |
| 25 | + (os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), ""), |
| 26 | + (os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), "-f opossum"), |
| 27 | + (os.path.join("tests", "test_exclude") + " -e requirements.txt", os.path.join("tests", "result", "exclude"), "") |
| 28 | +]) |
33 | 29 | @pytest.mark.windows |
34 | | -def test_windows(run_command): |
35 | | - for command in WINDOW_COMMANDS: |
36 | | - return_code, stdout, stderr = run_command(command) |
37 | | - assert return_code == 0, f"Command failed: {command}\nstdout: {stdout}\nstderr: {stderr}" |
| 30 | +def test_windows(input_path, output_path, extra_args): |
| 31 | + command = f"{DIST_PATH} -p {input_path} -o {output_path} {extra_args}" |
| 32 | + result = subprocess.run(command, shell=True, capture_output=True, text=True) |
| 33 | + assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}" |
| 34 | + assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}" |
0 commit comments