forked from finos/common-domain-model
-
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.
Changes to utilize the new Python code generator (v2) (finos#2869)
* update to use the new Python Generator (v2). Includes expanded Python unit tests * cleanup validation test * Python Generator Cleanup * revert bundle usage in pom * additional pom cleanup * Updated to align to CDM bundle changes * additional alignment to next version of CDM * release.md clean up * one more release.md update * Update pom.xml to use correct bundle version --------- Co-authored-by: minesh-s-patel <[email protected]>
- Loading branch information
Showing
20 changed files
with
323 additions
and
127 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
Empty file.
This file was deleted.
Oops, something went wrong.
24 changes: 13 additions & 11 deletions
24
rosetta-source/src/test/python/semantics/test_cardinality.py
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,35 +1,37 @@ | ||
import pytest | ||
'''testing cardinality enforcement''' | ||
import datetime | ||
import pytest | ||
from cdm.base.datetime.DateList import DateList | ||
from rosetta.runtime.utils import ConditionViolationError | ||
|
||
|
||
def test_1_many_fail(): | ||
'''DateList cannot be empty''' | ||
dl = DateList(date=[]) | ||
with pytest.raises(ConditionViolationError): | ||
dl.validate_conditions() | ||
|
||
|
||
def test_1_many_fail_nopar(): | ||
def test_1_many_fail_empty_constructor(): | ||
'''DateList cannot be empty''' | ||
dl = DateList() | ||
with pytest.raises(ConditionViolationError): | ||
dl.validate_conditions() | ||
|
||
|
||
def test_1_many_pass(): | ||
'''Valid DateList''' | ||
dl = DateList(date=[datetime.date(2020, 1, 1)]) | ||
dl.validate_conditions() | ||
|
||
|
||
if __name__ == "__main__": | ||
print("first one") | ||
test_1_many_pass() | ||
print("second one") | ||
test_1_many_fail() | ||
print("third one") | ||
test_1_many_fail_nopar() | ||
|
||
|
||
# EOF | ||
print("test_1_many_pass") | ||
test_1_many_pass() | ||
print("test_1_many_fail") | ||
test_1_many_fail() | ||
print("test_1_many_fail_empty_constructor") | ||
test_1_many_fail_empty_constructor() | ||
|
||
|
||
# EOF |
36 changes: 23 additions & 13 deletions
36
rosetta-source/src/test/python/semantics/test_conditions.py
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,40 +1,50 @@ | ||
'''Full attribute validation - pydantic and constraints''' | ||
import pytest | ||
from pydantic import ValidationError | ||
from rosetta.runtime.utils import ConditionViolationError | ||
from cdm.base.math.NonNegativeQuantity import NonNegativeQuantity | ||
from cdm.base.math.UnitType import UnitType | ||
from cdm.base.datetime.Frequency import Frequency | ||
from cdm.base.datetime.PeriodExtendedEnum import PeriodExtendedEnum | ||
|
||
''' | ||
def test_recursive_conds(): | ||
unit = UnitType(currency='EUR') | ||
mq = NonNegativeQuantity(value=10, unit=unit) | ||
mq.validate_model() | ||
|
||
''' | ||
|
||
def test_recursive_conds_base_fail(): | ||
def test_recursive_conditions_base_fail(): | ||
'''condition_0_AmountOnlyExists violation''' | ||
unit = UnitType(currency='EUR') | ||
mq = NonNegativeQuantity(unit=unit) | ||
with pytest.raises(ConditionViolationError): | ||
mq.validate_model() | ||
|
||
def test_recursive_conds_direct_fail(): | ||
|
||
def test_recursive_conditions_direct_fail(): | ||
'''Negative quantity condition violation''' | ||
unit = UnitType(currency='EUR') | ||
mq = NonNegativeQuantity(value=-10, unit=unit) | ||
with pytest.raises(ConditionViolationError): | ||
mq.validate_model() | ||
|
||
|
||
def test_attrib_validity(): | ||
def test_bad_attrib_validation(): | ||
'''Invalid attribute assigned''' | ||
unit = UnitType(currency='EUR') | ||
mq = NonNegativeQuantity(value=10, unit=unit) | ||
mq.frequency = 'Blah' | ||
with pytest.raises(ValidationError): | ||
mq.validate_model() | ||
|
||
|
||
def test_correct_attrib_validation(): | ||
'''Valid attribute assigned''' | ||
unit = UnitType(currency='EUR') | ||
mq = NonNegativeQuantity(value=10, unit=unit) | ||
mq.frequency = Frequency(periodMultiplier=1, period=PeriodExtendedEnum.M) | ||
mq.validate_model() | ||
|
||
|
||
if __name__ == "__main__": | ||
test_recursive_conds_base_fail() | ||
test_recursive_conds_direct_fail() | ||
test_attrib_validity() | ||
test_recursive_conditions_base_fail() | ||
test_recursive_conditions_direct_fail() | ||
test_bad_attrib_validation() | ||
test_correct_attrib_validation() | ||
|
||
# EOF |
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
51 changes: 51 additions & 0 deletions
51
rosetta-source/src/test/python/semantics/test_local_conditions.py
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,51 @@ | ||
'''Tests of the local registration of conditions''' | ||
import inspect | ||
import pytest | ||
from rosetta.runtime.utils import rosetta_local_condition | ||
from rosetta.runtime.utils import execute_local_conditions | ||
from rosetta.runtime.utils import ConditionViolationError | ||
|
||
|
||
def test_pre_post_conditions(): | ||
'''Tests the registration of functions in two different registries''' | ||
_pre_registry = {} | ||
_post_registry = {} | ||
self = inspect.currentframe() | ||
|
||
# A local PRE condition | ||
@rosetta_local_condition(_pre_registry) | ||
def some_local_condition(): | ||
print(f'Pre {self}') | ||
return True | ||
|
||
# A local POST condition | ||
@rosetta_local_condition(_post_registry) | ||
def some_local_post_condition(): | ||
print(f'Post {self}') | ||
return True | ||
|
||
# Check all PRE conditions | ||
execute_local_conditions(_pre_registry, 'Pre-condition') | ||
|
||
print('Some Code....') | ||
|
||
# Check all POST conditions | ||
execute_local_conditions(_post_registry, 'Post-condition') | ||
|
||
|
||
def test_raise_local_cond(): | ||
'''checks if exception is raised and it is of the correct type''' | ||
_registry = {} | ||
@rosetta_local_condition(_registry) | ||
def some_failing_local_post_condition(): | ||
return False | ||
|
||
with pytest.raises(ConditionViolationError): | ||
execute_local_conditions(_registry, 'condition') | ||
|
||
|
||
if __name__ == '__main__': | ||
test_pre_post_conditions() | ||
test_raise_local_cond() | ||
|
||
# EOF |
26 changes: 26 additions & 0 deletions
26
rosetta-source/src/test/python/semantics/test_pydantic_simple.py
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,26 @@ | ||
# pylint: disable=unused-import,missing-function-docstring,invalid-name | ||
from datetime import date | ||
from cdm.event.common.Trade import Trade | ||
from cdm.event.common.TradeIdentifier import TradeIdentifier | ||
from cdm.product.template.TradableProduct import TradableProduct | ||
from cdm.product.template.Product import Product | ||
|
||
|
||
def test_trade(): | ||
product = Product() | ||
tradableProduct = TradableProduct(product=product) | ||
tradeIdentifier=[TradeIdentifier(issuer='Acme Corp')] | ||
|
||
t = Trade( | ||
tradeDate=date(2023, 1, 1), | ||
tradableProduct=tradableProduct, | ||
tradeIdentifier=tradeIdentifier | ||
) | ||
print(t.model_dump()) | ||
print('Done!') | ||
|
||
|
||
if __name__ == '__main__': | ||
test_trade() | ||
|
||
# EOF |
Oops, something went wrong.