예제 #1
0
def test_maybe_default_from_env():
    # maybe fill in parameter default from the env, depending on getenv
    up = UserParameter('name', default='env(INTAKE_TEST_VAR)')
    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': "{{name}}"},
                          parameters=[up],
                          getenv=False)
    s = e()
    assert s.kwargs['arg1'] == 'env(INTAKE_TEST_VAR)'

    os.environ['INTAKE_TEST_VAR'] = 'oi'
    # Clear the cached source so we can (not) pick up the changed environment variable.
    e.clear_cached_default_source()

    s = e()
    assert s.kwargs['arg1'] == 'env(INTAKE_TEST_VAR)'

    up = UserParameter('name', default='env(INTAKE_TEST_VAR)')
    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': "{{name}}"},
                          parameters=[up],
                          getenv=True)
    s = e()
    assert s.kwargs['arg1'] == 'oi'

    del os.environ['INTAKE_TEST_VAR']
    # Clear the cached source so we can pick up the changed environment variable.
    e.clear_cached_default_source()

    s = e()
    assert s.kwargs['arg1'] == ''
예제 #2
0
def test_auto_env_expansion():
    os.environ['INTAKE_TEST_VAR'] = 'oi'
    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': "{{env(INTAKE_TEST_VAR)}}"},
                          parameters=[],
                          getenv=False)
    s = e()

    # when getenv is False, you pass through the text
    assert s.kwargs['arg1'] == '{{env(INTAKE_TEST_VAR)}}'

    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': "{{env(INTAKE_TEST_VAR)}}"},
                          parameters=[],
                          getenv=True)
    s = e()
    assert s.kwargs['arg1'] == 'oi'

    # same, but with quoted environment name
    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': '{{env("INTAKE_TEST_VAR")}}'},
                          parameters=[],
                          getenv=True)
    s = e()
    assert s.kwargs['arg1'] == 'oi'

    del os.environ['INTAKE_TEST_VAR']
    # Clear the cached source so we can pick up the changed environment variable.
    e.clear_cached_default_source()

    s = e()
    assert s.kwargs['arg1'] == ''

    e = LocalCatalogEntry('',
                          '',
                          driver,
                          args={'arg1': "{{env(INTAKE_TEST_VAR)}}"},
                          parameters=[],
                          getenv=False)
    s = e()
    assert s.kwargs['arg1'] == '{{env(INTAKE_TEST_VAR)}}'