diff options
| author | Alexander Schepanovski <suor.web@gmail.com> | 2014-08-09 22:19:09 +0800 |
|---|---|---|
| committer | Alexander Schepanovski <suor.web@gmail.com> | 2014-08-09 22:19:09 +0800 |
| commit | 95c5fee5612759f9ec37e97e419776a6a359f3a5 (patch) | |
| tree | 77653b168cb12d1364dacbfca8d267b246caea4e | |
| parent | 7969038573c8f2e7646a048ac8c738cd208ed571 (diff) | |
| download | tox-95c5fee5612759f9ec37e97e419776a6a359f3a5.tar.gz | |
Support boolean ops on factors
| -rw-r--r-- | tests/test_config.py | 18 | ||||
| -rw-r--r-- | tox/_config.py | 14 |
2 files changed, 28 insertions, 4 deletions
diff --git a/tests/test_config.py b/tests/test_config.py index fc429a4..7cbb656 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -850,6 +850,24 @@ class TestConfigTestEnv: ["dep-all", "dep-a", "dep-x"] assert [dep.name for dep in configs['b'].deps] == ["dep-all", "dep-b"] + def test_factor_ops(self, newconfig): + inisource=""" + [tox] + envlist = {a,b}-{x,y} + + [testenv] + deps= + a,b: dep-a-or-b + a-x: dep-a-and-x + {a,b}-y: dep-ab-and-y + """ + configs = newconfig([], inisource).envconfigs + get_deps = lambda env: [dep.name for dep in configs[env].deps] + assert get_deps("a-x") == ["dep-a-or-b", "dep-a-and-x"] + assert get_deps("a-y") == ["dep-a-or-b", "dep-ab-and-y"] + assert get_deps("b-x") == ["dep-a-or-b"] + assert get_deps("b-y") == ["dep-a-or-b", "dep-ab-and-y"] + def test_default_factors(self, newconfig): inisource=""" [tox] diff --git a/tox/_config.py b/tox/_config.py index 2503962..26603c9 100644 --- a/tox/_config.py +++ b/tox/_config.py @@ -302,7 +302,8 @@ class parseini: factors = set() if section in self._cfg: for _, value in self._cfg[section].items(): - factors.update(re.findall(r'^(\w+)\:\s+', value, re.M)) + exprs = re.findall(r'^([\w{},-]+)\:\s+', value, re.M) + factors.update(*mapcat(_split_factor_expr, exprs)) return factors def _makeenvconfig(self, name, section, subs, config): @@ -434,12 +435,17 @@ class parseini: dep2_name = pkg_resources.Requirement.parse(dep2).project_name return dep1_name == dep2_name + def _split_env(env): """if handed a list, action="append" was used for -e """ if not isinstance(env, list): env = [env] return mapcat(_expand_envstr, env) +def _split_factor_expr(expr): + partial_envs = _expand_envstr(expr) + return [set(e.split('-')) for e in partial_envs] + def _expand_envstr(envstr): # split by commas not in groups tokens = re.split(r'(\{[^}]+\})|,', envstr) @@ -628,12 +634,12 @@ class IniReader: def _apply_factors(self, s): def factor_line(line): - m = re.search(r'^(\w+)\:\s+(.+)', line) + m = re.search(r'^([\w{},-]+)\:\s+(.+)', line) if not m: return line - factor, line = m.groups() - if factor in self.factors: + expr, line = m.groups() + if any(fs <= self.factors for fs in _split_factor_expr(expr)): return line lines = s.strip().splitlines() |
