Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rwijtvliet committed Nov 1, 2024
1 parent cfa1ab3 commit 360413d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 49 deletions.
2 changes: 1 addition & 1 deletion portfolyo/core/pfline/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def _union(inop1: InOp, inop2: InOp) -> InOp:
return InOp(**kwargs)


def _equal(inop1: InOp, inop2: InOp) -> InOp:
def _equal(inop1: InOp, inop2: InOp) -> bool:
"""2 ``InOp`` objects are equal if they have the same attributes."""
if not isinstance(inop2, InOp):
return False
Expand Down
74 changes: 26 additions & 48 deletions tests/core/pfline/test_interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@
),
(
Q_(120e-3, "GW"),
io.InOp(w=Q_(120.0, "MW")),
ValueError,
),
(
Q_(432e9, "J/h"),
io.InOp(w=Q_(120.0, "MW")),
io.InOp(w=Q_(120.0e-3, "GW")),
ValueError,
),
(
Expand All @@ -56,7 +51,7 @@
),
(
Q_(90.0, "GWh"),
io.InOp(q=Q_(90_000.0, "MWh")),
io.InOp(q=Q_(90.0, "GWh")),
ValueError,
),
(
Expand All @@ -66,7 +61,7 @@
),
(
Q_(5.0, "ctEur/kWh"),
io.InOp(p=Q_(50.0, "Eur/MWh")),
io.InOp(p=Q_(5.0, "ctEur/kWh")),
ValueError,
),
(
Expand All @@ -76,7 +71,7 @@
),
(
Q_(4.5, "MEur"),
io.InOp(r=Q_(4_500_000.0, "Eur")),
io.InOp(r=Q_(4.5, "MEur")),
ValueError,
),
# . unknown unit
Expand All @@ -86,7 +81,7 @@
None,
),
# One or several values
# . name but no unit
# . key but no unit
(
{"nodim": 120.0},
io.InOp(nodim=120),
Expand Down Expand Up @@ -177,7 +172,7 @@
DimensionalityError,
None,
),
# . name and correct unit
# . key and correct unit
(
{"p": Q_(50.0, "Eur/MWh")},
io.InOp(p=Q_(50.0, "Eur/MWh")),
Expand Down Expand Up @@ -210,23 +205,20 @@
),
(
{"w": 120.0, "q": Q_(-90_000.0, "MWh")},
# io.InOp(w=120.0, q=-90_000),
DimensionalityError,
None,
),
(
pd.Series({"w": 120.0, "q": Q_(-90_000.0, "MWh")}),
# io.InOp(w=120.0, q=-90_000),
DimensionalityError,
None,
),
(
pd.Series({"w": 120.0, "q": Q_(-90.0, "GWh")}),
# io.InOp(w=120.0, q=-90_000),
DimensionalityError,
None,
),
# . unknown name -> KeyError
# . unknown key -> KeyError
(
{"z": 28.0},
KeyError,
Expand All @@ -247,13 +239,13 @@
KeyError,
None,
),
# . mix of know and unknown names -> KeyError
# . mix of know and unknown key -> KeyError
(
{"w": 120.0, "z": 28.0},
DimensionalityError,
None,
),
( # depends on what columnt we get firat
( # depends on what columnt we get first
pd.Series({"w": 120.0, "z": 28.0}),
DimensionalityError,
None,
Expand All @@ -268,7 +260,7 @@
KeyError,
None,
),
# . combination of name with incorrect unit -> error
# . combination of key with incorrect unit -> error
(
{"w": Q_(90.0, "MWh")},
AttributeError,
Expand Down Expand Up @@ -304,20 +296,15 @@
io.InOp(w=s1.astype("pint[MW]")),
),
(
(s1 / 1000).astype("pint[GW]"), # series with pint unit
io.InOp(w=s1.astype("pint[MW]")),
io.InOp(w=s1.astype("pint[MW]")),
s1.astype("pint[GW]"), # series with pint unit
io.InOp(w=s1.astype("pint[GW]")),
io.InOp(w=s1.astype("pint[GW]")),
),
(
pd.Series([Q_(v, "MW") for v in val1], idx1), # series of Quantities
io.InOp(w=s1.astype("pint[MW]")),
io.InOp(w=s1.astype("pint[MW]")),
),
(
s1.astype("pint[GWh]"),
io.InOp(q=s1.astype("pint[MWh]") * 1000),
io.InOp(q=s1.astype("pint[MWh]") * 1000),
),
(
s1.astype("pint[Eur/MWh]"),
io.InOp(p=s1.astype("pint[Eur/MWh]")),
Expand All @@ -335,7 +322,7 @@
None,
),
# One or several timeseries
# . name but no unit
# . key but no unit
(
{"w": s1},
DimensionalityError,
Expand Down Expand Up @@ -386,7 +373,7 @@
DimensionalityError,
None,
),
# . name and correct unit
# . key and correct unit
(
{"p": s1.astype("pint[Eur/MWh]")},
io.InOp(p=s1.astype("pint[Eur/MWh]")),
Expand Down Expand Up @@ -432,7 +419,7 @@
io.InOp(w=s1_u.astype("pint[MW]"), q=s2_u.astype("pint[MWh]") * 1000),
io.InOp(w=s1_u.astype("pint[MW]"), q=s2_u.astype("pint[MWh]") * 1000),
),
# . unknown name -> KeyError
# . unknown key -> KeyError
(
{"z": s1},
KeyError,
Expand All @@ -453,7 +440,7 @@
KeyError,
None,
),
# . mix of know and unknown names -> KeyError
# . mix of know and unknown keys -> KeyError
(
{"z": s2, "w": s1},
KeyError,
Expand All @@ -474,7 +461,7 @@
KeyError,
None,
),
# . combination of name with incorrect unit -> error
# . combination of key with incorrect unit -> error
(
{"w": s1.astype("pint[MWh]")},
DimensionalityError,
Expand Down Expand Up @@ -506,40 +493,35 @@
None,
),
# Combinations of value(s) and timeseries.
# . name but no unit
# . all have key but no unit
(
{"w": s1, "p": 50.0},
DimensionalityError,
None,
),
(
{"q": -s1, "p": 50.0, "r": s2},
DimensionalityError,
None,
),
# . name and correct unit
# . at least one has key but no unit
(
{"w": s1.astype("pint[MW]"), "p": 50.0},
DimensionalityError,
None,
),
(
{"w": s1.astype("pint[MW]"), "q": s2.astype("pint[MWh ]"), "p": 50},
{"w": s1.astype("pint[MW]"), "q": s2.astype("pint[MWh]"), "p": 50},
DimensionalityError,
None,
),
(
{"r": s1.astype("pint[MEur]"), "p": 50.0, "q": 90_000},
{"w": s1, "p": Q_(50.0, "Eur/MWh")},
DimensionalityError,
None,
),
# . unknown name -> KeyError
# . unknown key -> KeyError
(
{"z": s1, "xy": 50},
KeyError,
None,
),
# . mix of know and unknown names -> KeyError
# . mix of know and unknown keys -> KeyError
(
{"z": s1, "p": 50.0},
KeyError,
Expand All @@ -555,23 +537,19 @@
KeyError,
None,
),
# ( # exclude: not a valid dataframe contructor
# pd.DataFrame({"w": s1, "p": Q_(5.0, "ctEur/kWh"), "z": s2}),
# io.InterOp(w=s1, p=50, rest=({"z": s2},)),
# ),
(
pd.DataFrame({"w": s1.astype("pint[GW]"), "z": s2}),
KeyError,
None,
),
# . combination of name with incorrect unit -> error
# . combination of key with (at least one) incorrect dimension -> error
(
{"w": s1.astype("pint[MWh]"), "p": Q_(50.0, "MW")},
DimensionalityError,
None,
),
(
{"p": s1.astype("pint[MWh]"), "w": 120.0},
{"p": s1.astype("pint[MWh]"), "w": Q_(120.0, "MW")},
DimensionalityError,
None,
),
Expand Down

0 comments on commit 360413d

Please sign in to comment.