-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use decorator for checksum * Add decorator for skipping validations * Add tests for decorator * Update CHANGELOG * Document option to skip in README * Fix linting * Use functools.wraps around decorated functions
- Loading branch information
1 parent
290fa89
commit f9adeae
Showing
5 changed files
with
74 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
""" Common functions for PipeVal """ | ||
import os | ||
from functools import wraps | ||
|
||
# pylint: disable=C0103,W0613 | ||
def skippedValidation(name): | ||
""" | ||
Conditionally mark a validation to be skipped | ||
If the environment variable f'PIPEVAL_SKIP_{name}' is set to `true`, | ||
the decorated function will skip that validation. | ||
""" | ||
def decorator(func): | ||
return func | ||
|
||
def print_skip_message(func): | ||
@wraps(func) | ||
def skip_message(*args, **kwargs): | ||
print(f'PID:{os.getpid()} - Skipping validation {name.upper()}') | ||
|
||
return skip_message | ||
|
||
value = os.environ.get(f"PIPEVAL_SKIP_{name.upper()}") | ||
should_skip_validate = value is not None and value.lower() == 'true' | ||
|
||
if not should_skip_validate: | ||
return decorator | ||
|
||
return print_skip_message |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# pylint: disable=C0116 | ||
# pylint: disable=C0114 | ||
# pylint: disable=C0103 | ||
from pipeval.common import skippedValidation | ||
|
||
def test__skippedValidation__properly_skips_function_call(monkeypatch, capsys): | ||
monkeypatch.setenv('PIPEVAL_SKIP_CHECKSUM', 'true') | ||
|
||
@skippedValidation('CHECKSUM') | ||
def to_be_decorated(): | ||
print('Decorated function called') | ||
|
||
to_be_decorated() | ||
|
||
out, _ = capsys.readouterr() | ||
|
||
assert 'Skipping validation CHECKSUM' in out | ||
assert 'Decorated function called' not in out | ||
|
||
def test__skippedValidation__properly_calls_function(monkeypatch, capsys): | ||
monkeypatch.setenv('PIPEVAL_SKIP_CHECKSUM', 'false') | ||
|
||
@skippedValidation('CHECKSUM') | ||
def to_be_decorated(): | ||
print('Decorated function called') | ||
|
||
to_be_decorated() | ||
|
||
out, _ = capsys.readouterr() | ||
|
||
assert 'Skipping validation CHECKSUM' not in out | ||
assert 'Decorated function called' in out |