diff --git a/bashate/bashate.py b/bashate/bashate.py index 4512238..6c72a97 100755 --- a/bashate/bashate.py +++ b/bashate/bashate.py @@ -372,7 +372,10 @@ class BashateRun(object): report.print_error(MESSAGES['E004'].msg, line) -def main(): +def main(args=None): + + if args is None: + args = sys.argv[1:] parser = argparse.ArgumentParser( description='A bash script style checker') @@ -385,7 +388,7 @@ def main(): help='Rules to always error (rather than warn)') parser.add_argument('-v', '--verbose', action='store_true', default=False) parser.add_argument('-s', '--show', action='store_true', default=False) - opts = parser.parse_args() + opts = parser.parse_args(args) if opts.show: messages.print_messages() diff --git a/bashate/tests/test_bashate.py b/bashate/tests/test_bashate.py index 103db9a..089728f 100644 --- a/bashate/tests/test_bashate.py +++ b/bashate/tests/test_bashate.py @@ -34,37 +34,38 @@ class TestBashate(base.TestCase): self.run = bashate.BashateRun() @mock.patch('bashate.bashate.BashateRun') - @mock.patch('sys.argv') - def test_main_no_files(self, m_bashaterun, m_argv): + def test_main_no_files(self, m_bashaterun): m_run_obj = mock.MagicMock() m_run_obj.error_count = 0 + m_run_obj.warning_count = 0 m_bashaterun.return_value = m_run_obj - result = bashate.main() + result = bashate.main([]) expected_return = 1 self.assertEqual(expected_return, result) @mock.patch('bashate.bashate.BashateRun') - @mock.patch('sys.argv') - def test_main_return_one_on_errors(self, m_bashaterun, m_argv): + def test_main_return_one_on_errors(self, m_bashaterun): m_run_obj = mock.MagicMock() m_run_obj.warning_count = 1 m_run_obj.error_count = 1 m_bashaterun.return_value = m_run_obj - result = bashate.main() + result = bashate.main([]) expected_return = 1 self.assertEqual(expected_return, result) @mock.patch('bashate.bashate.BashateRun') - @mock.patch('sys.argv') - def test_main_return_one_on_ioerror(self, m_bashaterun, m_argv): + def test_main_return_one_on_ioerror(self, m_bashaterun): m_run_obj = mock.MagicMock() m_run_obj.error_count = 0 m_run_obj.check_files = mock.Mock(side_effect=IOError) m_bashaterun.return_value = m_run_obj - result = bashate.main() + result = bashate.main(['--verbose', + '/path/to/fileA', '/path/to/fileB']) + m_run_obj.check_files.assert_called_with(['/path/to/fileA', + '/path/to/fileB'], True) expected_return = 1 self.assertEqual(expected_return, result)