Skip to content

Commit

Permalink
added tests for longify data
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Aug 22, 2023
1 parent c413ae6 commit 28dcf28
Showing 1 changed file with 41 additions and 2 deletions.
43 changes: 41 additions & 2 deletions tests/test_read_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from pytest import mark, raises

from otoole.exceptions import OtooleDeprecationError, OtooleError

# from otoole.preprocess.longify_data import check_datatypes
from otoole.preprocess.longify_data import check_datatypes
from otoole.read_strategies import ReadCsv, ReadDatafile, ReadExcel, ReadMemory
from otoole.results.results import (
ReadCbc,
Expand Down Expand Up @@ -1164,3 +1163,43 @@ def test_whitespace_converter(
reader = ReadCsv(user_config=user_config, keep_whitespace=keep_whitespace)
actual = reader._whitespace_converter(indices)
assert actual == expected


class TestLongifyData:
"""Tests for the preprocess.longify_data module"""

# example availability factor data
data_valid = pd.DataFrame(
[
["SIMPLICITY", "ETH", 2014, 1.0],
["SIMPLICITY", "RAWSUG", 2014, 0.5],
["SIMPLICITY", "ETH", 2015, 1.03],
["SIMPLICITY", "RAWSUG", 2015, 0.51],
["SIMPLICITY", "ETH", 2016, 1.061],
["SIMPLICITY", "RAWSUG", 2016, 0.519],
],
columns=["REGION", "FUEL", "YEAR", "VALUE"],
)

data_invalid = pd.DataFrame(
[
["SIMPLICITY", "ETH", "invalid", 1.0],
["SIMPLICITY", "RAWSUG", 2014, 0.5],
],
columns=["REGION", "FUEL", "YEAR", "VALUE"],
)

def test_check_datatypes_valid(self, user_config):
df = self.data_valid.astype(
{"REGION": str, "FUEL": str, "YEAR": int, "VALUE": float}
)
actual = check_datatypes(df, user_config, "AvailabilityFactor")
expected = df.copy()

pd.testing.assert_frame_equal(actual, expected)

def test_check_datatypes_invalid(self, user_config):
df = self.data_invalid

with raises(ValueError):
check_datatypes(df, user_config, "AvailabilityFactor")

0 comments on commit 28dcf28

Please sign in to comment.