def test_unused_param(): template_str = "$test_param" experiment_str = """ { variants: [[{ test_param: [1], test_param_2: [2], }]] }""" with pytest.raises(ValueError) as excinfo: create_experiment_yaml_strings([experiment_str], template_str) assert excinfo.value.message == "Unused parameters: ['test_param_2']"
def test_missing_param(): ## Failing missing param template_str = "$test_param" experiment_str = """ { variants: [[{ test_param_2: [2], }]] }""" with pytest.raises(KeyError) as excinfo: create_experiment_yaml_strings([experiment_str], template_str) assert excinfo.value.message == 'test_param'
def test_cycle_in_param_template_logic(): template_str = "$test_param" experiment_str = """ { templates: { test_template: $test_param_2, }, variants: [[{ test_param: [1], test_param_2: [$test_template], }]] }""" with pytest.raises(ValueError) as excinfo: create_experiment_yaml_strings([experiment_str], template_str) assert excinfo.value.message == "Could not replace all templates"
def test_param_in_unused_nested_template(): template_str = "" experiment_str = """ { templates: { top_template: $test_template, test_template: $test_param_2, }, variants: [[{ test_param: [$top_template], test_param_2: [2], ignore_unused: [['test_param']], }]] }""" with pytest.raises(ValueError) as excinfo: create_experiment_yaml_strings([experiment_str], template_str) assert excinfo.value.message == "Unused parameters: ['test_param_2']"
def test_single_param(): template_str = "$test_param" experiment_str = """ { variants: [[{ test_param: [1], }]] }""" all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs[0] == "1"
def test_ignore_unused_param(): template_str = "$test_param" experiment_str = """ { variants: [[{ test_param: [1], test_param_2: [2], ignore_unused: [['test_param_2']], }]] }""" all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs[0] == '1'
def test_param_used_in_template(): template_str = "$the_template" experiment_str = """ { templates: { test_template: $test_param, }, variants: [[{ test_param: [1], the_template: [$test_template] }]] }""" all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs[0] == '1\n...\n' # somehow our create_config_objects add these \n...\n ...
def test_param_used_in_template(): template_str = "$the_template" experiment_str = """ { templates: { test_template: $test_param, }, variants: [[{ test_param: [1], the_template: [$test_template] }]] }""" all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs[ 0] == '1\n...\n' # somehow our create_config_objects add these \n...\n ...
def test_using_param_two_times(): template_str = "$test_param, template: $the_template" experiment_str = """ { templates: { test_template: {number: $test_param}, }, variants: [[{ test_param: [1,2], the_template: [$test_template], }]] } """ all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs[0] == "1, template: {number: 1}\n" assert all_train_strs[1] == "2, template: {number: 2}\n"
def test_param_in_nested_template(): template_str = "$test_param" experiment_str = """ { templates: { top_template: $test_template, test_template: $test_param_2, }, variants: [[{ test_param: [$top_template], test_param_2: [2], }]] }""" all_train_strs = create_experiment_yaml_strings([experiment_str], template_str) assert all_train_strs == [u'2\n...\n\n...\n']