コード例 #1
0
ファイル: test_testr.py プロジェクト: sapcc/rally
    def test_setup_with_concurrency_stestr(self):
        self.verifier.manager._use_testr = False
        # default behaviour
        cfg = {"verifier": self.verifier}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd([], cfg["testr_cmd"], stestr=True)
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 0}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd([], cfg["testr_cmd"], stestr=True)

        # serial mode
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 1}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--serial"], cfg["testr_cmd"], stestr=True)

        # parallel mode
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 2}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--concurrency", "2"],
                            cfg["testr_cmd"],
                            stestr=True)
コード例 #2
0
ファイル: test_testr.py プロジェクト: sapcc/rally
    def test_setup_with_skip_and_load_lists(self, mock_generate_random_path):
        # with load_list, but without skip_list
        load_list = ["tests.foo", "tests.bar"]
        cfg = {"verifier": self.verifier, "run_args": {"load_list": load_list}}
        ctx = testr.TestrContext(cfg)
        mock_open = mock.mock_open()
        with mock.patch("%s.open" % PATH, mock_open):
            ctx.setup()
        mock_open.assert_called_once_with(
            mock_generate_random_path.return_value, "w")
        handle = mock_open.return_value
        handle.write.assert_called_once_with("\n".join(load_list))
        self.assertEqualCmd([
            "--parallel", "--load-list", mock_generate_random_path.return_value
        ], cfg["testr_cmd"])
        self.assertFalse(self.verifier.manager.list_tests.called)

        # with load_list and skip_list
        load_list = ["tests.foo", "tests.bar"]
        skip_list = {"tests.foo": "skip reason"}
        cfg = {
            "verifier": self.verifier,
            "run_args": {
                "load_list": load_list,
                "skip_list": skip_list
            }
        }
        ctx = testr.TestrContext(cfg)
        mock_open = mock.mock_open()
        with mock.patch("%s.open" % PATH, mock_open):
            ctx.setup()
        mock_open.assert_called_once_with(
            mock_generate_random_path.return_value, "w")
        handle = mock_open.return_value
        handle.write.assert_called_once_with(load_list[1])
        self.assertEqualCmd([
            "--parallel", "--load-list", mock_generate_random_path.return_value
        ], cfg["testr_cmd"])
        self.assertFalse(self.verifier.manager.list_tests.called)

        # with skip_list, but without load_list
        load_list = ["tests.foo", "tests.bar"]
        self.verifier.manager.list_tests.return_value = load_list
        skip_list = {"tests.foo": "skip reason"}
        cfg = {"verifier": self.verifier, "run_args": {"skip_list": skip_list}}
        ctx = testr.TestrContext(cfg)
        mock_open = mock.mock_open()
        with mock.patch("%s.open" % PATH, mock_open):
            ctx.setup()
        mock_open.assert_called_once_with(
            mock_generate_random_path.return_value, "w")
        handle = mock_open.return_value
        handle.write.assert_called_once_with(load_list[1])
        self.assertEqualCmd([
            "--parallel", "--load-list", mock_generate_random_path.return_value
        ], cfg["testr_cmd"])
        self.verifier.manager.list_tests.assert_called_once_with()
コード例 #3
0
ファイル: test_testr.py プロジェクト: sapcc/rally
    def test_setup_with_concurrency(self):
        # default behaviour
        cfg = {"verifier": self.verifier}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--parallel"], cfg["testr_cmd"])
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 0}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--parallel"], cfg["testr_cmd"])

        # serial mode
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 1}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--concurrency", "1"], cfg["testr_cmd"])

        # parallel mode
        cfg = {"verifier": self.verifier, "run_args": {"concurrency": 2}}
        ctx = testr.TestrContext(cfg)
        ctx.setup()
        self.assertEqualCmd(["--parallel", "--concurrency", "2"],
                            cfg["testr_cmd"])
コード例 #4
0
ファイル: test_testr.py プロジェクト: sapcc/rally
 def test_skip_list_with_regex_positive_match(self,
                                              mock_generate_random_path):
     # using a regex in skip_list
     load_list = ["tests.foo.bar", "tests.bar"]
     self.verifier.manager.list_tests.return_value = load_list
     skip_list = {"^tests.foo": "skip reason"}
     cfg = {"verifier": self.verifier, "run_args": {"skip_list": skip_list}}
     ctx = testr.TestrContext(cfg)
     mock_open = mock.mock_open()
     with mock.patch("%s.open" % PATH, mock_open):
         ctx.setup()
     mock_open.assert_called_once_with(
         mock_generate_random_path.return_value, "w")
     handle = mock_open.return_value
     handle.write.assert_called_once_with(load_list[1])
     self.assertEqualCmd([
         "--parallel", "--load-list", mock_generate_random_path.return_value
     ], cfg["testr_cmd"])
     self.verifier.manager.list_tests.assert_called_once_with()
コード例 #5
0
ファイル: test_testr.py プロジェクト: sapcc/rally
 def test_skip_list_with_invalid_regex(self, mock_generate_random_path):
     load_list = [
         "tests.foo[e3976dea-bed9-4b14-abaf-59372de9303]", "tests.bar"
     ]
     self.verifier.manager.list_tests.return_value = load_list
     skip_list = {
         "tests.foo[e3976dea-bed9-4b14-abaf-59372de9303]": "skip reason"
     }
     cfg = {"verifier": self.verifier, "run_args": {"skip_list": skip_list}}
     ctx = testr.TestrContext(cfg)
     mock_open = mock.mock_open()
     with mock.patch("%s.open" % PATH, mock_open):
         ctx.setup()
     mock_open.assert_called_once_with(
         mock_generate_random_path.return_value, "w")
     handle = mock_open.return_value
     handle.write.assert_called_once_with(load_list[1])
     self.assertEqualCmd([
         "--parallel", "--load-list", mock_generate_random_path.return_value
     ], cfg["testr_cmd"])
     self.verifier.manager.list_tests.assert_called_once_with()
コード例 #6
0
ファイル: test_testr.py プロジェクト: sapcc/rally
    def test_cleanup(self, mock_exists, mock_remove):
        files = {
            "/path/foo_1": True,
            "/path/bar_1": False,
            "/path/foo_2": False,
            "/path/bar_2": True
        }

        def fake_exists(path):
            return files.get(path, False)

        mock_exists.side_effect = fake_exists

        ctx = testr.TestrContext({"verifier": self.verifier})
        ctx._tmp_files = files.keys()

        ctx.cleanup()

        self.assertEqual([mock.call(f) for f in files.keys()],
                         mock_exists.call_args_list)
        self.assertEqual([mock.call(f) for f in files.keys() if files[f]],
                         mock_remove.call_args_list)
コード例 #7
0
ファイル: test_testr.py プロジェクト: sapcc/rally
 def test_setup_with_pattern(self):
     cfg = {"verifier": self.verifier, "run_args": {"pattern": "foo"}}
     ctx = testr.TestrContext(cfg)
     ctx.setup()
     self.assertEqualCmd(["--parallel", "foo"], cfg["testr_cmd"])
コード例 #8
0
ファイル: test_testr.py プロジェクト: sapcc/rally
 def test_setup_with_failing(self):
     cfg = {"verifier": self.verifier, "run_args": {"failed": True}}
     ctx = testr.TestrContext(cfg)
     ctx.setup()
     self.assertEqualCmd(["--parallel", "--failing"], cfg["testr_cmd"])