|
14 | 14 | validate_matrix_entry, |
15 | 15 | validate_master_config, |
16 | 16 | validate_runner_config, |
| 17 | + load_config_files, |
| 18 | + load_runner_file, |
17 | 19 | ) |
18 | 20 |
|
19 | 21 |
|
@@ -738,3 +740,130 @@ def test_multiple_runner_types(self, valid_runner_config): |
738 | 740 | assert "h200" in result |
739 | 741 | assert "mi300x" in result |
740 | 742 | assert "gb200" in result |
| 743 | + |
| 744 | + |
| 745 | +# ============================================================================= |
| 746 | +# Test load_config_files |
| 747 | +# ============================================================================= |
| 748 | + |
| 749 | +class TestLoadConfigFiles: |
| 750 | + """Tests for load_config_files function.""" |
| 751 | + |
| 752 | + def test_load_single_file_with_validation(self, tmp_path, valid_single_node_master_config): |
| 753 | + """Should load and validate a single config file.""" |
| 754 | + config_file = tmp_path / "config.yaml" |
| 755 | + import yaml |
| 756 | + config_file.write_text(yaml.dump({"test-config": valid_single_node_master_config})) |
| 757 | + result = load_config_files([str(config_file)]) |
| 758 | + assert "test-config" in result |
| 759 | + assert result["test-config"]["image"] == valid_single_node_master_config["image"] |
| 760 | + |
| 761 | + def test_load_single_file_without_validation(self, tmp_path): |
| 762 | + """Should load a single config file without validation when validate=False.""" |
| 763 | + config_file = tmp_path / "config.yaml" |
| 764 | + config_file.write_text(""" |
| 765 | +test-config: |
| 766 | + image: test-image |
| 767 | + model: test-model |
| 768 | +""") |
| 769 | + result = load_config_files([str(config_file)], validate=False) |
| 770 | + assert "test-config" in result |
| 771 | + assert result["test-config"]["image"] == "test-image" |
| 772 | + |
| 773 | + def test_load_multiple_files(self, tmp_path): |
| 774 | + """Should merge multiple config files.""" |
| 775 | + config1 = tmp_path / "config1.yaml" |
| 776 | + config1.write_text(""" |
| 777 | +config-one: |
| 778 | + value: 1 |
| 779 | +""") |
| 780 | + config2 = tmp_path / "config2.yaml" |
| 781 | + config2.write_text(""" |
| 782 | +config-two: |
| 783 | + value: 2 |
| 784 | +""") |
| 785 | + result = load_config_files([str(config1), str(config2)], validate=False) |
| 786 | + assert "config-one" in result |
| 787 | + assert "config-two" in result |
| 788 | + |
| 789 | + def test_duplicate_keys_raise_error(self, tmp_path): |
| 790 | + """Duplicate keys across files should raise error.""" |
| 791 | + config1 = tmp_path / "config1.yaml" |
| 792 | + config1.write_text(""" |
| 793 | +duplicate-key: |
| 794 | + value: 1 |
| 795 | +""") |
| 796 | + config2 = tmp_path / "config2.yaml" |
| 797 | + config2.write_text(""" |
| 798 | +duplicate-key: |
| 799 | + value: 2 |
| 800 | +""") |
| 801 | + with pytest.raises(ValueError) as exc_info: |
| 802 | + load_config_files([str(config1), str(config2)], validate=False) |
| 803 | + assert "Duplicate configuration keys" in str(exc_info.value) |
| 804 | + |
| 805 | + def test_nonexistent_file_raises_error(self): |
| 806 | + """Nonexistent file should raise error.""" |
| 807 | + with pytest.raises(ValueError) as exc_info: |
| 808 | + load_config_files(["nonexistent.yaml"]) |
| 809 | + assert "does not exist" in str(exc_info.value) |
| 810 | + |
| 811 | + def test_validation_runs_by_default(self, tmp_path): |
| 812 | + """Validation should run by default and catch invalid configs.""" |
| 813 | + config_file = tmp_path / "config.yaml" |
| 814 | + config_file.write_text(""" |
| 815 | +invalid-config: |
| 816 | + image: test-image |
| 817 | + # Missing required fields like model, model-prefix, precision, etc. |
| 818 | +""") |
| 819 | + with pytest.raises(ValueError) as exc_info: |
| 820 | + load_config_files([str(config_file)]) |
| 821 | + assert "failed validation" in str(exc_info.value) |
| 822 | + |
| 823 | + |
| 824 | +# ============================================================================= |
| 825 | +# Test load_runner_file |
| 826 | +# ============================================================================= |
| 827 | + |
| 828 | +class TestLoadRunnerFile: |
| 829 | + """Tests for load_runner_file function.""" |
| 830 | + |
| 831 | + def test_load_runner_file_with_validation(self, tmp_path): |
| 832 | + """Should load and validate runner config file.""" |
| 833 | + runner_file = tmp_path / "runners.yaml" |
| 834 | + runner_file.write_text(""" |
| 835 | +h100: |
| 836 | +- h100-node-0 |
| 837 | +- h100-node-1 |
| 838 | +""") |
| 839 | + result = load_runner_file(str(runner_file)) |
| 840 | + assert "h100" in result |
| 841 | + assert len(result["h100"]) == 2 |
| 842 | + |
| 843 | + def test_load_runner_file_without_validation(self, tmp_path): |
| 844 | + """Should load runner config file without validation when validate=False.""" |
| 845 | + runner_file = tmp_path / "runners.yaml" |
| 846 | + runner_file.write_text(""" |
| 847 | +h100: |
| 848 | +- h100-node-0 |
| 849 | +- h100-node-1 |
| 850 | +""") |
| 851 | + result = load_runner_file(str(runner_file), validate=False) |
| 852 | + assert "h100" in result |
| 853 | + assert len(result["h100"]) == 2 |
| 854 | + |
| 855 | + def test_nonexistent_runner_file(self): |
| 856 | + """Nonexistent runner file should raise error.""" |
| 857 | + with pytest.raises(ValueError) as exc_info: |
| 858 | + load_runner_file("nonexistent.yaml") |
| 859 | + assert "does not exist" in str(exc_info.value) |
| 860 | + |
| 861 | + def test_validation_runs_by_default(self, tmp_path): |
| 862 | + """Validation should run by default and catch invalid configs.""" |
| 863 | + runner_file = tmp_path / "runners.yaml" |
| 864 | + runner_file.write_text(""" |
| 865 | +h100: not-a-list |
| 866 | +""") |
| 867 | + with pytest.raises(ValueError) as exc_info: |
| 868 | + load_runner_file(str(runner_file)) |
| 869 | + assert "must be a list" in str(exc_info.value) |
0 commit comments