Skip to content

Commit 344909d

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

File tree

3 files changed

+57
-15
lines changed

3 files changed

+57
-15
lines changed

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ tox
33
pytest
44
pytest-cov
55
pytest-flake8
6+
pytest-xdist
67
flake8==3.9.2

tests/initial_tox_test.py

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

tox.ini

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ allowlist_externals =
1111
ls
1212
rm
1313
cat
14+
pytest
1415
{toxinidir}/dist/cli
1516
setenv =
1617
PYTHONPATH=.
@@ -24,28 +25,17 @@ ignore = E722, W503
2425
filterwarnings = ignore::DeprecationWarning
2526

2627
[testenv:test_run]
28+
changedir = tests
2729
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'
30+
pytest -n 4 initial_tox_test.py::test_test_run_environment
3431

3532
[testenv:release]
3633
deps =
3734
-r{toxinidir}/requirements-dev.txt
3835

3936
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
37+
pytest -n 5 tests/initial_tox_test.py::test_release_environment
4738
pytest -v --flake8
4839
pyinstaller --onefile cli.py -n cli --additional-hooks-dir=hooks --hidden-import=pkg_resources.extern
4940
{toxinidir}/dist/cli -p tests -o test_result_cli
50-
; py.test --cov-report term-missing --cov={envsitepackagesdir}/fosslight_binary
51-
41+
; py.test --cov-report term-missing --cov={envsitepackagesdir}/fosslight_binary

0 commit comments

Comments
 (0)