Example #1
0
    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)
Example #2
0
    def test_calls_args_run(self):
        """
        main calls args.run with args.
        """
        main([])

        self.mock_args.run.assert_called_once_with(self.mock_args)
Example #3
0
 def test_assigner(self):
     """
     The top level assigner module should respond to help
     without errors.
     """
     with self.assertRaisesRegex(SystemExit, r"^0$"):
         main(["--help"])
Example #4
0
    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)
Example #5
0
    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([])
Example #6
0
    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([])
Example #7
0
    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()))
Example #8
0
    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!")
Example #9
0
    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)
Example #10
0
    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"
        )
Example #11
0
 def test_subcommand(self, command):
     ("The {} subcommand should respond to help without errors.".format(
         command))
     with self.assertRaisesRegex(SystemExit, r"^0$"):
         main([command, "--help"])