Skip to content

Commit

Permalink
Add inheritance spec
Browse files Browse the repository at this point in the history
  • Loading branch information
quiqueporta committed May 25, 2024
1 parent efe594c commit 026b9dd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions specs/value_object_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,31 @@ class MyPoint(ValueObject):
equal("Money(amount=Decimal('100'), currency=Currency(symbol='€'))")
)

with context("inheritance"):

with it("can inherit from another value object"):

class MyPointException(Exception):
pass

class Point(ValueObject):
x: int
y: int

@invariant
def x_not_negative(self):
return self.x >= 0

class MyPoint(Point):

@invariant(MyPointException)
def y_not_negative(self):
return self.y >= 0, "Y must be positive"

expect(lambda: MyPoint(6, -1)).to(
raise_error(MyPointException, "Y must be positive")
)

with context("restrictions"):

with context("with mutable data types"):
Expand Down

0 comments on commit 026b9dd

Please sign in to comment.