-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from igorkramaric/support-existance-check-ked-…
…delegate Support existence check for KED delegate
- Loading branch information
Showing
9 changed files
with
165 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .predicate import DictionaryPredicateDelegate | ||
from .hstore_predicate import HStoreQueryDelegate | ||
from .pretty_print import PrettyPrintDelegate | ||
from .key_expectation_delegate import KeyExpectationDelegate | ||
from .parser import Daffodil |
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 @@ | ||
from builtins import object | ||
|
||
|
||
class BaseDaffodilDelegate(object): | ||
|
||
def mk_any(self, children): | ||
raise NotImplementedError() | ||
|
||
def mk_all(self, children): | ||
raise NotImplementedError() | ||
|
||
def mk_not_any(self, children): | ||
raise NotImplementedError() | ||
|
||
def mk_not_all(self, children): | ||
raise NotImplementedError() | ||
|
||
def mk_test(self, test_str): | ||
raise NotImplementedError() | ||
|
||
def mk_comment(self, comment, is_inline): | ||
raise NotImplementedError() | ||
|
||
def mk_cmp(self, key, val, test): | ||
raise NotImplementedError() | ||
|
||
def call(self, predicate, iterable): | ||
raise NotImplementedError() | ||
|
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,59 @@ | ||
from .base_delegate import BaseDaffodilDelegate | ||
|
||
|
||
class KeyExpectationDelegate(BaseDaffodilDelegate): | ||
""" | ||
Determines which keys in a daffodil are required in data dictionaries | ||
in order to match and which keys have to be omitted to match. | ||
Useful for making inferences like detecting when a key would never be set | ||
but should (or would be but shouldn't). | ||
""" | ||
def _mk_group(self, children, negate): | ||
expect_present = set() | ||
expect_omitted = set() | ||
|
||
for child in children: | ||
if negate: | ||
child = child[::-1] | ||
expect_present |= child[0] | ||
expect_omitted |= child[1] | ||
|
||
# if we expect a key to be present we can't also expect it not to be | ||
expect_omitted -= expect_present | ||
|
||
return expect_present, expect_omitted | ||
|
||
def mk_any(self, children): | ||
return self._mk_group(children, False) | ||
|
||
def mk_all(self, children): | ||
return self._mk_group(children, False) | ||
|
||
def mk_not_any(self, children): | ||
return self._mk_group(children, True) | ||
|
||
def mk_not_all(self, children): | ||
return self._mk_group(children, True) | ||
|
||
def mk_test(self, test_str): | ||
if test_str != "?=": | ||
return test_str | ||
|
||
def test_fn(k, v, t): | ||
return v | ||
|
||
test_fn.is_datapoint_test = True | ||
test_fn.test_str = test_str | ||
|
||
return test_fn | ||
|
||
def mk_comment(self, comment, is_inline): | ||
return set(), set() | ||
|
||
def mk_cmp(self, key, val, test): | ||
existance = getattr(test, "is_datapoint_test", False) | ||
|
||
if existance and val is False: | ||
return set(), {key} | ||
return {key}, set() |
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
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