Skip to content

Commit

Permalink
Fix CLI and add test. (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
lymereJ authored May 20, 2023
1 parent 39a33be commit 9bf77cf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
/build/
/dev/
/bin/
/dist/
/dist/
*.pyc
*pytest_cache
13 changes: 10 additions & 3 deletions copper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,33 @@
"""

import click, json, inspect
import copper.chiller as chiller

# import copper.Chiller as chiller
from copper.chiller import Chiller


@click.group()
def cli():
"""
Command Line Interface for Copper
Copper
A performance curve generator for building energy simulation
"""


@cli.command()
@click.argument("input_file", type=click.File("rb"), required=True)
def run(input_file):
"""Run a set of Copper instructions through a JSON input file. See 'Using Copper's command line interface in the Quickstart Guide section of the documenation for more information."""
try:
f = json.load(input_file)
except:
raise ValueError("Could not read the input file. A JSON file is expected.")
for eqp, eqp_props in f.items():
# Make sure that the equipment is supported by Copper
assert eqp_props["eqp_type"].lower() in ["chiller"]
assert eqp_props["eqp_type"].lower() in [
"chiller"
], "Equipment type not currently supported by Copper."

# Get properties for equipment type
eqp_type_props = inspect.getfullargspec(eval(eqp_props["eqp_type"]).__init__)[0]
Expand Down
29 changes: 29 additions & 0 deletions tests/data/cli_input_file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"Quickstart_Guide_Chiller":{
"eqp_type":"Chiller",
"compressor_type":"screw",
"condenser_type":"water",
"compressor_speed":"constant",
"ref_cap":300,
"ref_cap_unit":"ton",
"full_eff":0.61,
"full_eff_unit":"kw/ton",
"part_eff":0.52,
"part_eff_unit":"kw/ton",
"sim_engine":"energyplus",
"model":"ect_lwt",
"do":{
"generate_set_of_curves":{
"vars":[
"eir-f-plr"
],
"method":"nearest_neighbor",
"tol":0.05,
"export_path":"./",
"export_format":"json",
"export_name":"Quickstart_Guide_Chiller",
"random_seed":1
}
}
}
}
16 changes: 16 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import click, logging
from click.testing import CliRunner
from copper.cli import run


def test_cli_incorrect_file():
runner = CliRunner()
result = runner.invoke(run, ["test"])
assert "'test': No such file or directory" in result.output


def test_cli_correct(caplog):
caplog.set_level(logging.INFO)
runner = CliRunner()
result = runner.invoke(run, ["./tests/data/cli_input_file.json"])
assert "Target met after 13 generations."

0 comments on commit 9bf77cf

Please sign in to comment.