Skip to content

Refactor existing tox test to pytest #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 3, 2024
Merged
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8==3.9.2
pyinstaller
pyinstaller>=6.10.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyinstaller 버전을 제한한 사유는 무엇인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pyinstaller: error: argument --add-binary: Wrong syntax, should be --add-binary=SOURCE:DEST

pyinstaller에서 에러가 발생하며 위 메시지가 발생하여 구문을 고치고 버전을 제한하게 됐습니다.


생각을 해보니 위 에러는 unix / window 환경 차이의 문제 같기도 합니다..! (조금 더 찾아봐야 할 것 같습니다)

개인적으로 1단계 이후 2,3단계도 개인적으로 진행 해보려고 합니다.
그 때 필요 없다고 판단이 되면 pyinstaller 원상복구 시키고 버전 제한도 삭제하도록 하겠습니다!

tox>=4.18.1
pytest
pytest-cov
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ requirements-parser
defusedxml
packageurl-python
igraph
matplotlib
matplotlib
pytest
40 changes: 40 additions & 0 deletions tests/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import shutil
import pytest

set_up_directories = [
"tests/result/android",
"tests/result/cocoapods",
"tests/result/exclude",
"tests/result/gradle",
"tests/result/gradle2",
"tests/result/helm",
"tests/result/maven1",
"tests/result/maven2",
"tests/result/multi_pypi_npm",
"tests/result/npm1",
"tests/result/npm2",
"tests/result/nuget1",
"tests/result/nuget2",
"tests/result/pub",
"tests/result/pypi"
]

remove_directories = set_up_directories


@pytest.fixture(scope="session", autouse=True)
def setup_test_result_dir_and_teardown():
print("==============setup==============")
for directory in set_up_directories:
os.makedirs(directory, exist_ok=True)

yield

print("==============tearDown==============")
for directory in remove_directories:
shutil.rmtree(directory)
Empty file.
31 changes: 31 additions & 0 deletions tests/pytest/package_manager/test_android.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path, extra_args", [
("tests/test_android", "tests/result/android", "-m android")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path, extra_args):
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path", [
(os.path.join("tests", "test_android", "sunflower"), os.path.join("tests", "result", "android"))
])
@pytest.mark.windows
def test_windows(input_path, output_path):
command = f"{DIST_PATH} -p {input_path} -o {output_path}"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
18 changes: 18 additions & 0 deletions tests/pytest/package_manager/test_cocoapods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess


@pytest.mark.parametrize("input_path, output_path, extra_args", [
("tests/test_cocoapods", "tests/result/cocoapods", "-m cocoapods")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path, extra_args):
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
33 changes: 33 additions & 0 deletions tests/pytest/package_manager/test_gradle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path", [
("tests/test_gradle/jib", "tests/result/gradle"),
("tests/test_gradle2", "tests/result/gradle2")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path):
command = f"fosslight_dependency -p {input_path} -o {output_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path", [
(os.path.join("tests", "test_gradle", "jib"), os.path.join("tests", "result", "gradle")),
(os.path.join("tests", "test_gradle2"), os.path.join("tests", "result", "gradle2"))
])
@pytest.mark.windows
def test_windows(input_path, output_path):
command = f"{DIST_PATH} -p {input_path} -o {output_path} -m gradle"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
18 changes: 18 additions & 0 deletions tests/pytest/package_manager/test_helm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess


@pytest.mark.parametrize("input_path, output_path, extra_args", [
("tests/test_helm", "tests/result/helm", "-m helm")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path, extra_args):
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
32 changes: 32 additions & 0 deletions tests/pytest/package_manager/test_maven.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path", [
("tests/test_maven1/lombok.maven", "tests/result/maven1"),
("tests/test_maven2", "tests/result/maven2")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path):
command = f"fosslight_dependency -p {input_path} -o {output_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path", [
(os.path.join("tests", "test_maven2"), os.path.join("tests", "result", "maven2"))
])
@pytest.mark.windows
def test_windows(input_path, output_path):
command = f"{DIST_PATH} -p {input_path} -o {output_path} -m maven"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
19 changes: 19 additions & 0 deletions tests/pytest/package_manager/test_npm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess


@pytest.mark.parametrize("input_path, output_path, extra_args", [
("tests/test_npm1", "tests/result/npm1", ""),
("tests/test_npm2", "tests/result/npm2", "-m npm")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path, extra_args):
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
38 changes: 38 additions & 0 deletions tests/pytest/package_manager/test_nuget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

UBUNTU_COMMANDS = [
"fosslight_dependency -p tests/test_nuget -o tests/result/nuget1",
"fosslight_dependency -p tests/test_nuget2 -o tests/result/nuget2"
]

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path", [
("tests/test_nuget", "tests/result/nuget1"),
("tests/test_nuget2", "tests/result/nuget2")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path):
command = f"fosslight_dependency -p {input_path} -o {output_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path", [
(os.path.join("tests", "test_nuget"), os.path.join("tests", "result", "nuget1")),
(os.path.join("tests", "test_nuget2"), os.path.join("tests", "result", "nuget2"))
])
@pytest.mark.windows
def test_windows(input_path, output_path):
command = f"{DIST_PATH} -p {input_path} -o {output_path}"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
34 changes: 34 additions & 0 deletions tests/pytest/package_manager/test_pub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path", [
("tests/test_pub", "tests/result/pub"),
("tests/test_exclude -e requirements.txt", "tests/result/exclude")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path):
command = f"fosslight_dependency -p {input_path} -o {output_path}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path, extra_args", [
(os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), ""),
(os.path.join("tests", "test_pub"), os.path.join("tests", "result", "pub"), "-f opossum"),
(os.path.join("tests", "test_exclude") + " -e requirements.txt", os.path.join("tests", "result", "exclude"), "")
])
@pytest.mark.windows
def test_windows(input_path, output_path, extra_args):
command = f"{DIST_PATH} -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
33 changes: 33 additions & 0 deletions tests/pytest/package_manager/test_pypi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0
import os
import pytest
import subprocess

DIST_PATH = os.path.join(os.environ.get("TOX_PATH"), "dist", "cli.exe")


@pytest.mark.parametrize("input_path, output_path, extra_args", [
("tests/test_pypi", "tests/result/pypi", ""),
("tests/test_multi_pypi_npm", "tests/result/multi_pypi_npm", ""),
("tests/test_multi_pypi_npm", "tests/result/multi_pypi_npm", "-f opossum")
])
@pytest.mark.ubuntu
def test_ubuntu(input_path, output_path, extra_args):
command = f"fosslight_dependency -p {input_path} -o {output_path} {extra_args}"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"


@pytest.mark.parametrize("input_path, output_path", [
(os.path.join("tests", "test_pypi"), os.path.join("tests", "result", "pypi"))
])
@pytest.mark.windows
def test_windows(input_path, output_path):
command = f"{DIST_PATH} -p {input_path} -o {output_path}"
result = subprocess.run(command, capture_output=True, text=True)
assert result.returncode == 0, f"Command failed: {command}\nstdout: {result.stdout}\nstderr: {result.stderr}"
assert any(os.scandir(output_path)), f"Output file does not exist: {output_path}"
Loading
Loading