Skip to content

Commit

Permalink
Added default ini file and targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Babarberousse committed Jun 9, 2019
1 parent 073ba2d commit ccb9da0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 4 additions & 3 deletions bandit/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def main():
'(only JSON-formatted files are accepted)'
)
parser.add_argument(
'--ini', dest='ini_path', action='store', default=None,
'--ini', dest='ini_path', action='store', default='.bandit',
help='path to a .bandit file that supplies command line arguments'
)
python_ver = sys.version.replace('\n', '')
Expand Down Expand Up @@ -334,9 +334,10 @@ def main():
'recursive')
# TODO(tmcpeak): any other useful options to pass from .bandit?

# If no target has been set through args or ini file, then use a default
if not args.targets:
LOG.error("No targets found in CLI or ini files, exiting.")
sys.exit(2)
args.targets = '.'

# if the log format string was set in the options, reinitialize
if b_conf.get_option('log_format'):
log_format = b_conf.get_option('log_format')
Expand Down
2 changes: 1 addition & 1 deletion bandit/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def parse_ini_file(f_loc):
return {k: v for k, v in config.items('bandit')}

except (configparser.Error, KeyError, TypeError):
LOG.warning("Unable to parse config file %s or missing [bandit] "
LOG.warning("Config file %s not found or missing [bandit] "
"section", f_loc)

return None
Expand Down
8 changes: 2 additions & 6 deletions tests/functional/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ def _test_example(self, cmdlist, targets):
cmdlist.append(os.path.join(os.getcwd(), 'examples', t))
return self._test_runtime(cmdlist)

def test_no_arguments(self):
(retcode, output) = self._test_runtime(['bandit', ])
self.assertEqual(2, retcode)
self.assertIn("No targets found in CLI or ini files", output)

def test_piped_input(self):
with open('examples/imports.py', 'r') as infile:
(retcode, output) = self._test_runtime(['bandit', '-'], infile)
Expand Down Expand Up @@ -102,7 +97,8 @@ def test_example_okay(self):
self.assertIn("No issues identified.", output)

def test_recurse(self):
(retcode, output) = self._test_runtime(['bandit', '-r', 'examples/recursive1'])
(retcode, output) = self._test_runtime(['bandit', '-r',
'examples/recursive1'])
self.assertEqual(0, retcode)
self.assertIn("Total lines of code: 2", output)
self.assertIn("Files skipped (0):", output)
Expand Down

0 comments on commit ccb9da0

Please sign in to comment.