Merge "Don't mock argparse"
This commit is contained in:
commit
a14a7a313d
|
@ -264,7 +264,7 @@ def main():
|
|||
parser.add_argument('-s', '--show', action='store_true', default=False)
|
||||
opts = parser.parse_args()
|
||||
|
||||
if opts.show is True:
|
||||
if opts.show:
|
||||
messages.print_messages()
|
||||
sys.exit(0)
|
||||
|
||||
|
|
|
@ -33,34 +33,20 @@ class TestBashate(base.TestCase):
|
|||
super(TestBashate, self).setUp()
|
||||
self.run = bashate.BashateRun()
|
||||
|
||||
@mock.patch('argparse.ArgumentParser')
|
||||
@mock.patch('bashate.bashate.BashateRun')
|
||||
def test_main_no_files(self, m_bashaterun, m_argparser):
|
||||
m_opts = mock.MagicMock()
|
||||
m_opts.files = []
|
||||
m_parser_obj = mock.MagicMock()
|
||||
m_parser_obj.parse_args = mock.Mock(return_value=m_opts)
|
||||
m_argparser.return_value = m_parser_obj
|
||||
|
||||
@mock.patch('sys.argv')
|
||||
def test_main_no_files(self, m_bashaterun, m_argv):
|
||||
m_run_obj = mock.MagicMock()
|
||||
m_run_obj.ERRORS = 0
|
||||
m_bashaterun.return_value = m_run_obj
|
||||
|
||||
result = bashate.main()
|
||||
|
||||
m_parser_obj.print_usage.assert_called_once_with()
|
||||
expected_return = 1
|
||||
self.assertEqual(expected_return, result)
|
||||
|
||||
@mock.patch('argparse.ArgumentParser')
|
||||
@mock.patch('bashate.bashate.BashateRun')
|
||||
def test_main_return_one_on_errors(self, m_bashaterun, m_argparser):
|
||||
m_opts = mock.MagicMock()
|
||||
m_opts.files = 'not_a_file'
|
||||
m_parser_obj = mock.MagicMock()
|
||||
m_parser_obj.parse_args = mock.Mock(return_value=m_opts)
|
||||
m_argparser.return_value = m_parser_obj
|
||||
|
||||
@mock.patch('sys.argv')
|
||||
def test_main_return_one_on_errors(self, m_bashaterun, m_argv):
|
||||
m_run_obj = mock.MagicMock()
|
||||
m_run_obj.WARNINGS = 1
|
||||
m_run_obj.ERRORS = 1
|
||||
|
@ -70,15 +56,9 @@ class TestBashate(base.TestCase):
|
|||
expected_return = 1
|
||||
self.assertEqual(expected_return, result)
|
||||
|
||||
@mock.patch('argparse.ArgumentParser')
|
||||
@mock.patch('bashate.bashate.BashateRun')
|
||||
def test_main_return_one_on_ioerror(self, m_bashaterun, m_argparser):
|
||||
m_opts = mock.MagicMock()
|
||||
m_opts.files = 'not_a_file'
|
||||
m_parser_obj = mock.MagicMock()
|
||||
m_parser_obj.parse_args = mock.Mock(return_value=m_opts)
|
||||
m_argparser.return_value = m_parser_obj
|
||||
|
||||
@mock.patch('sys.argv')
|
||||
def test_main_return_one_on_ioerror(self, m_bashaterun, m_argv):
|
||||
m_run_obj = mock.MagicMock()
|
||||
m_run_obj.ERRORS = 0
|
||||
m_run_obj.check_files = mock.Mock(side_effect=IOError)
|
||||
|
|
Loading…
Reference in New Issue