Debian Codegraph @

petl/test/test_helpers.py

raw
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import, print_function, division
3
4 import pytest
5
6 from petl.test.helpers import eq_, ieq, get_env_vars_named
7
8 GET_ENV_PREFIX = "PETL_TEST_HELPER_ENVVAR_"
9
10
11 def _testcase_get_env_vars_named(num_vals, prefix=""):
12 res = {}
13 for i in range(1, num_vals, 1):
14 reskey = prefix + str(i)
15 res[reskey] = str(i)
16 return res
17
18
19 @pytest.fixture()
20 def setup_helpers_get_env_vars_named(monkeypatch):
21 varlist = _testcase_get_env_vars_named(3, prefix=GET_ENV_PREFIX)
22 for k, v in varlist.items():
23 monkeypatch.setenv(k, v)
24
25
26 def test_helper_get_env_vars_named_prefixed(setup_helpers_get_env_vars_named):
27 expected = _testcase_get_env_vars_named(3, GET_ENV_PREFIX)
28 found = get_env_vars_named(GET_ENV_PREFIX, remove_prefix=False)
29 ieq(found, expected)
30
31
32 def test_helper_get_env_vars_named_unprefixed(setup_helpers_get_env_vars_named):
33 expected = _testcase_get_env_vars_named(3)
34 found = get_env_vars_named(GET_ENV_PREFIX, remove_prefix=True)
35 ieq(found, expected)
36
37
38 def test_helper_get_env_vars_named_not_found(setup_helpers_get_env_vars_named):
39 expected = None
40 found = get_env_vars_named("PETL_TEST_HELPER_ENVVAR_NOT_FOUND_")
41 eq_(found, expected)