-
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.
refactor check, mark python/mypy#14622 bugs
- Loading branch information
Showing
5 changed files
with
56 additions
and
22 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,29 +1,26 @@ | ||
|
||
from shall.ShallEntity import ShallEntity, P, R | ||
from injector import inject | ||
from src.shall.CheckReturnConstraints import CheckReturnConstraints | ||
from src.shall.CheckReturnValue import CheckReturnValue | ||
from src.shall.CheckSideEffects import CheckSideEffects | ||
|
||
class Check(): | ||
@inject | ||
def __init__(self, | ||
checkReturnValue:CheckReturnValue[P,R], | ||
checkReturnConstraints: CheckReturnConstraints[P,R], | ||
checkSideEffects: CheckSideEffects[P,R] | ||
) -> None: | ||
self.checkReturnValue = checkReturnValue | ||
self.checkReturnConstraints = checkReturnConstraints | ||
self.checkSideEffects = checkSideEffects | ||
|
||
class Check(ShallEntity[P, R]): | ||
def check(self) -> None: | ||
paramlist = self.parameters[0] | ||
paramkwargs = self.parameters[1] | ||
print(self.explanation) | ||
callResult = self.callable(*paramlist, **paramkwargs) | ||
if self.returnValue == callResult: | ||
print("/return value PASSED") | ||
else: | ||
raise AssertionError(self.explanation + | ||
" did return " + str(callResult) + " instead of " + str(self.returnValue)) | ||
for (explanation, checker) in self.returnConstraints: | ||
checked = checker(self.returnValue, *paramlist, **paramkwargs) | ||
if checked: | ||
print("+"+explanation+": PASSED") | ||
else: | ||
raise AssertionError(explanation+" did not hold") | ||
for (explanation, sideEffectChecker) in self.sideEffectCheckers: | ||
sideEffectChecker.setUp(self.callable, *paramlist, **paramkwargs) | ||
result = sideEffectChecker.runTest() | ||
sideEffectChecker.tearDown() | ||
if result: | ||
print("-"+explanation+": PASSED") | ||
else: | ||
raise AssertionError( | ||
explanation+" did not hold: " + str(result)) | ||
self.checkReturnValue.checkReturnValue(callResult) | ||
self.checkReturnConstraints.checkReturnConstraints( paramlist, paramkwargs) | ||
self.checkSideEffects.checkSideEffects(paramlist,paramkwargs) |
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,11 @@ | ||
from src.shall.ShallEntity import ShallEntity, P, R | ||
|
||
|
||
class CheckReturnConstraints(ShallEntity[P, R]): | ||
def checkReturnConstraints(self, paramlist:P.args, paramkwargs: P.kwargs) -> None: #type:ignore # https://github.com/python/mypy/issues/14622 | ||
for (explanation, checker) in self.returnConstraints: | ||
checked = checker(self.returnValue, *paramlist, **paramkwargs) | ||
if checked: | ||
print("+"+explanation+": PASSED") | ||
else: | ||
raise AssertionError(explanation+" did not hold") |
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,10 @@ | ||
from src.shall.ShallEntity import ShallEntity, P, R | ||
|
||
|
||
class CheckReturnValue(ShallEntity[P, R]): | ||
def checkReturnValue(self, callResult: R) ->None: | ||
if self.returnValue == callResult: | ||
print("/return value PASSED") | ||
else: | ||
raise AssertionError(self.explanation + | ||
" did return " + str(callResult) + " instead of " + str(self.returnValue)) |
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,14 @@ | ||
from src.shall.ShallEntity import ShallEntity, P, R | ||
|
||
|
||
class CheckSideEffects(ShallEntity[P, R]): | ||
def checkSideEffects(self, paramlist:P.args, paramkwargs: P.kwargs) ->None: #type:ignore #https://github.com/python/mypy/issues/14622 | ||
for (explanation, sideEffectChecker) in self.sideEffectCheckers: | ||
sideEffectChecker.setUp(self.callable, *paramlist, **paramkwargs) | ||
result = sideEffectChecker.runTest() | ||
sideEffectChecker.tearDown() | ||
if result: | ||
print("-"+explanation+": PASSED") | ||
else: | ||
raise AssertionError( | ||
explanation+" did not hold: " + str(result)) |
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