Skip to content

Commit

Permalink
Fixed up some unexpected behavior (#35)
Browse files Browse the repository at this point in the history
* fixed occasional error message

* removed a test I was doing

* added unit test that handles a tags filter
  • Loading branch information
nhakmiller authored Jul 10, 2020
1 parent ad1393c commit 8897956
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions panther_analysis_tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,14 @@ def run_tests(analysis: Dict[str, Any], analysis_funcs: Dict[str, Any],
result = analysis_funcs['run'](test_case)
except KeyError as err:
logging.warning('KeyError: {%s}', err)
failed_tests[analysis.get('PolicyID') or
analysis['RuleID']].append(unit_test['Name'])
continue
except Exception as err: # pylint: disable=broad-except
# Catch arbitrary exceptions raised by user code
logging.warning('Unexpected exception: {%s}', err)
failed_tests[analysis.get('PolicyID') or
analysis['RuleID']].append(unit_test['Name'])
continue
test_result = 'PASS'
if result != unit_test['ExpectedResult']:
Expand Down Expand Up @@ -538,9 +542,6 @@ def run() -> None:
if args.filter is not None:
args.filter = parse_filter(args.filter)
return_code, out = args.func(args)
except AttributeError:
parser.print_help()
sys.exit(1)
except Exception as err: # pylint: disable=broad-except
# Catch arbitrary exceptions without printing help message
logging.warning('Unhandled exception: "%s"', err)
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/panther_analysis_tool/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ def test_with_filters(self):
assert_equal(return_code, 0)
assert_equal(len(invalid_specs), 0)

def test_with_tag_filters(self):
args = pat.setup_parser().parse_args('test --path tests/fixtures/valid_analysis --filter Tags=AWS,CIS'.split())
args.filter = pat.parse_filter(args.filter)
return_code, invalid_specs = pat.test_analysis(args)
assert_equal(return_code, 0)
assert_equal(len(invalid_specs), 0)

def test_zip_analysis(self):
# Note: This is a workaround for CI
try:
Expand Down

0 comments on commit 8897956

Please sign in to comment.