-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor existing tox test to pytest #189
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
soimkim
merged 13 commits into
fosslight:main
from
MoonJeWoong:refactor_pytest_without_conflict
Oct 3, 2024
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7270050
refactor test_text.py
MoonJeWoong 978cc24
refactor test_write_output.py, test_output_format.py
MoonJeWoong 693352e
refactor test_spdx_licenses.py
MoonJeWoong a6cdb5e
rename temp pytest package
MoonJeWoong 50fcaad
add init file to legacy package
MoonJeWoong d0694e8
refactor test_download.py
MoonJeWoong 051f156
refactor test_write_yaml.py
MoonJeWoong cc950e9
refactor test_opossum.py
MoonJeWoong c6c8fcf
refactor legacy tox test files related for logging
MoonJeWoong 0a7fc27
move omitted legacy test files
MoonJeWoong 8f11d92
move resource files
MoonJeWoong 336b955
move refactoring pytest files
MoonJeWoong 666f81f
reformat import statements
MoonJeWoong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| import os | ||
| import shutil | ||
|
|
||
| import pytest | ||
|
|
||
| from tests import constants | ||
| from fosslight_util.constant import FOSSLIGHT_SOURCE | ||
| from fosslight_util.oss_item import ScannerItem, FileItem, OssItem | ||
|
|
||
| set_up_directories = [ | ||
| constants.TEST_RESULT_DIR, | ||
| os.path.join(constants.TEST_RESULT_DIR, "convert") | ||
| ] | ||
| remove_directories = [constants.TEST_RESULT_DIR] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function", autouse=True) | ||
| def setup_test_result_dir_and_teardown(): | ||
| print("==============setup==============") | ||
| for dir in set_up_directories: | ||
| os.makedirs(dir, exist_ok=True) | ||
|
|
||
| yield | ||
|
|
||
| print("==============tearDown==============") | ||
| for dir in remove_directories: | ||
| shutil.rmtree(dir) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def scan_item(): | ||
| scan_item = ScannerItem(FOSSLIGHT_SOURCE) | ||
| scan_item.set_cover_pathinfo('tests/test_excel_and_csv', '') | ||
| scan_item.set_cover_comment('This is a test comment') | ||
|
|
||
| file_item = FileItem('test_result/excel_and_csv') | ||
|
|
||
| oss_item = OssItem("test_name1", "1.0.0", "Apache-2.0", "https://abc.com") | ||
| oss_item.comment = "test_name comment" | ||
| file_item.oss_items.append(oss_item) | ||
|
|
||
| oss_item2 = OssItem("test_name2", "2.0.0", "MIT", "https://abc2.com") | ||
| file_item.oss_items.append(oss_item2) | ||
|
|
||
| oss_item3 = OssItem("test_name3", "1.0.0", "GPL-2.0,BSD-3-Clause", "https://abc3.com") | ||
| file_item.oss_items.append(oss_item3) | ||
| file_item.comment = "all test comment" | ||
|
|
||
| scan_item.append_file_items([file_item]) | ||
|
|
||
| return scan_item | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| TEST_RESULT_DIR = "test_result" | ||
| TEST_RESOURCES_DIR = "resources" |
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from fosslight_util.download import cli_download_and_extract | ||
|
|
||
|
|
||
| def main(): | ||
| success, msg, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example", | ||
| "test_result/download/example", | ||
| "test_result/download_log/example") | ||
| if not success: | ||
| raise Exception(f"Download failed with git:{msg}") | ||
| success, msg, _, _ = cli_download_and_extract("https://pypi.org/project/filelock/3.4.1", | ||
| "test_result/download/filelock", | ||
| "test_result/download_log/filelock") | ||
| if not success: | ||
| raise Exception(f"Download failed with wget:{msg}") | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from fosslight_util.write_opossum import write_opossum | ||
| from fosslight_util.set_log import init_log | ||
| from fosslight_util.oss_item import ScannerItem, FileItem, OssItem | ||
| from fosslight_util.constant import FOSSLIGHT_SOURCE | ||
|
|
||
|
|
||
| def main(): | ||
| logger, _result_log = init_log("test_result/excel/log_write_opossum.txt") | ||
| logger.warning("TESTING - Writing an opossum") | ||
|
|
||
| scan_item = ScannerItem(FOSSLIGHT_SOURCE) | ||
| scan_item.set_cover_pathinfo('tests/test_excel_and_csv', '') | ||
| scan_item.set_cover_comment('This is a test comment') | ||
|
|
||
| file_item = FileItem('test_result/excel_and_csv') | ||
| oss_item = OssItem("test_name", "1.0.0", "Apache-2.0", "https://abc.com") | ||
| oss_item.comment = "test_name comment" | ||
| file_item.oss_items.append(oss_item) | ||
| oss_item2 = OssItem("test_name", "2.0.0", "MIT", "https://abc2.com") | ||
| file_item.oss_items.append(oss_item2) | ||
| file_item.comment = "all test comment" | ||
|
|
||
| scan_item.append_file_items([file_item]) | ||
|
|
||
| success, msg = write_opossum( | ||
| 'test_result/opossum/FL-TEST_opossum.json', scan_item) | ||
| logger.warning("Result:" + str(success) + ", error_msg:" + msg) | ||
MoonJeWoong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
MoonJeWoong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| from fosslight_util.set_log import init_log | ||
| from fosslight_util.spdx_licenses import get_spdx_licenses_json | ||
|
|
||
|
|
||
| def main(): | ||
| logger, _result_log = init_log("test_result/spdx_licenses/log_spdx_licenses.txt") | ||
| logger.warning("TESTING - Get spdx licenses") | ||
|
|
||
MoonJeWoong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| success, error_msg, licenses = get_spdx_licenses_json() | ||
| logger.warning("Result:" + str(success) + ", error_msg:" + error_msg) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| import os | ||
| from fosslight_util.set_log import init_log | ||
| from fosslight_util.write_txt import write_txt_file | ||
|
|
||
|
|
||
| def main(): | ||
| output_dir = "test_result/txt" | ||
| logger, _result_log = init_log(os.path.join(output_dir, "log.txt")) | ||
| logger.warning("TESTING - writing text file") | ||
| success, error_msg = write_txt_file( | ||
| os.path.join(output_dir, "test.txt"), "Testing - Writing text in a file.") | ||
| logger.warning("Result:" + str(success) + ", error_msg:"+error_msg) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
File renamed without changes.
File renamed without changes.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| same-oss: | ||
| - version: 0.0.0 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - BSD-3-Clause | ||
| download location: https://github.com/alecthomas/template | ||
| homepage: https://pkg.go.dev/github.com/alecthomas/template | ||
| comment: transitive, Cannot connect https://pkg.go.dev/github.com/alecthomas/[email protected], | ||
| get info from the latest version. | ||
| add-license-oss: | ||
| - version: 0.5.6 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MPL-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| - version: 0.5.3 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MPL-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| - version: 0.5.3 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - Apache-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| - version: 0.5.4 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - Apache-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| remove-version-oss: | ||
| - version: 1.0.1 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MIT | ||
| - Apache-2.0 | ||
| download location: https://github.com/konsorten/go-windows-terminal-sequences | ||
| homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences | ||
| comment: transitive | ||
| new-test-oss: | ||
| - version: 1.0.1 | ||
| source name or path: | ||
| - hi | ||
| license: | ||
| - MIT | ||
| - Apache-2.0 | ||
| download location: https://github.com/new-test-oss/new-test-oss | ||
| homepage: https://github.com/new-test-oss/new-test-oss | ||
| new-test-oss2: | ||
| - version: 1.0.1 | ||
| source name or path: | ||
| - hi2 | ||
| license: | ||
| - MIT | ||
| - version: 1.0.2 | ||
| source name or path: | ||
| - hi2 | ||
| license: | ||
| - MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| same-oss: | ||
| - version: 0.0.0 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - BSD-3-Clause | ||
| download location: https://github.com/alecthomas/template | ||
| homepage: https://pkg.go.dev/github.com/alecthomas/template | ||
| comment: transitive, Cannot connect https://pkg.go.dev/github.com/alecthomas/[email protected], | ||
| get info from the latest version. | ||
| add-license-oss: | ||
| - version: 0.5.6 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MPL-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| - version: 0.5.6 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MPL-2.0 | ||
| - Apache-2.0 | ||
| download location: https://github.com/hashicorp/go-retryablehttp | ||
| homepage: https://pkg.go.dev/github.com/hashicorp/go-retryablehttp | ||
| comment: transitive | ||
| remove-version-oss: | ||
| - version: 1.0.1 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MIT | ||
| download location: https://github.com/konsorten/go-windows-terminal-sequences | ||
| homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences | ||
| comment: transitive | ||
| - version: 2.0.1 | ||
| source name or path: | ||
| - go.mod | ||
| license: | ||
| - MIT | ||
| download location: https://github.com/konsorten/go-windows-terminal-sequences | ||
| homepage: https://pkg.go.dev/github.com/konsorten/go-windows-terminal-sequences | ||
| del-test-oss: | ||
| - version: 1.0.1 | ||
| source name or path: | ||
| - hi | ||
| license: | ||
| - MIT | ||
| - Apache-2.0 | ||
| download location: https://github.com/del-test-oss/del-test-oss | ||
| homepage: https://github.com/del-test-oss/del-test-oss |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,41 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2021 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
|
|
||
| import pytest | ||
MoonJeWoong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| from fosslight_util.download import cli_download_and_extract | ||
| from tests import constants | ||
|
|
||
|
|
||
| def test_download_from_github(): | ||
| # when | ||
| target_dir = os.path.join(constants.TEST_RESULT_DIR, "download/example") | ||
| success, _, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example", | ||
| target_dir, | ||
| "test_result/download_log/example") | ||
|
|
||
| # then | ||
| assert success is True | ||
| assert len(os.listdir(target_dir)) > 0 | ||
|
|
||
|
|
||
| def main(): | ||
| success, msg, _, _ = cli_download_and_extract("https://github.com/LGE-OSS/example", | ||
| "test_result/download/example", | ||
| "test_result/download_log/example") | ||
| if not success: | ||
| raise Exception(f"Download failed with git:{msg}") | ||
| success, msg, _, _ = cli_download_and_extract("https://pypi.org/project/filelock/3.4.1", | ||
| "test_result/download/filelock", | ||
| "test_result/download_log/filelock") | ||
| if not success: | ||
| raise Exception(f"Download failed with wget:{msg}") | ||
| @pytest.mark.parametrize("project_name, project_url", | ||
| [("filelock", "https://pypi.org/project/filelock/3.4.1"), | ||
| ("dependency", "https://pypi.org/project/fosslight-dependency/3.0.5/"), | ||
| ("jackson", "https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind/2.12.2"), | ||
| ("pub", "https://pub.dev/packages/file/versions/5.2.1")]) | ||
| def test_download_from_wget(project_name, project_url): | ||
| # given | ||
| target_dir = os.path.join(constants.TEST_RESULT_DIR, | ||
| os.path.join("download", project_name)) | ||
| log_dir = os.path.join(constants.TEST_RESULT_DIR, | ||
| os.path.join("download_log" + project_name)) | ||
|
|
||
| # when | ||
| success, _, _, _ = cli_download_and_extract(project_url, target_dir, log_dir) | ||
MoonJeWoong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
| # then | ||
| assert success is True | ||
| assert len(os.listdir(target_dir)) > 0 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.