forked from iterative/dvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parametrization: print pretty interpolation errors (iterative#4953)
* parametrization: print pretty interpolation errors * Fix col/loc in exception msg * Fix tests
- Loading branch information
Showing
3 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
import re | ||
|
||
import pytest | ||
|
||
|
@@ -9,6 +10,11 @@ | |
DATA = {"models": {"bar": "bar", "foo": "foo"}} | ||
|
||
|
||
def escape_ansi(line): | ||
ansi_escape = re.compile(r"(\x9B|\x1B\[)[0-?]*[ -\/]*[@-~]") | ||
return ansi_escape.sub("", line) | ||
|
||
|
||
@pytest.fixture | ||
def repo(tmp_dir, dvc): | ||
dump_yaml(tmp_dir / DEFAULT_PARAMS_FILE, DATA) | ||
|
@@ -73,7 +79,7 @@ def test_failed_to_interpolate(tmp_dir, repo): | |
with pytest.raises(ResolveError) as exc_info: | ||
resolver = DataResolver(repo, tmp_dir, d) | ||
resolver.resolve() | ||
assert str(exc_info.value) == ( | ||
assert escape_ansi(str(exc_info.value)) == ( | ||
"failed to parse 'stages.build.cmd' in 'dvc.yaml':\n" | ||
"${models.foo.}\n" | ||
" ^\n" | ||
|
@@ -170,7 +176,7 @@ def test_foreach_interpolation_key_error(tmp_dir, repo): | |
resolver = DataResolver(repo, tmp_dir, d) | ||
with pytest.raises(ResolveError) as exc_info: | ||
resolver.resolve() | ||
assert str(exc_info.value) == ( | ||
assert escape_ansi(str(exc_info.value)) == ( | ||
"failed to parse 'stages.build.foreach' in 'dvc.yaml':\n" | ||
"${models[123}\n" | ||
" ^\n" | ||
|
@@ -201,7 +207,7 @@ def test_foreach_generated_errors(tmp_dir, repo, syn, msg): | |
resolver = DataResolver(repo, tmp_dir, d) | ||
with pytest.raises(ResolveError) as exc_info: | ||
resolver.resolve() | ||
assert str(exc_info.value) == ( | ||
assert escape_ansi(str(exc_info.value)) == ( | ||
"failed to parse '[email protected]' in 'dvc.yaml':" + msg | ||
) | ||
|
||
|
@@ -260,7 +266,7 @@ def test_foreach_wdir_interpolation_issues(tmp_dir, repo, wdir, msg): | |
resolver = DataResolver(repo, tmp_dir, d) | ||
with pytest.raises(ResolveError) as exc_info: | ||
resolver.resolve() | ||
assert str(exc_info.value) == ( | ||
assert escape_ansi(str(exc_info.value)) == ( | ||
"failed to parse '[email protected]' in 'dvc.yaml':" + msg | ||
) | ||
|
||
|
@@ -297,7 +303,7 @@ def test_wdir_failed_to_interpolate(tmp_dir, repo, wdir, expected_msg): | |
resolver = DataResolver(repo, tmp_dir, d) | ||
with pytest.raises(ResolveError) as exc_info: | ||
resolver.resolve() | ||
assert str(exc_info.value) == ( | ||
assert escape_ansi(str(exc_info.value)) == ( | ||
"failed to parse 'stages.build.wdir' in 'dvc.yaml':" + expected_msg | ||
) | ||
|
||
|