-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor existing tox test to pytest #123
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
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0011cce
test-code revision
s-cu-bot 344909d
test-code revision
s-cu-bot 2858305
Merge branch 's-cu-bot' of https://github.com/s-cu-bot/fosslight_bina…
s-cu-bot ec66597
Update initial_tox_test.py
s-cu-bot 23e3bcd
Update initial_tox_test.py
s-cu-bot b3243a8
Update initial_tox_test.py
s-cu-bot 040bab3
Update initial_tox_test.py
s-cu-bot 0655ac1
create new test case
s-cu-bot 6b96411
Update tox.ini
s-cu-bot 0f904ff
Update file_format_test.py
s-cu-bot edfcbbf
Update initial_tox_test.py
s-cu-bot 3af7a1d
Update tox.ini
s-cu-bot a9220c9
Update tox.ini
s-cu-bot 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
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 |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ tox | |
| pytest | ||
| pytest-cov | ||
| pytest-flake8 | ||
| pytest-xdist | ||
| flake8==3.9.2 | ||
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,45 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2020 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
|
|
||
| def run_command(*args): # 리눅스 명령어 실행 | ||
| result = subprocess.run(args, capture_output=True, text=True) | ||
| success = result.returncode == 0 | ||
| output = result.stdout if success else result.stderr | ||
| return success, output | ||
|
|
||
|
|
||
| def test_output_file_format(): # 테스트 환경 tox.ini | ||
| # Given | ||
| run_command("rm", "-rf", "test_result") | ||
| os.makedirs("test_result", exist_ok=True) | ||
|
|
||
| # When | ||
| excel_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "excel") | ||
| csv_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "csv") | ||
| opossum_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "opossum") | ||
| yaml_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "yaml") | ||
s-cu-bot marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| files_in_result = os.listdir("test_result") | ||
|
|
||
| # Then | ||
| excel_files = [f for f in files_in_result if f.endswith('.xlsx')] # Assuming Excel files end with .xlsx | ||
| csv_files = [f for f in files_in_result if f.endswith('.csv')] | ||
| opossum_files = [f for f in files_in_result if f.endswith('.json')] # Assuming opossum files are in JSON format | ||
| yaml_files = [f for f in files_in_result if f.endswith('.yaml') or f.endswith('.yml')] | ||
|
|
||
| assert excel_success is True, "Test Output File : Excel files not properly created (not create)" | ||
| assert len(excel_files) > 0, "Test Output File : Excel files not properly created (length)" | ||
|
|
||
| assert csv_success is True, "Test Output File : CSV files not properly created (not create)" | ||
| assert len(csv_files) > 0, "Test Output File : CSV files not properly created (length)" | ||
|
|
||
| assert opossum_success is True, "Test Output File : JSON files not properly created (not create)" | ||
| assert len(opossum_files) > 0, "Test Output File : JSON files not properly created (length)" | ||
|
|
||
| assert yaml_success is True, "Test Output File : Yaml files not properly created (not create)" | ||
| assert len(yaml_files) > 0, "Test Output File : Yaml files not properly created (length)" | ||
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,70 @@ | ||
| #!/usr/bin/env python | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) 2020 LG Electronics Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import os | ||
| import subprocess | ||
|
|
||
|
|
||
| def run_command(*args): # 리눅스 명령어 실행 | ||
| result = subprocess.run(args, capture_output=True, text=True) | ||
| success = result.returncode == 0 | ||
| output = result.stdout if success else result.stderr | ||
| return success, output | ||
|
|
||
|
|
||
| def test_test_run_environment(): # 테스트 환경 tox.ini | ||
| # Given | ||
| run_command("rm", "-rf", "test_result") | ||
| os.makedirs("test_result", exist_ok=True) | ||
|
|
||
| # When | ||
| csv_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "csv") | ||
| exclude_success, _ = run_command( | ||
| "fosslight_bin", | ||
| "-p", ".", | ||
| "-e", "test", "commons-logging-1.2.jar", | ||
| "-o", "test_result/exclude_result.csv", | ||
| "-f", "csv" | ||
| ) | ||
|
|
||
| files_in_result = run_command("ls", "test_result")[1].split() | ||
| txt_success, txt_output = run_command("find", "test_result", "-type", "f", "-name", "fosslight_log*.txt") | ||
|
|
||
| # Then | ||
| csv_files = [f for f in files_in_result if f.endswith('.csv')] | ||
| txt_files = txt_output.split() | ||
| assert csv_success is True, "Test Run Environment: CSV files not properly created (not create)" | ||
| assert len(csv_files) > 0, "Test Run Environment: CSV files not properly created (length)" | ||
| assert exclude_success is True, "Test Run Environment: Exclude feature fail" | ||
| assert len(txt_files) > 0, "Test Run Environment: txt files not properly created" | ||
|
|
||
|
|
||
| def test_release_environment(): # 릴리즈 환경 tox.ini | ||
| # Given | ||
| run_command("rm", "-rf", "test_result") | ||
| os.makedirs("test_result", exist_ok=True) | ||
|
|
||
| # When | ||
| help_success, _ = run_command("fosslight_bin", "-h") | ||
| csv_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result/result.csv", "-f", "csv") | ||
| exclude_csv_success, _ = run_command( | ||
| "fosslight_bin", | ||
| "-p", ".", | ||
| "-e", "test", "commons-logging-1.2.jar", | ||
| "-o", "test_result/exclude_result.csv", | ||
| "-f", "csv" | ||
| ) | ||
|
|
||
| json_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result/result.json", "-f", "opossum") | ||
| files_in_result = run_command("ls", "test_result")[1].split() | ||
|
|
||
| # Then | ||
| required_files = ['result.csv', 'exclude_result.csv', 'result.json'] | ||
| files_exist = all(f in files_in_result for f in required_files) | ||
| assert help_success is True, "Release Run Environment: help method not properly processing" | ||
| assert csv_success is True, "Release Run Environment: CSV files not properly created" | ||
| assert exclude_csv_success is True, "Release Run Environment: Exclude feature fail" | ||
| assert json_success is True, "Release Run Environment: json files not properly created" | ||
| assert files_exist is True, "Release Run Environment: Required files not properly created" |
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
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.