def test_calls_make_parser(self): """ main calls parse_args on make_parser's returned parser. """ main([]) self.assertTrue(self.mock_parser.parse_args.called)
def test_calls_args_run(self): """ main calls args.run with args. """ main([]) self.mock_args.run.assert_called_once_with(self.mock_args)
def test_assigner(self): """ The top level assigner module should respond to help without errors. """ with self.assertRaisesRegex(SystemExit, r"^0$"): main(["--help"])
def test_main_sets_verbosity(self): """ main should set verosity and level from args. """ main([]) mock_logger = self.mock_logging.getLogger.return_value mock_logger.setLevel.assert_any_call(self.mock_args.verbosity)
def test_main_raises_exceptions_with_traceback(self): """ main should raise exceptions if traceback is True. """ self.mock_args.tracebacks = True self.mock_args.run.side_effect = ExampleError with self.assertRaises(ExampleError): main([])
def test_main_catches_exceptions(self): """ main should catch any exceptions and raise SystemExit. """ self.mock_args.tracebacks = False self.mock_args.run.side_effect = Exception with self.assertRaises(SystemExit): main([])
def test_main_logs_exceptions(self, mock_logger): """ main should log exceptions when raised. """ self.mock_args.tracebacks = False self.mock_args.run.side_effect = ExampleError try: main([]) except SystemExit: pass mock_logger.error.assert_called_once_with(str(ExampleError()))
def test_main_logs_gitcommandnotfound_with_catch(self, mock_logger): """ main should log a GitCommandNotFound with "git is not installed!" when raised. """ self.mock_args.tracebacks = False self.mock_args.run.side_effect = GitCommandNotFound( "git", "not installed!") try: main([]) except SystemExit: pass mock_logger.error.assert_called_once_with("git is not installed!")
def test_main_logs_keyerror_with_catch(self, mock_logger): """ main should log a KeyError with "is missing" when raised. """ self.mock_args.tracebacks = False self.mock_args.run.side_effect = KeyError() try: main([]) except SystemExit: pass mock_logger.error.assert_called_once_with( "%s is missing", self.mock_args.run.side_effect)
def test_main_reports_unexpected_exceptions(self, mock_logger): """ main should log exceptions when raised. """ self.mock_args.tracebacks = False self.mock_args.run.side_effect = ExampleError("unexpected error") try: main([]) except SystemExit: pass mock_logger.error.assert_any_call(str( ExampleError("unexpected error"))) mock_logger.error.assert_any_call( "This is a bug. Please file an issue here: https://github.com/redkyn/assigner/issues/new" )
def test_subcommand(self, command): ("The {} subcommand should respond to help without errors.".format( command)) with self.assertRaisesRegex(SystemExit, r"^0$"): main([command, "--help"])