Skip to content

Commit 0655ac1

Browse files
authored
create new test case
1 parent 040bab3 commit 0655ac1

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/file_format_test.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2020 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import os
7+
import subprocess
8+
9+
10+
def run_command(*args): # 리눅스 명령어 실행
11+
result = subprocess.run(args, capture_output=True, text=True)
12+
success = result.returncode == 0
13+
output = result.stdout if success else result.stderr
14+
return success, output
15+
16+
17+
def test_output_file_format(): # 테스트 환경 tox.ini
18+
# Given
19+
run_command("rm", "-rf", "test_result")
20+
os.makedirs("test_result", exist_ok=True)
21+
22+
# When
23+
excel_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "excel")
24+
csv_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "csv")
25+
opossum_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "opossum")
26+
yaml_success, _ = run_command("fosslight_bin", "-p", ".", "-o", "test_result", "-f", "yaml")
27+
files_in_result = os.listdir("test_result")
28+
29+
# Then
30+
excel_files = [f for f in files_in_result if f.endswith('.xlsx')] # Assuming Excel files end with .xlsx
31+
csv_files = [f for f in files_in_result if f.endswith('.csv')]
32+
opossum_files = [f for f in files_in_result if f.endswith('.json')] # Assuming opossum files are in JSON format
33+
yaml_files = [f for f in files_in_result if f.endswith('.yaml') or f.endswith('.yml')]
34+
35+
assert excel_success is True, "Test Output File : Excel files not properly created (not create)"
36+
assert len(excel_files) > 0, "Test Output File : Excel files not properly created (length)"
37+
38+
assert csv_success is True, "Test Output File : CSV files not properly created (not create)"
39+
assert len(csv_files) > 0, "Test Output File : CSV files not properly created (length)"
40+
41+
assert opossum_success is True, "Test Output File : JSON files not properly created (not create)"
42+
assert len(opossum_files) > 0, "Test Output File : JSON files not properly created (length)"
43+
44+
assert yaml_success is True, "Test Output File : Yaml files not properly created (not create)"
45+
assert len(yaml_files) > 0, "Test Output File : Yaml files not properly created (length)"

0 commit comments

Comments
 (0)