|
11 | 11 |
|
12 | 12 | ARRAY_OPTIONS = [o for o, t in RESERVED_OPTIONS.items() if t is list] |
13 | 13 | BOOLEAN_OPTIONS = [o for o, t in RESERVED_OPTIONS.items() if t is bool] |
14 | | -MAPPING_OPTIONS = [o for o, t in RESERVED_OPTIONS.items() if t is dict] |
| 14 | +MAPPING_OPTIONS = [o for o, t in RESERVED_OPTIONS.items() if t is dict and o != "workspace"] |
15 | 15 | STRING_OPTIONS = [o for o, t in RESERVED_OPTIONS.items() if t is str and o != "matrix-name-format"] |
| 16 | +WORKSPACE_OPTIONS = ["workspace"] # Workspace has nested structure, tested separately |
16 | 17 |
|
17 | 18 |
|
18 | 19 | def construct_matrix_data(env_name, config, overrides=None): |
@@ -2570,6 +2571,99 @@ def finalize_environments(self, config): |
2570 | 2571 | assert project_config.envs == expected_envs |
2571 | 2572 | assert project_config.matrices["foo"] == construct_matrix_data("foo", env_config) |
2572 | 2573 |
|
| 2574 | + @pytest.mark.parametrize("option", WORKSPACE_OPTIONS) |
| 2575 | + def test_overrides_matrix_workspace_invalid_type(self, isolation, option): |
| 2576 | + with pytest.raises( |
| 2577 | + TypeError, |
| 2578 | + match=f"Field `tool.hatch.envs.foo.overrides.matrix.version.{option}` must be a table", |
| 2579 | + ): |
| 2580 | + _ = ProjectConfig( |
| 2581 | + isolation, |
| 2582 | + { |
| 2583 | + "envs": { |
| 2584 | + "foo": {"matrix": [{"version": ["9000"]}], "overrides": {"matrix": {"version": {option: 9000}}}} |
| 2585 | + } |
| 2586 | + }, |
| 2587 | + PluginManager(), |
| 2588 | + ).envs |
| 2589 | + |
| 2590 | + @pytest.mark.parametrize("option", WORKSPACE_OPTIONS) |
| 2591 | + def test_overrides_matrix_workspace_members_append(self, isolation, option): |
| 2592 | + env_config = { |
| 2593 | + "foo": { |
| 2594 | + option: {"members": ["packages/core"]}, |
| 2595 | + "matrix": [{"version": ["9000"]}, {"feature": ["bar"]}], |
| 2596 | + "overrides": {"matrix": {"version": {option: {"members": ["packages/extra"]}}}}, |
| 2597 | + } |
| 2598 | + } |
| 2599 | + project_config = ProjectConfig(isolation, {"envs": env_config}, PluginManager()) |
| 2600 | + |
| 2601 | + expected_envs = { |
| 2602 | + "default": {"type": "virtual"}, |
| 2603 | + "foo.9000": {"type": "virtual", option: {"members": ["packages/core", "packages/extra"]}}, |
| 2604 | + "foo.bar": {"type": "virtual", option: {"members": ["packages/core"]}}, |
| 2605 | + } |
| 2606 | + |
| 2607 | + assert project_config.envs == expected_envs |
| 2608 | + |
| 2609 | + @pytest.mark.parametrize("option", WORKSPACE_OPTIONS) |
| 2610 | + def test_overrides_matrix_workspace_members_conditional(self, isolation, option): |
| 2611 | + env_config = { |
| 2612 | + "foo": { |
| 2613 | + option: {"members": ["packages/core"]}, |
| 2614 | + "matrix": [{"version": ["9000", "42"]}], |
| 2615 | + "overrides": { |
| 2616 | + "matrix": {"version": {option: {"members": [{"value": "packages/special", "if": ["42"]}]}}} |
| 2617 | + }, |
| 2618 | + } |
| 2619 | + } |
| 2620 | + project_config = ProjectConfig(isolation, {"envs": env_config}, PluginManager()) |
| 2621 | + |
| 2622 | + expected_envs = { |
| 2623 | + "default": {"type": "virtual"}, |
| 2624 | + "foo.9000": {"type": "virtual", option: {"members": ["packages/core"]}}, |
| 2625 | + "foo.42": {"type": "virtual", option: {"members": ["packages/core", "packages/special"]}}, |
| 2626 | + } |
| 2627 | + |
| 2628 | + assert project_config.envs == expected_envs |
| 2629 | + |
| 2630 | + @pytest.mark.parametrize("option", WORKSPACE_OPTIONS) |
| 2631 | + def test_overrides_matrix_workspace_parallel(self, isolation, option): |
| 2632 | + env_config = { |
| 2633 | + "foo": { |
| 2634 | + option: {"members": ["packages/*"], "parallel": True}, |
| 2635 | + "matrix": [{"version": ["9000", "42"]}], |
| 2636 | + "overrides": {"matrix": {"version": {option: {"parallel": {"value": False, "if": ["42"]}}}}}, |
| 2637 | + } |
| 2638 | + } |
| 2639 | + project_config = ProjectConfig(isolation, {"envs": env_config}, PluginManager()) |
| 2640 | + |
| 2641 | + expected_envs = { |
| 2642 | + "default": {"type": "virtual"}, |
| 2643 | + "foo.9000": {"type": "virtual", option: {"members": ["packages/*"], "parallel": True}}, |
| 2644 | + "foo.42": {"type": "virtual", option: {"members": ["packages/*"], "parallel": False}}, |
| 2645 | + } |
| 2646 | + |
| 2647 | + assert project_config.envs == expected_envs |
| 2648 | + |
| 2649 | + @pytest.mark.parametrize("option", WORKSPACE_OPTIONS) |
| 2650 | + def test_overrides_matrix_workspace_overwrite(self, isolation, option): |
| 2651 | + env_config = { |
| 2652 | + "foo": { |
| 2653 | + option: {"members": ["packages/core"], "parallel": True}, |
| 2654 | + "matrix": [{"version": ["9000"]}], |
| 2655 | + "overrides": {"matrix": {"version": {f"set-{option}": {"members": ["packages/new"]}}}}, |
| 2656 | + } |
| 2657 | + } |
| 2658 | + project_config = ProjectConfig(isolation, {"envs": env_config}, PluginManager()) |
| 2659 | + |
| 2660 | + expected_envs = { |
| 2661 | + "default": {"type": "virtual"}, |
| 2662 | + "foo.9000": {"type": "virtual", option: {"members": ["packages/new"]}}, |
| 2663 | + } |
| 2664 | + |
| 2665 | + assert project_config.envs == expected_envs |
| 2666 | + |
2573 | 2667 |
|
2574 | 2668 | class TestPublish: |
2575 | 2669 | def test_not_table(self, isolation): |
|
0 commit comments