Skip to content

Commit

Permalink
Issue#17: Adding exit codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiah-c-leary committed Mar 5, 2024
1 parent 16a4ee0 commit 3bf797e
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
#html_static_path = ['_static']

html_sidebars = {
'**': [
Expand Down
21 changes: 21 additions & 0 deletions docs/source/exit_codes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Exit Codes
==========

ELFWS provides the following exit codes to report execution status.

+------+---------------------------------+
| Code | Description |
+======+=================================+
| 0 | Success |
+------+---------------------------------+
| 1 | Suppression file error |
+------+---------------------------------+
| 2 | No matching log parser |
+------+---------------------------------+
| 3 | No command line arguments given |
+------+---------------------------------+
| 4 | Could not write report file |
+------+---------------------------------+
| 5 | Could not write junit file |
+------+---------------------------------+

1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Welcome to eda-log-file-warning-suppressor's documentation!
overview
installation
usage
exit_codes
evaluating_warnings
suppression_rules
theory_of_operation/theory_of_operation
Expand Down
2 changes: 1 addition & 1 deletion elfws/cmd_line_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def print_help_if_no_command_line_options_given(oParser):
'''
if len(sys.argv) == 1:
oParser.print_help()
sys.exit(1)
sys.exit(3)


def add_file_arguments_to_parser(oParser):
Expand Down
2 changes: 2 additions & 0 deletions elfws/subcommand/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def create(cla):
with open(cla.output_suppression_file, 'w') as file:
yaml.dump(dSup, file)

sys.exit(0)


def create_suppression_dict(oWarnList):
'''
Expand Down
6 changes: 4 additions & 2 deletions elfws/subcommand/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def report(cla):
build_section_5(oWarnList, lReport)
build_summary(oWarnList, oSupList, lReport)

utils.write_file(cla.report_file, lReport)
utils.write_report_file(cla.report_file, lReport)

if cla.junit:
lJUnitFile = junit.generate_junit_xml_file(cla, oWarnList, oSupList)
utils.write_file(cla.junit, lJUnitFile)
utils.write_junit_file(cla.junit, lJUnitFile)

sys.exit(0)


def build_header(cla, lReport):
Expand Down
4 changes: 3 additions & 1 deletion elfws/subcommand/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ def show(cla):

if cla.junit:
lJUnitFile = junit.generate_junit_xml_file(cla, oWarnList, oSupList)
utils.write_file(cla.junit, lJUnitFile)
utils.write_junit_file(cla.junit, lJUnitFile)

sys.exit(0)
2 changes: 2 additions & 0 deletions elfws/subcommand/suppress.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def suppress(cla):

display.results(cla.log_file, cla.suppression_file, oSupList, oWarnList)

sys.exit(0)


def extract_non_suppressed_warnings(oWarnList, oSupList):
oReturn = warning_list.create()
Expand Down
4 changes: 3 additions & 1 deletion elfws/subcommand/version.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

import sys

from elfws import version


def print_version():

print('EDA Log File Warning Suppressor (ELFWS) version ' + version.version)
exit(0)
sys.exit(0)
13 changes: 11 additions & 2 deletions elfws/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def create_warning_list(lLogFile, sLogFileName):
return mTool.extract_warnings(lLogFile)
except AttributeError:
print('ERROR: File ' + sLogFileName + ' is not recognized as a supported logfile.')
sys.exit(1)
sys.exit(2)


def apply_suppression_rules_to_warnings(oWarnList, oSupList):
Expand Down Expand Up @@ -378,7 +378,15 @@ def do_messages_match(oWarning, oSuppression):
return False


def write_file(sFilename, lFile):
def write_junit_file(sFilename, lFile):
write_file(sFilename, lFile, 5)


def write_report_file(sFilename, lFile):
write_file(sFilename, lFile, 4)


def write_file(sFilename, lFile, iExitCode):
'''
Writes a list of strings to a file.
Expand All @@ -396,3 +404,4 @@ def write_file(sFilename, lFile):
oFile.write(sLine + '\n')
except PermissionError as err:
print(err, "Could not write to file " + sFilename)
sys.exit(iExitCode)
96 changes: 83 additions & 13 deletions tests/elfws/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def tearDown(self):
@mock.patch('sys.stdout')
def test_version(self, mockStdout):
sys.argv = ['elfws', 'version']

try:
__main__.main()
except SystemExit:
pass
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)


mockStdout.write.assert_has_calls([
mock.call('EDA Log File Warning Suppressor (ELFWS) version ' + version.version), mock.call('\n')
Expand All @@ -52,7 +56,13 @@ def test_version(self, mockStdout):
def test_show(self, mock_datetime, mock_stdout):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'show', sWarningFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lLogFile = utils.read_log_file('tests/elfws/show_output.txt')

Expand All @@ -66,7 +76,13 @@ def test_show(self, mock_datetime, mock_stdout):
@mock.patch('elfws.version.version', '0.1')
def test_create_without_suppression_file(self):
sys.argv = ['elfws', 'create', sWarningFile, sYamlFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/create_yaml_wo_suppression.yaml')
lActual = utils.read_log_file(sYamlFile)
Expand All @@ -76,7 +92,13 @@ def test_create_without_suppression_file(self):
@mock.patch('elfws.version.version', '0.1')
def test_create_with_suppression_file(self):
sys.argv = ['elfws', 'create', sWarningFile, sYamlFile, '--suppression_file', sSupFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/create_yaml_with_suppression.yaml')
lActual = utils.read_log_file(sYamlFile)
Expand All @@ -89,7 +111,13 @@ def test_create_with_suppression_file(self):
def test_suppress(self, mock_datetime, mock_stdout):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'suppress', sWarningFile, sSupFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lLogFile = utils.read_log_file('tests/elfws/suppress_output.txt')

Expand All @@ -105,7 +133,13 @@ def test_suppress(self, mock_datetime, mock_stdout):
def test_report(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', sWarningFile, 'tests/subcommand/report/suppress_microsemi_designer_logfile.yaml', sReportFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/report_output.txt')
lActual = utils.read_log_file(sReportFile)
Expand All @@ -117,7 +151,13 @@ def test_report(self, mock_datetime):
def test_report_all_warnings_suppressed(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', sWarningFile, 'tests/elfws/suppress_all_microsemi_designer_warnings.yaml', sReportFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/report_output_all_warnings_suppressed.txt')
lActual = utils.read_log_file(sReportFile)
Expand All @@ -129,7 +169,13 @@ def test_report_all_warnings_suppressed(self, mock_datetime):
def test_report_no_warnings(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', 'tests/elfws/no_warnings/warning_messages.rpt', 'tests/elfws/no_warnings/suppression_file.yaml', sReportFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/no_warnings/report_output.txt')
lActual = utils.read_log_file(sReportFile)
Expand All @@ -141,7 +187,13 @@ def test_report_no_warnings(self, mock_datetime):
def test_report_w_long_id(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', 'tests/vendor/microsemi/designer/warning_messages_w_long_id.rpt', 'tests/subcommand/report/suppress_microsemi_designer_logfile_w_long_id.yaml', sReportFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/report_output_long_id.txt')
lActual = utils.read_log_file(sReportFile)
Expand All @@ -153,7 +205,13 @@ def test_report_w_long_id(self, mock_datetime):
def test_report_w_investigate(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', 'tests/vendor/microsemi/designer/warning_messages.log', 'tests/elfws/investigate/suppression.yaml', sReportFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/elfws/investigate/report_output.txt')
lActual = utils.read_log_file(sReportFile)
Expand All @@ -162,7 +220,13 @@ def test_report_w_investigate(self, mock_datetime):

def test_report_w_junit_output(self):
sys.argv = ['elfws', 'report', 'tests/vendor/microsemi/designer/warning_messages.log', 'tests/subcommand/report/suppress_for_junit_xml.yaml', sReportFile, '--junit', sXmlFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/subcommand/report/junit_output.xml')
lActual = utils.read_log_file(sXmlFile)
Expand All @@ -175,7 +239,13 @@ def test_report_w_junit_output(self):
@mock.patch('sys.stdout')
def test_show_w_junit_output(self, mockStdout):
sys.argv = ['elfws', 'show', 'tests/vendor/microsemi/designer/warning_messages.log', '--junit', sXmlFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/subcommand/show/junit_output.xml')
lActual = utils.read_log_file(sXmlFile)
Expand Down
8 changes: 7 additions & 1 deletion tests/junit/test_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ def tearDown(self):
@mock.patch('sys.stdout')
def test_report_w_junit_output(self, mockStdout):
sys.argv = ['elfws', 'show', sWarningFile, '--junit', sXmlFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file(os.path.join(os.path.dirname(__file__), 'junit_output.xml'))
lActual = utils.read_log_file(sXmlFile)
Expand Down
8 changes: 7 additions & 1 deletion tests/option/suppress_in_json_if_unmatched/test_option.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class test_arguments(unittest.TestCase):
def test_report_w_junit_output(self, mock_datetime):
mock_datetime.now.return_value = 'Some Date'
sys.argv = ['elfws', 'report', os.path.join(os.path.dirname(__file__), 'warning_messages.log'), os.path.join(os.path.dirname(__file__), 'suppression.yaml'), sReportFile, '--junit', sXmlFile]
__main__.main()

try:
__main__.main()
except SystemExit as e:
iExitStatus = e.args[0]

self.assertEqual(iExitStatus, 0)

lExpected = utils.read_log_file('tests/option/suppress_in_json_if_unmatched/expected.xml')
lActual = utils.read_log_file(sXmlFile)
Expand Down

0 comments on commit 3bf797e

Please sign in to comment.