Example #1
0
 def test_load_good_entry_points(self):
     with mock_iter_entry_points(GOOD_ENTRY_POINTS):
         resources = get_responses()
     expected = [
         amazing_demo_response({}),
         wonderful_demo_response({}),
     ]
     self.assertEqual(resources, expected)
Example #2
0
    def test_main_with_log(self):
        # Test logging configuration with the main function.
        argv = ["etsdemo", "-v"]
        mocked_io = io.StringIO()
        with mock_iter_entry_points(
            {}), mock_demo_launch(), mocked_io, mock.patch(
                "sys.stdout", mocked_io), mock.patch("sys.stderr",
                                                     mocked_io), mock.patch(
                                                         "sys.argv", argv):
            main_module.main()
            console_output = mocked_io.getvalue()

        self.assertIn("Found 0 resource(s).", console_output)
Example #3
0
    def test_main(self):
        # Main function must be launchable even if there are no data available.
        # In normal running situation, no loggings should be emitted
        argv = ["etsdemo"]
        mocked_io = io.StringIO()
        with mock_iter_entry_points(
            {}), mock_demo_launch(), mocked_io, mock.patch(
                "sys.stdout", mocked_io), mock.patch("sys.stderr",
                                                     mocked_io), mock.patch(
                                                         "sys.argv", argv):
            main_module.main()
            console_output = mocked_io.getvalue()

        self.assertNotIn("Found 0 resource(s).", console_output)
Example #4
0
    def test_load_import_error(self):
        # entry points are contributed by other packages, and loading them
        # may fail. In this test, the path is wrong and results in ImportError.
        error_entry_point = {
            "traitsui": {
                "etsdemo_data": [
                    "missing_demo={}:nonexisting_function".format(__name__),
                    "amazing_demo={}:amazing_demo_response".format(__name__),
                ],
            },
        }
        with mock_iter_entry_points(error_entry_point):
            with self.assertLogs(LOGGER_NAME) as watcher:
                resources = get_responses()

        self.assertEqual(len(resources), 1)
        log_output, = watcher.output
        self.assertIn("Failed to load entry point", log_output)
Example #5
0
    def test_load_errored_entry_points(self):
        # entry points are contributed by other packages, and running them
        # may fail.
        error_entry_point = {
            "traitsui": {
                "etsdemo_data": [
                    "error_demo={}:misbehaving_demo_response".format(__name__),
                    "amazing_demo={}:amazing_demo_response".format(__name__),
                ],
            },
        }
        with mock_iter_entry_points(error_entry_point):
            with self.assertLogs(LOGGER_NAME) as watcher:
                resources = get_responses()

        self.assertEqual(len(resources), 1)
        log_output, = watcher.output
        self.assertIn("Failed to obtain data from", log_output)