Skip to content

Commit

Permalink
Added a test for cli call to convert_results
Browse files Browse the repository at this point in the history
  • Loading branch information
willu47 committed Jun 20, 2023
1 parent 2729b45 commit ba4ac35
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/otoole/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ def validate_model(args):
def _result_matrix(args):
convert_results(
args.config,
args.input_datapackage,
args.input_csvs,
args.input_datafile,
args.to_path,
args.from_path,
args.from_format,
args.to_format,
args.write_defaults,
args.from_path,
args.to_path,
input_datapackage=args.input_datapackage,
input_csvs=args.input_csvs,
input_datafile=args.input_datafile,
write_defaults=args.write_defaults,
)


Expand All @@ -126,7 +126,8 @@ def _conversion_matrix(args):
args.to_format,
args.from_path,
args.to_path,
args.write_defaults,
write_defaults=args.write_defaults,
keep_whitespace=args.keep_whitespace,
)


Expand Down Expand Up @@ -222,9 +223,14 @@ def get_parser():
help="Input GNUMathProg datafile required for OSeMOSYS short or fast results",
default=None,
)
result_parser.add_argument(
"--input_csvs",
help="Input folder of CSVs required for OSeMOSYS short or fast results",
default=None,
)
result_parser.add_argument(
"--input_datapackage",
help="Deprecated",
help="Deprecated. Use --input_csvs instead",
default=None,
)
result_parser.add_argument("config", help="Path to config YAML file")
Expand Down
29 changes: 29 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,35 @@
from otoole import __version__


class TestResults:
"""Test the conversion of results via the command line interface"""

def test_convert_results(self):
"""Test converting CBC solution file to folder of CSVs"""
config = os.path.join("tests", "fixtures", "super_simple", "super_simple.yaml")
super_simple_csvs = os.path.join("tests", "fixtures", "super_simple", "csv")
from_format = "cbc"
to_format = "csv"
from_path = os.path.join(
"tests", "fixtures", "super_simple", "super_simple_gnu.sol"
)
to_path = mkdtemp()
commands = [
"otoole",
"results",
from_format,
to_format,
from_path,
to_path,
config,
"--input_csvs",
super_simple_csvs,
]
actual = run(commands, capture_output=True)
assert actual.returncode == 0, print(actual.stdout)
assert os.path.exists(os.path.join(to_path, "NewCapacity.csv"))


class TestConvert:
def test_version(self):
result = run(["otoole", "--version"], capture_output=True)
Expand Down

0 comments on commit ba4ac35

Please sign in to comment.