Exemplo n.º 1
0
    def test_unknown_error(self, mocked_parse_args, mocked_exit):
        """Test an unknown error exit
        """
        # create mocks
        def function(args):
            raise Exception("error")

        mocked_parse_args.return_value = Namespace(function=function, debug=False)

        # call the function
        with self.assertLogs("dakara_feeder.commands.feed", "DEBUG") as logger:
            feed.main()

        # assert the call
        mocked_exit.assert_called_with(128)

        # assert the logs
        self.assertListEqual(
            logger.output,
            [
                ANY,
                "CRITICAL:dakara_feeder.commands.feed:Please fill a bug report at "
                "https://github.com/DakaraProject/dakara-feeder/issues",
            ],
        )
Exemplo n.º 2
0
    def test_normal_exit(self, mocked_parse_args, mocked_exit):
        """Test a normal exit
        """
        # create mocks
        function = MagicMock()
        mocked_parse_args.return_value = Namespace(function=function, debug=False)

        # call the function
        feed.main()

        # assert the call
        function.assert_called_with(ANY)
        mocked_exit.assert_called_with(0)
Exemplo n.º 3
0
    def test_unknown_error_debug(self, mocked_parse_args, mocked_exit):
        """Test an unknown error exit in debug mode
        """
        # create mocks
        def function(args):
            raise Exception("error")

        mocked_parse_args.return_value = Namespace(function=function, debug=True)

        # call the function
        with self.assertRaisesRegex(Exception, "error"):
            feed.main()

        # assert the call
        mocked_exit.assert_not_called()
Exemplo n.º 4
0
    def test_known_error(self, mocked_parse_args, mocked_exit):
        """Test a known error exit
        """
        # create mocks
        def function(args):
            raise DakaraError("error")

        mocked_parse_args.return_value = Namespace(function=function, debug=False)

        # call the function
        with self.assertLogs("dakara_feeder.commands.feed", "DEBUG") as logger:
            feed.main()

        # assert the call
        mocked_exit.assert_called_with(1)

        # assert the logs
        self.assertListEqual(
            logger.output, ["CRITICAL:dakara_feeder.commands.feed:error"]
        )
Exemplo n.º 5
0
    def test_keyboard_interrupt(self, mocked_parse_args, mocked_exit):
        """Test a Ctrl+C exit
        """
        # create mocks
        def function(args):
            raise KeyboardInterrupt()

        mocked_parse_args.return_value = Namespace(function=function, debug=False)

        # call the function
        with self.assertLogs("dakara_feeder.commands.feed", "DEBUG") as logger:
            feed.main()

        # assert the call
        mocked_exit.assert_called_with(255)

        # assert the logs
        self.assertListEqual(
            logger.output, ["INFO:dakara_feeder.commands.feed:Quit by user"]
        )
Exemplo n.º 6
0
from dakara_feeder.commands import feed

feed.main()