-
Notifications
You must be signed in to change notification settings - Fork 6
Yet another refactor #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
netcompare/check_types.py
Outdated
| """ | ||
| raise NotImplementedError | ||
|
|
||
| def evaluate(self, reference_value: dict, value_to_compare: Any) -> Tuple[Dict, bool]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def evaluate(self, reference_value: dict, value_to_compare: Any) -> Tuple[Dict, bool]: | |
| def evaluate(self, value_to_compare: Any, **reference_value) -> Tuple[Dict, bool]: |
netcompare/check_types.py
Outdated
|
|
||
| def evaluate(self, reference_value: dict, value_to_compare: Any) -> Tuple[Dict, bool]: | ||
|
|
||
| return self.hook_evaluate(self.args_class(reference_value), value_to_compare) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return self.hook_evaluate(self.args_class(reference_value), value_to_compare) | |
| return self.hook_evaluate(self.args_class(**reference_value), value_to_compare) |
| Args: | ||
| reference_value: Can be any structured data or just a simple value. | ||
| value_to_compare: Similar value as above to perform comparison. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just remember about updating docstrings, or get someone to do that. I can volunteer.
netcompare/check_types.py
Outdated
|
|
||
| def __init__(self, *args): | ||
| """Check Type init method.""" | ||
| class_args = CheckArguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use validator_class for consistency.
| reference_value: Can be any structured data or just a simple value. | ||
| value_to_compare: Similar value as above to perform comparison. | ||
| Returns: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding:
self.validator_class.validate(**kwargs) in this abstract method? This would show the proper usage.
| # pylint: disable=arguments-differ | ||
|
|
||
|
|
||
| class CheckType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes me think that using abstract class could simplify it and still enforce common interface.
from abc import ABC, abstractmethod
class CheckType(ABC):
@abstractmethod
def validate(self, **kwargs):
# Validate logic
pass
@abstractmethod
def evaluate(self, data, **kwargs):
self.validate(**kwargs)
# Evaluate logic
pass
class MyCheck(CheckType):
def validate(self, **kwargs):
# check-type logic
return
def evaluate(self, data, **kwargs):
self.validate(**kwargs)
# check-type logic
return
Definitely not something to do now, but just wanted to share this as an idea. IMO cleaner and less boilerplate code.
|
LGTM. Let's make this roll so we can move forward with the last check implementation :) |
|
@pszulczewski @lvrfrc87 , the PR is almost ready, only 3 tests are failing, but I believe that maybe it's related to some change in the logic. could you take it from here and merge it? |
| def _within_tolerance(*, old_value: float, new_value: float) -> bool: | ||
| """Return True if new value is within the tolerance range of the previous value.""" | ||
| max_diff = old_value * self.tolerance_factor | ||
| tolerance_factor = tolerance / 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chadell this line was missing.
|
@chadell build is failing but locally is ok. Is it something you can look at? |
Proposing a new iteration to improve the usability of the library.
Proposed workflows, where the
evaluatehas an implicit validation of the reference_data perCheckType:check = CheckType("parameter_match")
check.evaluate(my_var,
class ParameterMatch:
def evaluate(value, param1, param2, ):
self.validate(param1, param2)
... logic ...