Skip to content

Commit 756d120

Browse files
authored
Refactor existing tox test to pytest (#225)
Signed-off-by: yongjunhong <[email protected]>
1 parent f703a48 commit 756d120

File tree

14 files changed

+306
-51
lines changed

14 files changed

+306
-51
lines changed

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
flake8==3.9.2
2-
pyinstaller
2+
pyinstaller>=6.10.0
33
tox>=4.18.1
44
pytest
55
pytest-cov

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ requirements-parser
1010
defusedxml
1111
packageurl-python
1212
igraph
13-
matplotlib
13+
matplotlib

tests/pytest/conftest.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import shutil
7+
import pytest
8+
9+
set_up_directories = [
10+
"tests/result/android",
11+
"tests/result/cocoapods",
12+
"tests/result/exclude",
13+
"tests/result/gradle",
14+
"tests/result/gradle2",
15+
"tests/result/helm",
16+
"tests/result/maven1",
17+
"tests/result/maven2",
18+
"tests/result/multi_pypi_npm",
19+
"tests/result/npm1",
20+
"tests/result/npm2",
21+
"tests/result/nuget1",
22+
"tests/result/nuget2",
23+
"tests/result/pub",
24+
"tests/result/pypi"
25+
]
26+
27+
remove_directories = set_up_directories
28+
29+
30+
@pytest.fixture(scope="session", autouse=True)
31+
def setup_test_result_dir_and_teardown():
32+
print("==============setup==============")
33+
for directory in set_up_directories:
34+
os.makedirs(directory, exist_ok=True)
35+
36+
yield
37+
38+
print("==============tearDown==============")
39+
for directory in remove_directories:
40+
shutil.rmtree(directory)

tests/pytest/package_manager/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")
10+
11+
12+
@pytest.mark.parametrize("input_path, output_path, extra_args", [
13+
("tests/test_android", "tests/result/android", "-m android")
14+
])
15+
@pytest.mark.ubuntu
16+
def test_ubuntu(input_path, output_path, extra_args):
17+
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
18+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
19+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
20+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
21+
22+
23+
@pytest.mark.parametrize("input_path, output_path", [
24+
(os.path.join("tests", "test_android", "sunflower"), os.path.join("tests", "result", "android"))
25+
])
26+
@pytest.mark.windows
27+
def test_windows(input_path, output_path):
28+
command = f"{DIST_PATH} -p {input_path} -o {output_path}"
29+
result = subprocess.run(command, capture_output=True, text=True)
30+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
31+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
10+
@pytest.mark.parametrize("input_path, output_path, extra_args", [
11+
("tests/test_cocoapods", "tests/result/cocoapods", "-m cocoapods")
12+
])
13+
@pytest.mark.ubuntu
14+
def test_ubuntu(input_path, output_path, extra_args):
15+
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
16+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
17+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
18+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")
10+
11+
12+
@pytest.mark.parametrize("input_path, output_path", [
13+
("tests/test_gradle/jib", "tests/result/gradle"),
14+
("tests/test_gradle2", "tests/result/gradle2")
15+
])
16+
@pytest.mark.ubuntu
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}"
22+
23+
24+
@pytest.mark.parametrize("input_path, output_path", [
25+
(os.path.join("tests", "test_gradle", "jib"), os.path.join("tests", "result", "gradle")),
26+
(os.path.join("tests", "test_gradle2"), os.path.join("tests", "result", "gradle2"))
27+
])
28+
@pytest.mark.windows
29+
def test_windows(input_path, output_path):
30+
command = f"{DIST_PATH} -p {input_path} -o {output_path} -m gradle"
31+
result = subprocess.run(command, capture_output=True, text=True)
32+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
33+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
10+
@pytest.mark.parametrize("input_path, output_path, extra_args", [
11+
("tests/test_helm", "tests/result/helm", "-m helm")
12+
])
13+
@pytest.mark.ubuntu
14+
def test_ubuntu(input_path, output_path, extra_args):
15+
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
16+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
17+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
18+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")
10+
11+
12+
@pytest.mark.parametrize("input_path, output_path", [
13+
("tests/test_maven1/lombok.maven", "tests/result/maven1"),
14+
("tests/test_maven2", "tests/result/maven2")
15+
])
16+
@pytest.mark.ubuntu
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}"
22+
23+
24+
@pytest.mark.parametrize("input_path, output_path", [
25+
(os.path.join("tests", "test_maven2"), os.path.join("tests", "result", "maven2"))
26+
])
27+
@pytest.mark.windows
28+
def test_windows(input_path, output_path):
29+
command = f"{DIST_PATH} -p {input_path} -o {output_path} -m maven"
30+
result = subprocess.run(command, capture_output=True, text=True)
31+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
32+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
import os
6+
import pytest
7+
import subprocess
8+
9+
10+
@pytest.mark.parametrize("input_path, output_path, extra_args", [
11+
("tests/test_npm1", "tests/result/npm1", ""),
12+
("tests/test_npm2", "tests/result/npm2", "-m npm")
13+
])
14+
@pytest.mark.ubuntu
15+
def test_ubuntu(input_path, output_path, extra_args):
16+
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
17+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
18+
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
19+
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"

0 commit comments

Comments
 (0)