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

Adding a command line interface #31

Merged
merged 3 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
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
23 changes: 23 additions & 0 deletions hpxml_version_translator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import argparse
from hpxml_version_translator.converter import convert_hpxml2_to_3
import sys


def main(argv=sys.argv[1:]):
parser = argparse.ArgumentParser(description='HPXML Version Translator, convert an HPXML v2.x file to 3.0')
parser.add_argument(
'hpxml_input',
help='Filename of hpxml v2.x file'
)
parser.add_argument(
'-o', '--output',
type=argparse.FileType('wb'),
default=sys.stdout.buffer,
help='Filename of output HPXML v3 file. If not provided, will go to stdout'
)
args = parser.parse_args(argv)
convert_hpxml2_to_3(args.hpxml_input, args.output)


if __name__ == '__main__':
main()
3 changes: 3 additions & 0 deletions hpxml_version_translator/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import main

main()
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
]
},
python_requires='>=3.6',
entry_points={
'console_scripts': [
'hpxml_version_translator=hpxml_version_translator:main'
]
}
)
17 changes: 17 additions & 0 deletions test/test_converter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import io
from lxml import objectify
import pathlib
import pytest
import tempfile

from hpxml_version_translator.converter import convert_hpxml2_to_3
from hpxml_version_translator import exceptions as exc
from hpxml_version_translator import main


hpxml_dir = pathlib.Path(__file__).resolve().parent / 'hpxml_files'
Expand Down Expand Up @@ -613,6 +615,21 @@ def test_deprecated_items():
assert wh2.AnnualEnergyUse.ConsumptionInfo.ConsumptionDetail.Consumption == 600


def test_cli(capsysbinary):
with tempfile.TemporaryDirectory() as tmpdir:
tmppath = pathlib.Path(tmpdir).resolve()
input_filename = str(hpxml_dir / 'version_change.xml')
output_filename = str(tmppath / 'out.xml')
main([input_filename, '-o', output_filename])
root = objectify.parse(output_filename).getroot()
assert root.attrib['schemaVersion'] == '3.0'

main([input_filename])
f = io.BytesIO(capsysbinary.readouterr().out)
root = objectify.parse(f).getroot()
assert root.attrib['schemaVersion'] == '3.0'


def test_desuperheater_flexibility():
root = convert_hpxml_and_parse(hpxml_dir / 'desuperheater_flexibility.xml')

Expand Down