-
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.
Beginnig of check contract, marked ignores with the corresponding myp…
…y bug python/mypy#14806 8 times python/mypy#14785 2 times
- Loading branch information
Showing
16 changed files
with
51 additions
and
48 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
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
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,22 +1,29 @@ | ||
from typing import Callable, cast | ||
from unittest.mock import Mock | ||
from Shall import Shall | ||
from shall.Check import Check | ||
from shall.ShallConstructor import ShallConstructor | ||
|
||
def callable(a:int)-> str: | ||
return str(a) | ||
def check(returnValue: None, self: Check[[int],str] ) -> bool: | ||
mock = cast(Mock,self.callable) | ||
mock.assert_called_once() | ||
return True | ||
|
||
class CheckContract: | ||
callableMock:Callable[[int], str] = Mock() | ||
cast(Mock,callableMock).return_value="2" | ||
selfMock= Mock() | ||
selfMock.callable = callable | ||
selfMock.callable = callableMock | ||
selfMock.parameters = ((2,),{}) | ||
selfMock.returnValue = "2" | ||
selfMock.explanation = "explanation" | ||
selfMock.returnConstraints = list() | ||
selfMock.sideEffectCheckers = list() | ||
|
||
rules = [( | ||
Shall("checks the contract", Check[[int],str].check) | ||
Shall[[Check[[int],str]],None]("checks the contract", Check[[int],str].check) #type:ignore #https://github.com/python/mypy/issues/14806 | ||
.ifCalledWith(selfMock) | ||
.thenReturn(None) | ||
)] | ||
.suchThat("the callable is called", check) | ||
)] | ||
|
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,20 +1,21 @@ | ||
from typing import Any, Callable, List, Self, Unpack | ||
from typing import Any | ||
from unittest.mock import MagicMock | ||
from Shall import Shall | ||
from shall.IfCalledWith import IfCalledWith | ||
from shall.ShallEntity import ShallEntity, P, R | ||
|
||
def checker(returnValue:Any, self:ShallEntity[P,R], otherparam: int, foo: str) -> bool: | ||
def checker(returnValue:IfCalledWith[[int, str], None], self:IfCalledWith[[int, str], None], otherparam: int, foo: str) -> bool: | ||
expected = ((1,), {'foo': 'bar'}) | ||
return self.parameters == expected | ||
|
||
class IfCalledWithContract: | ||
mockSelf:IfCalledWith[[int, str], None] = MagicMock() | ||
rules = [( | ||
Shall("defines the parameters with which the SUT is called", | ||
IfCalledWith[[int,str], None].ifCalledWith) #type:ignore | ||
.ifCalledWith(mockSelf,1,foo="bar") #type:ignore | ||
.thenReturn(mockSelf) #type:ignore | ||
.suchThat("registers the return value", checker) #type:ignore | ||
Shall[IfCalledWith[[int,str], None],IfCalledWith[[int,str], None]]( | ||
"defines the parameters with which the SUT is called", | ||
IfCalledWith[[int,str], None].ifCalledWith) #type: ignore #https://github.com/python/mypy/issues/14806 | ||
.ifCalledWith(mockSelf,1,foo="bar") #type:ignore # https://github.com/python/mypy/issues/14806 | ||
.thenReturn(mockSelf) | ||
.suchThat("registers the return value", checker) #type: ignore # https://github.com/python/mypy/issues/14806 | ||
)] | ||
|
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