Skip to content

Commit

Permalink
lfs
Browse files Browse the repository at this point in the history
  • Loading branch information
dguittet committed Jan 12, 2023
1 parent 6d05d38 commit a06e233
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 228,439 deletions.
Empty file added dispatches/tests/__init__.py
Empty file.
Empty file.
8,788 changes: 3 additions & 8,785 deletions dispatches/tests/data/prescient_5bus/DAY_AHEAD_load.csv

Large diffs are not rendered by default.

8,788 changes: 3 additions & 8,785 deletions dispatches/tests/data/prescient_5bus/DAY_AHEAD_renewables.csv

Large diffs are not rendered by default.

105,412 changes: 3 additions & 105,409 deletions dispatches/tests/data/prescient_5bus/REAL_TIME_load.csv

Large diffs are not rendered by default.

105,412 changes: 3 additions & 105,409 deletions dispatches/tests/data/prescient_5bus/REAL_TIME_renewables.csv

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions dispatches/tests/data/prescient_5bus/branch.csv
Git LFS file not shown
9 changes: 3 additions & 6 deletions dispatches/tests/data/prescient_5bus/bus.csv
Git LFS file not shown
12 changes: 3 additions & 9 deletions dispatches/tests/data/prescient_5bus/gen.csv
Git LFS file not shown
6 changes: 3 additions & 3 deletions dispatches/tests/data/prescient_5bus/initial_status.csv
Git LFS file not shown
4 changes: 3 additions & 1 deletion dispatches/tests/data/prescient_5bus/reserves.csv
Git LFS file not shown
10 changes: 3 additions & 7 deletions dispatches/tests/data/prescient_5bus/simulation_objects.csv
Git LFS file not shown
20 changes: 3 additions & 17 deletions dispatches/tests/data/prescient_5bus/timeseries_pointers.csv
Git LFS file not shown
70 changes: 70 additions & 0 deletions dispatches/tests/test_headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#################################################################################
# DISPATCHES was produced under the DOE Design Integration and Synthesis
# Platform to Advance Tightly Coupled Hybrid Energy Systems program (DISPATCHES),
# and is copyright (c) 2022 by the software owners: The Regents of the University
# of California, through Lawrence Berkeley National Laboratory, National
# Technology & Engineering Solutions of Sandia, LLC, Alliance for Sustainable
# Energy, LLC, Battelle Energy Alliance, LLC, University of Notre Dame du Lac, et
# al. All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. Both files are also available online at the URL:
# "https://github.com/gmlc-dispatches/dispatches".
#
#################################################################################
"""
Test that headers are on all files
"""
# stdlib
from pathlib import Path
import os

import pytest

pytest.importorskip("addheader", reason="addheader (optional dev. dependency) not available")

# third-party
from addheader.add import FileFinder, detect_files
import yaml


@pytest.fixture
def package_root():
"""Determine package root.
"""
import dispatches
return Path(dispatches.__file__).parent


@pytest.fixture
def patterns(package_root):
"""Grab glob patterns from config file.
"""
conf_file = package_root.parent / ".addheader.yml"
if not conf_file.exists():
print(f"Cannot load configuration file from '{conf_file}'. Perhaps this is not development mode?")
return None
with open(conf_file) as f:
conf_data = yaml.safe_load(f)
print(f"Patterns for finding files with headers: {conf_data['patterns']}")
return conf_data["patterns"]


@pytest.mark.unit
def test_headers(package_root, patterns):
if patterns is None:
print(f"ERROR: Did not get glob patterns: skipping test")
else:
# modify patterns to match the files that should have headers
ff = FileFinder(package_root, glob_patterns=patterns)
has_header, missing_header = detect_files(ff)
# ignore empty files (probably should add option in 'detect_files' for this)
nonempty_missing_header = list(filter(lambda p: p.stat().st_size > 0, missing_header))
#
if len(nonempty_missing_header) > 0:
pfx = str(package_root.resolve())
pfx_len = len(pfx)
file_list = ", ".join([str(p)[pfx_len + 1:] for p in nonempty_missing_header])
print(f"Missing headers from files under '{pfx}{os.path.sep}': {file_list}")
# uncomment to require all files to have headers
assert len(nonempty_missing_header) == 0
102 changes: 102 additions & 0 deletions dispatches/tests/test_prescient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#################################################################################
# DISPATCHES was produced under the DOE Design Integration and Synthesis
# Platform to Advance Tightly Coupled Hybrid Energy Systems program (DISPATCHES),
# and is copyright (c) 2022 by the software owners: The Regents of the University
# of California, through Lawrence Berkeley National Laboratory, National
# Technology & Engineering Solutions of Sandia, LLC, Alliance for Sustainable
# Energy, LLC, Battelle Energy Alliance, LLC, University of Notre Dame du Lac, et
# al. All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. Both files are also available online at the URL:
# "https://github.com/gmlc-dispatches/dispatches".
#
#################################################################################

import importlib
from numbers import Number
from pathlib import Path
from typing import Dict, Union, List

import pytest
import pandas as pd


prescient_simulator = pytest.importorskip("prescient.simulator", reason="Prescient (gridx-prescient) not available")


@pytest.fixture(scope="module")
def base_dir() -> Path:
pkg_init_path = Path(importlib.util.find_spec("dispatches.tests.data").origin)
return pkg_init_path.parent


# define custom type for type hinting
PrescientOptions = Dict[str, Union[str, bool, Number, dict]]


class Test5Bus:
"Simple test using 5bus use case"

@pytest.fixture
def data_path(self, base_dir: Path) -> Path:
return base_dir / "prescient_5bus"

@pytest.mark.unit
def test_data_path_available(self, data_path: Path):
assert data_path.is_dir()

@pytest.fixture
def output_dir(self, tmp_path: Path) -> Path:
path = tmp_path / "5bus_output"
path.mkdir()
return path

@pytest.fixture
def prescient_options(self, data_path: Path, output_dir: Path) -> PrescientOptions:
return {
"data_path": str(data_path),
"input_format":"rts-gmlc",
"simulate_out_of_sample":True,
"run_sced_with_persistent_forecast_errors":True,
"output_directory": str(output_dir),
"start_date":"07-10-2020",
"num_days":2,
"sced_horizon":1,
"ruc_mipgap":0.01,
"reserve_factor":0.1,
"deterministic_ruc_solver":"cbc",
"deterministic_ruc_solver_options":{"feas":"off", "DivingF":"on",},
"sced_solver":"cbc",
"sced_frequency_minutes":60,
"ruc_horizon":36,
"compute_market_settlements":True,
"monitor_all_contingencies":False,
"output_solver_logs":False,
"price_threshold":1000,
"contingency_price_threshold":100,
"reserve_price_threshold":5,
}

@pytest.fixture
def run_simulator(self, prescient_options: PrescientOptions) -> None:
from prescient.simulator import Prescient

sim = Prescient()
sim.simulate(**prescient_options)

@pytest.fixture
def simulation_results_table(
self,
run_simulator,
output_dir: Path,
name: str = "overall_simulation_output.csv"
) -> pd.DataFrame:

path = output_dir / name
return pd.read_csv(path)

@pytest.mark.component
# TODO use a more specific test to validate simulation output
def test_simulation_results(self, simulation_results_table: pd.DataFrame):
assert not simulation_results_table.empty

0 comments on commit a06e233

Please sign in to comment.