Skip to content

Commit 33e047c

Browse files
authored
Merge pull request #83 from fosslight/develop
Check null after removing empty sheet
2 parents bb43d5a + 1d93034 commit 33e047c

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

src/fosslight_util/output_format.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
55
import os
6-
from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv
6+
from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv, remove_empty_sheet
77
from fosslight_util.write_opossum import write_opossum
88
from fosslight_util.write_yaml import write_yaml
99

@@ -63,7 +63,8 @@ def write_output_file(output_file_without_ext, file_extension, sheet_list, exten
6363
success = True
6464
msg = ''
6565

66-
if sheet_list:
66+
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
67+
if is_not_null:
6768
if file_extension == '':
6869
file_extension = '.xlsx'
6970
result_file = output_file_without_ext + file_extension

src/fosslight_util/write_excel.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
115115

116116
try:
117117
sheet_list = copy.deepcopy(sheet_list_origin)
118-
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
119-
if is_not_null:
118+
if sheet_list:
120119
output_files = []
121120
output_dir = os.path.dirname(output_file)
122121
Path(output_dir).mkdir(parents=True, exist_ok=True)
@@ -160,8 +159,7 @@ def write_result_to_excel(out_file_name, sheet_list, extended_header={}):
160159
error_msg = ""
161160

162161
try:
163-
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
164-
if is_not_null:
162+
if sheet_list:
165163
output_dir = os.path.dirname(out_file_name)
166164
Path(output_dir).mkdir(parents=True, exist_ok=True)
167165

src/fosslight_util/write_opossum.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from typing import Dict, Optional
1515

1616
import fosslight_util.constant as constant
17-
from fosslight_util.write_excel import remove_empty_sheet
1817

1918

2019
PACKAGE = {
@@ -177,9 +176,7 @@ def write_opossum(filename, sheet_list):
177176
_filesWithChildren_key = 'filesWithChildren'
178177
_attributionBreakpoints_key = 'attributionBreakpoints'
179178

180-
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
181-
182-
if is_not_null:
179+
if sheet_list:
183180
output_dir = os.path.dirname(filename)
184181
Path(output_dir).mkdir(parents=True, exist_ok=True)
185182

src/fosslight_util/write_yaml.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from pathlib import Path
1111
import fosslight_util.constant as constant
1212
from fosslight_util.oss_item import OssItem
13-
from fosslight_util.write_excel import remove_empty_sheet, _EMPTY_ITEM_MSG
13+
from fosslight_util.write_excel import _EMPTY_ITEM_MSG
1414

1515
_logger = logging.getLogger(constant.LOGGER_NAME)
1616

@@ -22,8 +22,7 @@ def write_yaml(output_file, sheet_list_origin, separate_yaml=False):
2222

2323
try:
2424
sheet_list = copy.deepcopy(sheet_list_origin)
25-
is_not_null, sheet_list = remove_empty_sheet(sheet_list)
26-
if is_not_null:
25+
if sheet_list:
2726
output_files = []
2827
output_dir = os.path.dirname(output_file)
2928

tests/test_excel_and_csv.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# -*- coding: utf-8 -*-
33
# Copyright (c) 2021 LG Electronics Inc.
44
# SPDX-License-Identifier: Apache-2.0
5-
from fosslight_util.write_excel import write_excel_and_csv, write_result_to_csv, write_result_to_excel
5+
from fosslight_util.write_excel import write_excel_and_csv
6+
from fosslight_util.output_format import write_output_file
67
from fosslight_util.set_log import init_log
8+
from copy import deepcopy
79

810

911
def main():
@@ -53,23 +55,17 @@ def main():
5355

5456
logger.warning("TESTING - Writing an excel and csv")
5557
success, msg, result_file = write_excel_and_csv(
56-
'test_result/excel_and_csv/FOSSLight-Report', sheet_contents)
57-
logger.warning(f"Result:{success}, error_msg:{msg}, result:{result_file}")
58+
'test_result/excel_and_csv/FOSSLight-Report', deepcopy(sheet_contents))
59+
logger.warning(f"|-- Result:{success}, file:{result_file}, error_msg:{msg}")
5860

5961
logger.warning("TESTING - Writing an excel")
60-
success, msg = write_result_to_excel(
61-
'test_result/excel_and_csv/excel/Test_Excel.xlsx', sheet_contents)
62-
logger.warning(f"Result:{success}, error_msg:{msg}")
62+
success, msg, result_file = write_output_file('test_result/excel_and_csv/excel/Test_Excel', '.xlsx', deepcopy(sheet_contents))
63+
logger.warning(f"|-- Result:{success}, file:{result_file}, error_msg:{msg}")
6364

64-
logger.warning("TESTING - Writing an csv (separate sheet)")
65-
success, msg, result_file = write_result_to_csv(
66-
'test_result/excel_and_csv/csv/Test_Csv.csv', sheet_contents, True)
67-
logger.warning(f"Result:{success}, error_msg:{msg}, result:{result_file}")
68-
69-
logger.warning("TESTING - Writing an csv (merge one sheet)")
70-
success, msg, result_file = write_result_to_csv(
71-
'test_result/excel_and_csv/csv/Test_Csv.csv', sheet_contents)
72-
logger.warning(f"Result:{success}, error_msg:{msg}, result:{result_file}")
65+
logger.warning("TESTING - Writing an csv")
66+
success, msg, result_file = write_output_file(
67+
'test_result/excel_and_csv/csv/Test_Csv', '.csv', deepcopy(sheet_contents))
68+
logger.warning(f"|-- Result:{success}, file:{result_file}, error_msg:{msg}")
7369

7470

7571
if __name__ == '__main__':

tox.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ commands =
3535
cat test_result/excel_and_csv/FOSSLight-Report_BIN_TEST.csv
3636
cat test_result/excel_and_csv/FOSSLight-Report_CUSTOM_HEADER_SHEET.csv
3737
cat test_result/excel_and_csv/csv/Test_Csv.csv
38-
cat test_result/excel_and_csv/csv/Test_Csv_SRC.csv
39-
cat test_result/excel_and_csv/csv/Test_Csv_BIN_TEST.csv
40-
cat test_result/excel_and_csv/csv/Test_Csv_CUSTOM_HEADER_SHEET.csv
4138
# Test - downloading source
4239
fosslight_download -s "https://github.com/LGE-OSS/example" -t test_git/
4340
ls test_git/
@@ -72,9 +69,6 @@ commands =
7269
cat test_result/excel_and_csv/FOSSLight-Report_BIN_TEST.csv
7370
cat test_result/excel_and_csv/FOSSLight-Report_CUSTOM_HEADER_SHEET.csv
7471
cat test_result/excel_and_csv/csv/Test_Csv.csv
75-
cat test_result/excel_and_csv/csv/Test_Csv_SRC.csv
76-
cat test_result/excel_and_csv/csv/Test_Csv_BIN_TEST.csv
77-
cat test_result/excel_and_csv/csv/Test_Csv_CUSTOM_HEADER_SHEET.csv
7872
# Test - writing opossum
7973
python tests/test_opossum.py
8074
ls test_result/opossum

0 commit comments

Comments
 (0)