From 99cc4d767abe4a3fe4bb9dc173cbc98c9cd892c3 Mon Sep 17 00:00:00 2001 From: gmega Date: Thu, 19 Dec 2024 21:19:16 -0300 Subject: [PATCH] chore: run formatter --- benchmarks/k8s/parameter_expander.py | 29 ++++++++++-------- .../k8s/tests/test_parameter_expander.py | 30 +++++-------------- 2 files changed, 24 insertions(+), 35 deletions(-) diff --git a/benchmarks/k8s/parameter_expander.py b/benchmarks/k8s/parameter_expander.py index 59968d1..1c3b175 100644 --- a/benchmarks/k8s/parameter_expander.py +++ b/benchmarks/k8s/parameter_expander.py @@ -23,8 +23,10 @@ def expand(parameters: Dict[str, Any], run_id: bool = False) -> List[Dict[str, A expanded_items = _expand_simple(simple) else: expanded_items = [ - simple + constrained for simple, constrained in - itertools.product(_expand_simple(simple), _expand_constrained(constrained)) + simple + constrained + for simple, constrained in itertools.product( + _expand_simple(simple), _expand_constrained(constrained) + ) ] final_expansion = [dict(item, **fixed) for item in expanded_items] @@ -36,7 +38,9 @@ def expand(parameters: Dict[str, Any], run_id: bool = False) -> List[Dict[str, A return final_expansion -def _expand_simple(expandable: Dict[str, List[Any]]) -> List[List[Tuple[str, List[Any]]]]: +def _expand_simple( + expandable: Dict[str, List[Any]], +) -> List[List[Tuple[str, List[Any]]]]: keys = expandable.keys() return [ list(zip(keys, list(value_set))) @@ -44,7 +48,9 @@ def _expand_simple(expandable: Dict[str, List[Any]]) -> List[List[Tuple[str, Lis ] -def _expand_constrained(constrained: Dict[str, List[Any]]) -> List[List[Tuple[str, List[Any]]]]: +def _expand_constrained( + constrained: Dict[str, List[Any]], +) -> List[List[Tuple[str, List[Any]]]]: return [ expansion for k, v in constrained.items() @@ -52,11 +58,12 @@ def _expand_constrained(constrained: Dict[str, List[Any]]) -> List[List[Tuple[st ] -def _expand_single_constraint(combined_key: str, - values: List[List[Any]]) -> List[List[Tuple[str, List[Any]]]]: - keys = combined_key[len('constrained__'):].split('_') +def _expand_single_constraint( + combined_key: str, values: List[List[Any]] +) -> List[List[Tuple[str, List[Any]]]]: + keys = combined_key[len("constrained__") :].split("_") if len(keys) < 2: - raise ValueError(f'Invalid combined key {combined_key}') + raise ValueError(f"Invalid combined key {combined_key}") normalized_values = [_normalize_values(value_set) for value_set in values] @@ -68,10 +75,7 @@ def _expand_single_constraint(combined_key: str, def _normalize_values(values: List[Any | List[Any]]) -> List[List[Any]]: - return [ - value if isinstance(value, list) else [value] - for value in values - ] + return [value if isinstance(value, list) else [value] for value in values] def normalize_argo_params(argo_params: List[Dict[str, Any]]) -> Dict[str, Any]: @@ -85,7 +89,6 @@ def normalize_argo_params(argo_params: List[Dict[str, Any]]) -> Dict[str, Any]: if __name__ == "__main__": - if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} ''") sys.exit(1) diff --git a/benchmarks/k8s/tests/test_parameter_expander.py b/benchmarks/k8s/tests/test_parameter_expander.py index e688eb8..d9926d4 100644 --- a/benchmarks/k8s/tests/test_parameter_expander.py +++ b/benchmarks/k8s/tests/test_parameter_expander.py @@ -5,12 +5,7 @@ from benchmarks.k8s.parameter_expander import normalize_argo_params def test_should_expand_simple_parameter_lists(): - matrix = { - "a": [1, 2], - "b": [3, 4], - "c": "foo", - "d": 5 - } + matrix = {"a": [1, 2], "b": [3, 4], "c": "foo", "d": 5} assert expander.expand(matrix) == [ {"a": 1, "b": 3, "c": "foo", "d": 5}, @@ -21,12 +16,7 @@ def test_should_expand_simple_parameter_lists(): def test_should_add_run_id_when_requested(): - matrix = { - "a": [1, 2], - "b": [3, 4], - "c": "foo", - "d": 5 - } + matrix = {"a": [1, 2], "b": [3, 4], "c": "foo", "d": 5} assert expander.expand(matrix, run_id=True) == [ {"a": 1, "b": 3, "c": "foo", "d": 5, "runId": 1}, @@ -37,13 +27,7 @@ def test_should_add_run_id_when_requested(): def test_should_expand_constrained_parameter_pairs(): - matrix = { - "constrained__att1_att2": [ - [1, [2, 3]], - [[4, 5], 6] - ], - "b": [1, 2] - } + matrix = {"constrained__att1_att2": [[1, [2, 3]], [[4, 5], 6]], "b": [1, 2]} assert expander.expand(matrix) == [ {"att1": 1, "att2": 2, "b": 1}, @@ -58,9 +42,11 @@ def test_should_expand_constrained_parameter_pairs(): def test_should_normalize_simple_argo_parameter_list(): - argo_params = json.loads('[{"name":"repetitions","value":"1"},{"name":"fileSize","value":"100MB"},' - '{"name":"networkSize","value":"5"},{"name":"seeders","value":"1"},' - '{"name":"seederSets","value":"1"},{"name":"maxExperimentDuration","value":"72h"}]') + argo_params = json.loads( + '[{"name":"repetitions","value":"1"},{"name":"fileSize","value":"100MB"},' + '{"name":"networkSize","value":"5"},{"name":"seeders","value":"1"},' + '{"name":"seederSets","value":"1"},{"name":"maxExperimentDuration","value":"72h"}]' + ) assert normalize_argo_params(argo_params) == { "repetitions": 1,