Example #1
0
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']"
Example #2
0
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']"
Example #3
0
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'
Example #4
0
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'
Example #5
0
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"
Example #6
0
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"
Example #7
0
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']"
Example #8
0
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']"
Example #9
0
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"
Example #10
0
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'
Example #11
0
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'
Example #12
0
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"
Example #13
0
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 ...
Example #14
0
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 ...
Example #15
0
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"
Example #16
0
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']
Example #17
0
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"
Example #18
0
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']