Skip to content

Commit

Permalink
all tests are passing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandruBurlacu committed Oct 17, 2018
1 parent 03d5c3b commit 0733750
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
7 changes: 5 additions & 2 deletions examples/class_inheritance_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

from pycontracts import Contract

def remove_fst(dictionary):
del dictionary["arg__0"]
return dictionary

class TestClassBase(object):

@Contract.pre_conditions({
"Both arguments should be positive": lambda args, kwargs: args[1] > 0 and args[2] > 0
"Both arguments should be positive": lambda args: args.arg__1 > 0 and args.arg__2 > 0
})
def query(self, arg1, arg2):
return arg1 * arg2
Expand All @@ -24,7 +27,7 @@ class TestClassChild(TestClassBase):
"Return argument should be 0": lambda ret: ret == 0
})
def query(self, arg1, arg2):
return arg1 * arg2 - super().query(arg1, arg2)
return arg1 * arg2 - super(TestClassChild, self).query(arg1, arg2)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/class_methods_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class TestClass(object):

@Contract.pre_conditions({
"Both arguments should be positive": lambda args, kwargs: args[1] > 0 and args[2] > 0
"Both arguments should be positive": lambda args: args.arg__1 > 0 and args.arg__2 > 0
})
def query(self, arg1, arg2):
return arg1 * arg2
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pycontracts import Contract

@Contract.pre_conditions({
"First argument should be positive": lambda args, kwargs: args[0] > 0
"First argument should be positive": lambda args: args.arg__0 > 0
})
@Contract.post_conditions({
"Return argument should be negative": lambda ret: ret < 0
Expand Down
1 change: 0 additions & 1 deletion pycontracts/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def __init__(self, *args, **kwargs):
self.__unify_kwargs()

self.all_args = deepcopy(self.__dict__)
print(self.all_args)

def __unify_args(self):
for idx, value in enumerate(self.__args):
Expand Down
6 changes: 5 additions & 1 deletion tests/test_contracts_classes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import unittest
from pycontracts import Contract, exceptions

def remove_fst(dictionary):
del dictionary["arg__0"]
return dictionary

class TestClassBase(object):

@Contract.pre_conditions({
"All arguments should be positive":
lambda args: all(map(lambda x: 1 if x > 0 else 0, list(args.all_args.values())))
lambda args: all(map(lambda x: 1 if x > 0 else 0, list(remove_fst(args.all_args).values())))
})
def query(self, arg1, arg2):
return arg1 * arg2
Expand Down

0 comments on commit 0733750

Please sign in to comment.