Esempio n. 1
0
    def test_run_tests_calls_utility_functions(self):
        """The run_tests method must call all the utility functions.

        This test is somewhat ugly, and relies on a lot of mocks. This will be
        cleaned up once run has been completely refactored.

        """
        fake_args = create_default_run_args()
        program = run.TestProgram(fake_args)
        mock_test_result = Mock()
        mock_test_result.wasSuccessful.return_value = True
        mock_test_suite = Mock()
        mock_test_suite.run.return_value = mock_test_result
        mock_construct_test_result = Mock()
        with ExitStack() as stack:
            load_tests = stack.enter_context(
                patch.object(run, 'load_test_suite_from_name'))
            fake_construct = stack.enter_context(
                patch.object(run, 'construct_test_result'))
            configure_debug = stack.enter_context(
                patch.object(run, '_configure_debug_profile'))
            config_timeout = stack.enter_context(
                patch.object(run, '_configure_timeout_profile'))
            config_test_timeout = stack.enter_context(
                patch.object(run, '_configure_test_timeout'))

            load_tests.return_value = (mock_test_suite, False)
            fake_construct.return_value = mock_construct_test_result
            program.run()

            config_timeout.assert_called_once_with(fake_args)
            configure_debug.assert_called_once_with(fake_args)
            config_test_timeout.assert_called_once_with(fake_args)
            fake_construct.assert_called_once_with(fake_args)
            load_tests.assert_called_once_with(fake_args.suite)
Esempio n. 2
0
    def test_list_command_calls_list_tests_method(self):
        fake_args = Namespace(mode='list')
        program = run.TestProgram(fake_args)
        with patch.object(program, 'list_tests') as patched_list_tests:
            program.run()

            patched_list_tests.assert_called_once_with()
Esempio n. 3
0
    def test_launch_command_calls_launch_app_method(self):
        fake_args = Namespace(mode='launch')
        program = run.TestProgram(fake_args)
        with patch.object(program, 'launch_app') as patched_launch_app:
            program.run()

            patched_launch_app.assert_called_once_with()
Esempio n. 4
0
    def test_vis_command_calls_run_vis_method(self):
        fake_args = Namespace(mode='vis')
        program = run.TestProgram(fake_args)
        with patch.object(program, 'run_vis') as patched_run_vis:
            program.run()

            patched_run_vis.assert_called_once_with()
Esempio n. 5
0
    def test_run_logs_autopilot_version(self):
        with patch.object(run, 'log_autopilot_version') as log_version:
            fake_args = Namespace(mode=None)
            program = run.TestProgram(fake_args)
            program.run()

            log_version.assert_called_once_with()
Esempio n. 6
0
    def test_run_calls_setup_logging_with_verbose_arg(self):
        fake_args = Namespace(verbose=1, mode='')
        program = run.TestProgram(fake_args)
        with patch.object(run, 'setup_logging') as patched_setup_logging:
            program.run()

            patched_setup_logging.assert_called_once_with(True)
Esempio n. 7
0
    def test_calls_parse_args_by_default(self):
        fake_args = Namespace()
        with patch.object(run, '_parse_arguments') as fake_parse_args:
            fake_parse_args.return_value = fake_args
            program = run.TestProgram()

            fake_parse_args.assert_called_once_with()
            self.assertThat(program.args, Equals(fake_args))
Esempio n. 8
0
    def test_passes_empty_list_without_testability_set(self, patched_vis_main):
        args = Namespace(
            mode='vis',
            testability=False,
            enable_profile=False,
        )
        program = run.TestProgram(args)
        program.run()

        patched_vis_main.assert_called_once_with([])
Esempio n. 9
0
    def test_passes_testability_to_vis_main(self, patched_vis_main):
        args = Namespace(
            mode='vis',
            testability=True,
            enable_profile=False,
        )
        program = run.TestProgram(args)
        program.run()

        patched_vis_main.assert_called_once_with(['-testability'])
Esempio n. 10
0
    def test_vis_command_runs_under_profiling_if_profiling_is_enabled(self):
        fake_args = Namespace(
            mode='vis',
            enable_profile=True,
            testability=False,
        )
        program = run.TestProgram(fake_args)
        with patch.object(run, '_run_with_profiling') as patched_run_profile:
            program.run()

            self.assertThat(
                patched_run_profile.call_count,
                Equals(1),
            )
Esempio n. 11
0
    def test_launch_app_launches_app_with_arguments(self, patched_launch_proc):
        app_name = self.getUniqueString()
        app_arguments = self.getUniqueString()
        fake_args = Namespace(mode='launch',
                              application=[app_name, app_arguments],
                              interface=None)

        with patch.object(run,
                          '_prepare_application_for_launch',
                          return_value=(app_name, app_arguments)):
            program = run.TestProgram(fake_args)
            program.run()
            patched_launch_proc.assert_called_once_with(app_name,
                                                        app_arguments,
                                                        capture_output=False)
Esempio n. 12
0
    def test_launch_app_exits_using_print_message_and_exit_error(self):
        app_name = self.getUniqueString()
        app_arguments = self.getUniqueString()
        error_message = "Cannot find application 'blah'"
        fake_args = Namespace(mode='launch',
                              application=[app_name, app_arguments],
                              interface=None)

        with patch.object(run,
                          '_prepare_application_for_launch',
                          side_effect=RuntimeError(error_message)):
            with patch.object(
                    run, '_print_message_and_exit_error') as print_and_exit:
                run.TestProgram(fake_args).run()
                print_and_exit.assert_called_once_with("Error: %s" %
                                                       error_message)
Esempio n. 13
0
    def test_launch_app_exits_with_message_on_failure(
            self, patched_launch_proc):  # NOQA
        app_name = self.getUniqueString()
        app_arguments = self.getUniqueString()
        fake_args = Namespace(mode='launch',
                              application=[app_name, app_arguments],
                              interface=None)

        with patch.object(run,
                          '_prepare_application_for_launch',
                          return_value=(app_name, app_arguments)):
            with patch('sys.stdout', new=StringIO()) as stdout:
                patched_launch_proc.side_effect = RuntimeError(
                    "Failure Message")
                program = run.TestProgram(fake_args)
                self.assertThat(lambda: program.run(), raises(SystemExit(1)))
                self.assertThat(stdout.getvalue(),
                                Contains("Error: Failure Message"))
Esempio n. 14
0
 def test_dont_run_when_zero_tests_loaded(self):
     fake_args = create_default_run_args()
     program = run.TestProgram(fake_args)
     with patch('sys.stdout', new=StringIO()):
         self.assertRaisesRegexp(RuntimeError, 'Did not find any tests',
                                 program.run)
Esempio n. 15
0
    def test_can_provide_args(self):
        fake_args = Namespace()
        program = run.TestProgram(fake_args)

        self.assertThat(program.args, Equals(fake_args))