Ejemplo n.º 1
0
    def test_install(self, mock_verifier_manager_install):
        launcher = testr.TestrLauncher(mock.Mock())
        launcher._init_testr = mock.Mock()

        launcher.install()

        mock_verifier_manager_install.assert_called_once_with()
        launcher._init_testr.assert_called_once_with()
Ejemplo n.º 2
0
    def test__init_testr(self, mock_isdir, mock_exists, mock_check_output,
                         mock_rmtree):
        launcher = testr.TestrLauncher(mock.Mock())
        mock_exists.assert_called_once_with(
            os.path.join(launcher.repo_dir, ".testr.conf"))
        mock_exists.reset_mock()

        # case #1: testr already initialized
        mock_isdir.return_value = True

        launcher._init_testr()

        self.assertFalse(mock_check_output.called)
        self.assertFalse(mock_exists.called)
        self.assertFalse(mock_rmtree.called)

        # case #2: initializing testr without errors
        mock_isdir.return_value = False

        launcher._init_testr()

        mock_check_output.assert_called_once_with(["testr", "init"],
                                                  cwd=launcher.repo_dir,
                                                  env=launcher.environ)
        self.assertFalse(mock_exists.called)
        self.assertFalse(mock_rmtree.called)
        mock_check_output.reset_mock()

        # case #3: initializing stestr without errors
        launcher._use_testr = False

        launcher._init_testr()

        mock_check_output.assert_called_once_with(["stestr", "init"],
                                                  cwd=launcher.repo_dir,
                                                  env=launcher.environ)
        self.assertFalse(mock_exists.called)
        self.assertFalse(mock_rmtree.called)
        mock_check_output.reset_mock()

        # case #4: initializing testr with error
        mock_check_output.side_effect = OSError
        test_repository_dir = os.path.join(launcher.base_dir,
                                           ".testrepository")

        self.assertRaises(exceptions.RallyException, launcher._init_testr)

        mock_check_output.assert_called_once_with(["stestr", "init"],
                                                  cwd=launcher.repo_dir,
                                                  env=launcher.environ)
        mock_exists.assert_called_once_with(test_repository_dir)
        mock_rmtree.assert_called_once_with(test_repository_dir)
Ejemplo n.º 3
0
    def test_run_exclude(self, mock_popen, mock_parse):
        launcher = testr.TestrLauncher(mock.Mock())
        xfail_list = {"test1": "reason1"}
        ctx = {
            "testr_cmd": ["ls", "-la"],
            "xfail_list": xfail_list,
            "skip_list": None
        }
        launcher = testr.TestrLauncher(mock.Mock())

        result = launcher.run(ctx)
        self.assertEqual(mock_parse.return_value, result)

        mock_popen.assert_called_once_with(ctx["testr_cmd"],
                                           env=launcher.run_environ,
                                           cwd=launcher.repo_dir,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.STDOUT)
        mock_popen.return_value.wait.assert_called_once_with()
        mock_parse.assert_called_once_with(mock_popen.return_value.stdout,
                                           live=True,
                                           expected_failures=xfail_list,
                                           skipped_tests=None,
                                           logger_name=launcher.verifier.name)
Ejemplo n.º 4
0
    def test_list_tests_via_testr(self, mock_check_output):
        mock_check_output.return_value = (
            "logging message\n"  # should be ignored
            "one more useless data\n"  # should be ignored
            "tests.FooTestCase.test_something\n"  # valid
            "tests.FooTestCase.test_another[\n"  # invalid
            "tests.BarTestCase.test_another[id=123]\n"  # valid
            "tests.FooTestCase.test_another[id=a2-213,smoke]\n"  # valid
        )
        verifier = mock.Mock()

        launcher = testr.TestrLauncher(verifier)
        launcher._use_testr = True

        self.assertEqual([
            "tests.FooTestCase.test_something",
            "tests.BarTestCase.test_another[id=123]",
            "tests.FooTestCase.test_another[id=a2-213,smoke]"
        ], launcher.list_tests())

        mock_check_output.assert_called_once_with(["testr", "list-tests", ""],
                                                  cwd=launcher.repo_dir,
                                                  env=launcher.environ,
                                                  debug_output=False)