Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
favilo committed Jun 21, 2024
1 parent ddf85c1 commit ab8cf43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion esrally/mechanic/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def list_cars(cfg: types.Config):
console.println(tabulate.tabulate([[c.name, c.type, c.description] for c in cars], headers=["Name", "Type", "Description"]))


def load_car(repo, name, car_params=None):
def load_car(repo: str, name: Collection[str], car_params: Mapping=None) -> "Car":
class Component:
def __init__(self, root_path, entry_point):
self.root_path = root_path
Expand Down
2 changes: 1 addition & 1 deletion esrally/utils/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def can_load(self):
"""
:return: True iff the component entry point could be found.
"""
return self.root_path and all(
return all(self.root_path) and all(
os.path.exists(os.path.join(root_path, "%s.py" % self.component_entry_point)) for root_path in self.root_path
)

Expand Down
2 changes: 1 addition & 1 deletion tests/mechanic/provisioner_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def null_apply_config(source_root_path, target_root_path, config_vars):
installer = provisioner.ElasticsearchInstaller(
car=team.Car(
names="unit-test-car",
root_path=None,
root_path=None, # type: ignore
config_paths=[HOME_DIR + "/.rally/benchmarks/teams/default/my-car"],
variables={
"heap": "4g",
Expand Down
28 changes: 13 additions & 15 deletions tests/mechanic/team_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def test_load_known_car(self):
car = team.load_car(self.team_dir, ["default"], car_params={"data_paths": ["/mnt/disk0", "/mnt/disk1"]})
assert car.name == "default"
assert car.config_paths == [os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates")]
assert car.root_path is None
assert car.root_path == []
assert car.variables == {"heap_size": "1g", "clean_command": "./gradlew clean", "data_paths": ["/mnt/disk0", "/mnt/disk1"]}
assert car.root_path is None
assert car.root_path == []

def test_load_car_with_mixin_single_config_base(self):
car = team.load_car(self.team_dir, ["32gheap", "ea"])
assert car.name == "32gheap+ea"
assert car.config_paths == [os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates")]
assert car.root_path is None
assert car.root_path == []
assert car.variables == {"heap_size": "32g", "clean_command": "./gradlew clean", "assertions": "true"}
assert car.root_path is None
assert car.root_path == []

def test_load_car_with_mixin_multiple_config_bases(self):
car = team.load_car(self.team_dir, ["32gheap", "ea", "verbose"])
Expand All @@ -67,7 +67,7 @@ def test_load_car_with_mixin_multiple_config_bases(self):
os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates"),
os.path.join(current_dir, "data", "cars", "v1", "verbose_logging", "templates"),
]
assert car.root_path is None
assert car.root_path == []
assert car.variables == {"heap_size": "32g", "clean_command": "./gradlew clean", "verbose_logging": "true", "assertions": "true"}

def test_load_car_with_install_hook(self):
Expand All @@ -77,7 +77,7 @@ def test_load_car_with_install_hook(self):
os.path.join(current_dir, "data", "cars", "v1", "vanilla", "templates"),
os.path.join(current_dir, "data", "cars", "v1", "with_hook", "templates"),
]
assert car.root_path == os.path.join(current_dir, "data", "cars", "v1", "with_hook")
assert car.root_path == [os.path.join(current_dir, "data", "cars", "v1", "with_hook")]
assert car.variables == {"heap_size": "1g", "clean_command": "./gradlew clean", "data_paths": ["/mnt/disk0", "/mnt/disk1"]}

def test_load_car_with_multiple_bases_referring_same_install_hook(self):
Expand All @@ -88,7 +88,7 @@ def test_load_car_with_multiple_bases_referring_same_install_hook(self):
os.path.join(current_dir, "data", "cars", "v1", "with_hook", "templates"),
os.path.join(current_dir, "data", "cars", "v1", "verbose_logging", "templates"),
]
assert car.root_path == os.path.join(current_dir, "data", "cars", "v1", "with_hook")
assert car.root_path == [os.path.join(current_dir, "data", "cars", "v1", "with_hook")]
assert car.variables == {"heap_size": "16g", "clean_command": "./gradlew clean", "verbose_logging": "true"}

def test_raises_error_on_unknown_car(self):
Expand All @@ -112,12 +112,10 @@ def test_raises_error_on_missing_config_base(self):
):
team.load_car(self.team_dir, ["missing_cfg_base"])

def test_raises_error_if_more_than_one_different_install_hook(self):
with pytest.raises(
exceptions.SystemSetupError,
match=r"Invalid car: \['multi_hook'\]. Multiple bootstrap hooks are forbidden.",
):
team.load_car(self.team_dir, ["multi_hook"])
def test_doesnt_raise_error_if_more_than_one_different_install_hook(self):
car = team.load_car(self.team_dir, ["multi_hook"])
assert isinstance(car.root_path, list)
assert len(car.root_path) == 2


class TestPluginLoader:
Expand Down Expand Up @@ -229,7 +227,7 @@ def test_loads_module(self):
hook = self.UnitTestHook()
handler = team.BootstrapHookHandler(plugin, loader_class=self.UnitTestComponentLoader)

handler.loader.registration_function = hook
handler.loader.registration_function = [hook]
handler.load()

handler.invoke("post_install", variables={"increment": 4})
Expand All @@ -242,7 +240,7 @@ def test_cannot_register_for_unknown_phase(self):
hook = self.UnitTestHook(phase="this_is_an_unknown_install_phase")
handler = team.BootstrapHookHandler(plugin, loader_class=self.UnitTestComponentLoader)

handler.loader.registration_function = hook
handler.loader.registration_function = [hook]
with pytest.raises(exceptions.SystemSetupError) as exc:
handler.load()
assert exc.value.args[0] == "Unknown bootstrap phase [this_is_an_unknown_install_phase]. Valid phases are: ['post_install']."

0 comments on commit ab8cf43

Please sign in to comment.