diff --git a/tests/test_core.py b/tests/test_core.py index 5593885..da93695 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -1,6 +1,5 @@ from optionlab.models import Inputs, Outputs from optionlab.strategy import StrategyEngine -import datetime as dt def test_covered_call(nvidia): @@ -10,7 +9,7 @@ def test_covered_call(nvidia): nvidia | { # The covered call strategy is defined - 'strategy': [ + "strategy": [ {"type": "stock", "n": 100, "action": "buy"}, { "type": "call", @@ -51,8 +50,8 @@ def test_covered_call_w_days_to_target(nvidia): inputs = Inputs.model_validate( nvidia | { - 'days_to_target_date': 30, - 'strategy': [ + "days_to_target_date": 30, + "strategy": [ {"type": "stock", "n": 100, "action": "buy"}, { "type": "call", @@ -80,7 +79,7 @@ def test_covered_call_w_prev_position(nvidia): nvidia | { # The covered call strategy is defined - 'strategy': [ + "strategy": [ {"type": "stock", "n": 100, "action": "buy", "prev_pos": 158.99}, { "type": "call", @@ -121,7 +120,7 @@ def test_100_perc_itm(nvidia): nvidia | { # The covered call strategy is defined - 'strategy': [ + "strategy": [ { "type": "call", "strike": 165.0, diff --git a/tests/test_models.py b/tests/test_models.py index c876636..fedb2d7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,7 +1,9 @@ +import datetime as dt + import pytest from optionlab.models import Inputs -import datetime as dt + def test_only_one_closed_position(nvidia): @@ -16,17 +18,14 @@ def test_only_one_closed_position(nvidia): with pytest.raises(ValueError) as err: Inputs.model_validate(inputs) - assert ( - "Only one position of type 'closed' is allowed!" - in str(err.value) - ) + assert "Only one position of type 'closed' is allowed!" in str(err.value) def test_validate_dates(nvidia): strategy = [{"type": "closed", "prev_pos": 100}] inputs = nvidia | { - 'start_date': dt.date(2023, 1, 14), - 'target_date': dt.date(2023, 1, 10), + "start_date": dt.date(2023, 1, 14), + "target_date": dt.date(2023, 1, 10), "strategy": strategy, } @@ -36,8 +35,8 @@ def test_validate_dates(nvidia): assert "Start date must be before target date!" in str(err.value) inputs = nvidia | { - 'start_date': dt.date(2023, 1, 14), - 'target_date': dt.date(2023, 1, 17), + "start_date": dt.date(2023, 1, 14), + "target_date": dt.date(2023, 1, 17), "strategy": [ { "type": "call", @@ -56,23 +55,25 @@ def test_validate_dates(nvidia): assert "Expiration dates must be after or on target date!" in str(err.value) inputs = nvidia | { - 'start_date': None, - 'target_date': None, - 'days_to_target_date': 30, - 'strategy': [ - {"type": "stock", "n": 100, "action": "buy"}, - { - "type": "call", - "strike": 185.0, - "premium": 4.1, - "n": 100, - "action": "sell", - "expiration": dt.date(2023, 1, 17), - }, - ], - } + "start_date": None, + "target_date": None, + "days_to_target_date": 30, + "strategy": [ + {"type": "stock", "n": 100, "action": "buy"}, + { + "type": "call", + "strike": 185.0, + "premium": 4.1, + "n": 100, + "action": "sell", + "expiration": dt.date(2023, 1, 17), + }, + ], + } with pytest.raises(ValueError) as err: Inputs.model_validate(inputs) - assert "You can't mix a strategy expiration with a days_to_target_date." in str(err.value) + assert "You can't mix a strategy expiration with a days_to_target_date." in str( + err.value + )