Skip to content

Commit

Permalink
blacked tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marc committed Mar 10, 2024
1 parent 1136d06 commit 0c7bd8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 31 deletions.
11 changes: 5 additions & 6 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from optionlab.models import Inputs, Outputs
from optionlab.strategy import StrategyEngine
import datetime as dt


def test_covered_call(nvidia):
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -121,7 +120,7 @@ def test_100_perc_itm(nvidia):
nvidia
| {
# The covered call strategy is defined
'strategy': [
"strategy": [
{
"type": "call",
"strike": 165.0,
Expand Down
51 changes: 26 additions & 25 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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):

Expand All @@ -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,
}

Expand All @@ -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",
Expand All @@ -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
)

0 comments on commit 0c7bd8c

Please sign in to comment.