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"
0 commit comments