Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: create tests for grid equality #183

Merged
merged 2 commits into from
May 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 88 additions & 4 deletions powersimdata/input/tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import pandas as pd
import pytest
import unittest
import copy

from powersimdata.input.usa_tamu_model import check_interconnect
Expand Down Expand Up @@ -213,10 +214,92 @@ def test_link():
assert np.array_equal(output['c'], values[2])


def test_deepcopy_works():
g = Grid(['Texas'])
copied_grid = copy.deepcopy(g)
assert isinstance(copied_grid, Grid)
@pytest.fixture(scope="session")
def base_texas():
return Grid(['Texas'])


@pytest.fixture(scope="session")
def base_western():
return Grid(['Western'])


def test_deepcopy_works(base_texas):
assert isinstance(copy.deepcopy(base_texas), Grid)


def test_grid_eq_success_simple(base_texas):
assert base_texas == Grid(['Texas'])


def test_grid_eq_failure_simple(base_texas, base_western):
assert base_texas != base_western


def test_grid_eq_failure_bus(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.bus.baseKV.iloc[0] *= 2
assert base_texas != test_grid


def test_grid_eq_success_bus_type(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.bus.type = 1
assert base_texas == test_grid


def test_grid_eq_failure_branch(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.branch.rateA.iloc[0] *= 2
assert base_texas != test_grid


def test_grid_eq_failure_dcline(base_western):
test_grid = copy.deepcopy(base_western)
test_grid.dcline.Pmax.iloc[0] *= 2
assert base_western != test_grid


def test_grid_eq_failure_gencost_before(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.gencost['before'].n.iloc[0] += 1
assert base_texas != test_grid


def test_grid_eq_success_gencost_after(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.gencost['after'] = test_grid.gencost['after'].drop(
test_grid.gencost['after'].tail(1).index)
assert base_texas == test_grid


def test_grid_eq_failure_plant(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.plant.Pmax.iloc[0] *= 2
assert base_texas != test_grid


def test_grid_eq_success_plant_ramp30(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.plant.ramp_30.iloc[0] *= 2
assert base_texas == test_grid


def test_grid_eq_failure_sub(base_texas):
test_grid = copy.deepcopy(base_texas)
test_grid.sub.name.iloc[0] = test_grid.sub.name.iloc[0][::-1]
assert base_texas != test_grid


def test_grid_eq_failure_storage(base_texas):
test_grid = copy.deepcopy(base_texas)
gencost = {g: 0 for g in test_grid.storage['gencost'].columns}
gen = {g: 0 for g in test_grid.storage['gen'].columns}
test_grid.storage['gencost'] = test_grid.storage['gencost'].append(
gencost, ignore_index=True)
test_grid.storage['gen'] = test_grid.storage['gen'].append(
gen, ignore_index=True)
assert base_texas != test_grid


def test_that_fields_are_not_modified_when_loading_another_grid():
Expand All @@ -225,6 +308,7 @@ def test_that_fields_are_not_modified_when_loading_another_grid():
eastern_grid = Grid(['Eastern'])
assert western_plant_original_shape == western_grid.plant.shape


def test_that_fields_can_be_modified_with_conventional_syntax():
grid = Grid(['Texas'])
grid.plant = grid.plant.append(grid.plant.iloc[0:4])
Expand Down