예제 #1
0
def test_preprocessing():
    try:
        os.environ['FOO'] = 'abcdef'
        pp = proxy_to_partialplus(
            Proxy(callable=dict,
                  positionals=(),
                  keywords={'x': '${FOO}'},
                  yaml_src=None))
        p = evaluate(pp)
        assert p['x'] == 'abcdef'
        pp = proxy_to_partialplus(Proxy(callable=dict,
                                        positionals=(),
                                        keywords={'x': '${BAR}'},
                                        yaml_src=None),
                                  environ={'BAR': 'fedcba'})
        p = evaluate(pp)
        assert p['x'] == 'fedcba'
        pp = proxy_to_partialplus(Proxy(callable=dict,
                                        positionals=(),
                                        keywords={'x': '${FOO}'},
                                        yaml_src=None),
                                  environ={'FOO': 'ghijkl'})
        p = evaluate(pp)
        assert p['x'] == 'ghijkl'
    finally:
        del os.environ['FOO']
    # Test turning it off.
    pp = proxy_to_partialplus(Proxy(callable=dict,
                                    positionals=(),
                                    keywords={'x': '${BAZ}'},
                                    yaml_src=None),
                              preprocess_strings=False)
    p = evaluate(pp)
    assert p['x'] == '${BAZ}'
예제 #2
0
def test_preprocessing():
    try:
        os.environ['FOO'] = 'abcdef'
        pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                        keywords={'x': '${FOO}'},
                                        yaml_src=None))
        p = evaluate(pp)
        assert p['x'] == 'abcdef'
        pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                        keywords={'x': '${BAR}'},
                                        yaml_src=None),
                                  environ={'BAR': 'fedcba'})
        p = evaluate(pp)
        assert p['x'] == 'fedcba'
        pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                        keywords={'x': '${FOO}'},
                                        yaml_src=None),
                                  environ={'FOO': 'ghijkl'})
        p = evaluate(pp)
        assert p['x'] == 'ghijkl'
    finally:
        del os.environ['FOO']
    # Test turning it off.
    pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                    keywords={'x': '${BAZ}'},
                                    yaml_src=None), preprocess_strings=False)
    p = evaluate(pp)
    assert p['x'] == '${BAZ}'
예제 #3
0
def test_no_preprocessing_raises_when_environ_provided():
    raised = False
    try:
        proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                   keywords={'x': '${FOO}'},
                                   yaml_src=None),
                             preprocess_strings=False,
                             environ={'a': 'b'})
    except ValueError:
        raised = True
    assert raised
예제 #4
0
def test_no_preprocessing_raises_when_environ_provided():
    raised = False
    try:
        proxy_to_partialplus(Proxy(callable=dict,
                                   positionals=(),
                                   keywords={'x': '${FOO}'},
                                   yaml_src=None),
                             preprocess_strings=False,
                             environ={'a': 'b'})
    except ValueError:
        raised = True
    assert raised
예제 #5
0
def test_append_yaml_callback():
    pfail = Proxy(callable=dict, positionals=(), keywords={'value': 5},
                  yaml_src="test_value_1")
    pobj = Proxy(callable=Foo, positionals=(), keywords={'x': 3},
                 yaml_src="test_value_2")
    raised = False
    try:
        test = append_yaml_callback(pfail, proxy_to_partialplus(pfail))
    except AttributeError:
        raised = True
    assert not raised
    test = evaluate(append_yaml_callback(pobj, proxy_to_partialplus(pobj)))
    assert hasattr(test, 'yaml_src')
    assert test.yaml_src == "test_value_2"
예제 #6
0
def test_proxy_to_partialplus():
    # Use proxy_callback=None to test without YAML-appending.
    pp = proxy_to_partialplus(Proxy(callable=dict,
                                    positionals=(),
                                    keywords={'x': [5, 3, 2]},
                                    yaml_src=None),
                              proxy_callback=None)
    assert evaluate(pp) == {'x': [5, 3, 2]}
예제 #7
0
def test_append_yaml_callback():
    pfail = Proxy(callable=dict,
                  positionals=(),
                  keywords={'value': 5},
                  yaml_src="test_value_1")
    pobj = Proxy(callable=Foo,
                 positionals=(),
                 keywords={'x': 3},
                 yaml_src="test_value_2")
    raised = False
    try:
        test = append_yaml_callback(pfail, proxy_to_partialplus(pfail))
    except AttributeError:
        raised = True
    assert not raised
    test = evaluate(append_yaml_callback(pobj, proxy_to_partialplus(pobj)))
    assert hasattr(test, 'yaml_src')
    assert test.yaml_src == "test_value_2"
예제 #8
0
def test_proxy_to_partialplus_literal_callback():
    def baz(x):
        if isinstance(x, int):
            x *= 2
        return x

    # Use proxy_callback=None to test without YAML-appending.
    pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                    keywords={'x': 5}, yaml_src=None),
                              proxy_callback=None, literal_callback=baz)
    assert evaluate(pp)['x'] == 10
예제 #9
0
def test_proxy_to_partialplus_literal_callback():
    def baz(x):
        if isinstance(x, int):
            x *= 2
        return x

    # Use proxy_callback=None to test without YAML-appending.
    pp = proxy_to_partialplus(Proxy(callable=dict,
                                    positionals=(),
                                    keywords={'x': 5},
                                    yaml_src=None),
                              proxy_callback=None,
                              literal_callback=baz)
    assert evaluate(pp)['x'] == 10
예제 #10
0
def test_identical_proxy_identical_partialplus():
    proxy = Proxy(lambda: None, None, None, None)
    pp = proxy_to_partialplus([{'a': proxy}, proxy], proxy_callback=None)
    assert pp.args[0].args[1].args[1] is pp.args[1]
예제 #11
0
def test_do_not_recurse():
    proxy = Proxy(callable=do_not_recurse,
                  positionals=(),
                  keywords={'value': Proxy(None, None, None, None)},
                  yaml_src=None)
    assert isinstance(evaluate(proxy_to_partialplus(proxy)), Proxy)
예제 #12
0
def test_proxy_to_partialplus():
    # Use proxy_callback=None to test without YAML-appending.
    pp = proxy_to_partialplus(Proxy(callable=dict, positionals=(),
                                    keywords={'x': [5, 3, 2]}, yaml_src=None),
                              proxy_callback=None)
    assert evaluate(pp) == {'x': [5, 3, 2]}
예제 #13
0
def test_identical_proxy_identical_partialplus():
    proxy = Proxy(lambda: None, None, None, None)
    pp = proxy_to_partialplus([{'a': proxy}, proxy], proxy_callback=None)
    assert pp.args[0].args[1].args[1] is pp.args[1]
예제 #14
0
def test_do_not_recurse():
    proxy = Proxy(callable=do_not_recurse, positionals=(),
                  keywords={'value': Proxy(None, None, None, None)},
                  yaml_src=None)
    assert isinstance(evaluate(proxy_to_partialplus(proxy)), Proxy)