Skip to content

Commit 0011cce

Browse files
committed
test-code revision
Signed-off-by: s-cu-bot <[email protected]>
1 parent 6658d24 commit 0011cce

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed

tests/initial_tox_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
import subprocess
3+
4+
def run_command(command): #리눅스 명령어 실행
5+
result = subprocess.run(command, shell=True, capture_output=True, text=True)
6+
success = result.returncode == 0
7+
output = result.stdout if success else result.stderr
8+
return success, output
9+
10+
def test_test_run_environment(): #테스트 환경 tox.ini
11+
# Given
12+
run_command("rm -rf test_result")
13+
os.makedirs("test_result", exist_ok=True)
14+
15+
# When
16+
csv_success, _ = run_command("fosslight_bin -p tests -o test_result -f csv")
17+
exclude_success, _ = run_command("fosslight_bin -p tests -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv")
18+
files_in_result = run_command("ls test_result/")[1].split()
19+
txt_success, txt_output = run_command("bash -c 'find test_result -type f -name \"fosslight_binary*.txt\"'")
20+
21+
# Then
22+
csv_files = [f for f in files_in_result if f.endswith('.csv')]
23+
txt_files = txt_output.split()
24+
success = csv_success and exclude_success and len(csv_files) > 0 and len(txt_files) > 0
25+
assert success is True, "Test Run Environment: CSV and TXT files not properly created"
26+
27+
def test_release_environment(): #릴리즈 환경 tox.ini
28+
# Given
29+
os.makedirs("test_result", exist_ok=True)
30+
31+
# When
32+
help_success, _ = run_command("fosslight_bin -h")
33+
csv_success, _ = run_command("fosslight_bin -p tests -o test_result/result.csv -f csv")
34+
exclude_csv_success, _ = run_command("fosslight_bin -p tests -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv")
35+
json_success, _ = run_command("fosslight_bin -p tests -o test_result/result.json -f opossum")
36+
files_in_result = run_command("ls test_result/")[1].split()
37+
38+
# Then
39+
required_files = ['result.csv', 'exclude_result.csv', 'result.json']
40+
files_exist = all(f in files_in_result for f in required_files)
41+
success = help_success and csv_success and exclude_csv_success and json_success and files_exist
42+
assert success is True, "Release Environment: Required files not found or failed to execute"

tox.ini

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,14 @@ filterwarnings = ignore::DeprecationWarning
2525

2626
[testenv:test_run]
2727
commands =
28-
rm -rf test_result
29-
fosslight_bin -p tests -o test_result -f csv
30-
fosslight_bin -p tests -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv
31-
ls test_result/
32-
bash -c 'find test_result -type f -name "fosslight_report*.csv" | xargs cat'
33-
bash -c 'find test_result -type f -name "fosslight_binary*.txt" | xargs cat'
28+
python initial_tox_test.py::test_test_run_environment
3429

3530
[testenv:release]
3631
deps =
3732
-r{toxinidir}/requirements-dev.txt
3833

3934
commands =
40-
fosslight_bin -h
41-
fosslight_bin -p tests -o test_result/result.csv -f csv
42-
fosslight_bin -p tests -e test commons-logging-1.2.jar -o test_result/exclude_result.csv -f csv
43-
ls test_result/
44-
cat test_result/result.csv
45-
cat test_result/exclude_result.csv
46-
fosslight_bin -p tests -o test_result/result.json -f opossum
35+
python initial_tox_test.py::test_release_environment
4736
pytest -v --flake8
4837
pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --hidden-import=pkg_resources.extern
4938
{toxinidir}/dist/cli -p tests -o test_result_cli

0 commit comments

Comments
 (0)