Skip to content

Commit

Permalink
Add testing for hvac diagram, call PythonPlugin file from Python API, f…
Browse files Browse the repository at this point in the history
…ixes #17 and fixes #19
  • Loading branch information
Myoldmopar committed Oct 8, 2021
1 parent 18b6ed1 commit 72e6b2d
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
7 changes: 5 additions & 2 deletions ep_testing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def __init__(self, run_config_key, msvc_version=None):
self.tag_last_version = 'v9.5.0'

# If this is turned on, it expects to find an asset already downloaded at the specified location
self.skip_download = False
self.skipped_download_file = '/tmp/ep.tar.gz'
self.skip_download = True
if self.os == OS.Windows:
self.skipped_download_file = 'C:/tmp/ep.zip'
else:
self.skipped_download_file = '/tmp/ep.tar.gz'

# But if we are on Travis, we override it to always download a new asset
if os.environ.get('TRAVIS'):
Expand Down
7 changes: 5 additions & 2 deletions ep_testing/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os
import requests
import shutil
from subprocess import check_call, CalledProcessError
from subprocess import check_call, CalledProcessError, STDOUT
import urllib.request

from ep_testing.exceptions import EPTestingException
Expand Down Expand Up @@ -137,7 +137,10 @@ def _extract_asset(self) -> str:
except Exception as e:
raise EPTestingException('Could not create extraction path at %s; error: %s' % (self.extract_path, str(e)))
try:
check_call(self.extract_command)
self._my_print("Extracting asset...")
dev_null = open(os.devnull, 'w')
check_call(self.extract_command, stdout=dev_null, stderr=STDOUT)
self._my_print(" ...Extraction Complete")
except CalledProcessError as e:
raise EPTestingException("Extraction failed with this error: " + str(e))
# should result in a single new directory inside the extract path, like: /extract/path/EnergyPlus-V1-abc-Linux
Expand Down
10 changes: 5 additions & 5 deletions ep_testing/tester.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from tempfile import mkdtemp

from ep_testing.config import TestConfiguration, OS
from ep_testing.tests.api import TestPythonAPIAccess, TestCAPIAccess, TestCppAPIDelayedAccess
from ep_testing.tests.energyplus import TestPlainDDRunEPlusFile
from ep_testing.tests.expand_objects import TestExpandObjectsAndRun
from ep_testing.tests.hvacdiagram import HVACDiagram
from ep_testing.tests.transition import TransitionOldFile


Expand All @@ -17,9 +17,6 @@ def __init__(self, config: TestConfiguration, install_path: str, verbose: bool):

def run(self):
saved_path = os.getcwd()
temp_dir = mkdtemp()
print('Creating sandbox dir and changing to it: ' + temp_dir)
os.chdir(temp_dir)
TestPlainDDRunEPlusFile().run(
self.install_path, self.verbose, {'test_file': '1ZoneUncontrolled.idf'}
)
Expand All @@ -32,6 +29,9 @@ def run(self):
TransitionOldFile().run(
self.install_path, self.verbose, {'last_version': self.config.tag_last_version}
)
HVACDiagram().run(
self.install_path, self.verbose, {}
)
if self.config.os == OS.Windows:
print("Windows Symlink runs are not testable on Travis, I think the user needs symlink privilege.")
else:
Expand All @@ -49,7 +49,7 @@ def run(self):
if self.config.bitness == 'x32':
print("Travis does not have a 32-bit Python package readily available, so not testing Python API")
elif self.config.os == OS.Mac and self.config.os_version == '10.14':
print("E+ technically supports 10.15, but most things work on 10.14. Not Python API though, skipping that.")
print("E+ technically supports 10.15, and most things work on 10.14. Not Python API though, skipping that.")
else:
TestPythonAPIAccess().run(
self.install_path, self.verbose, {'os': self.config.os}
Expand Down
3 changes: 2 additions & 1 deletion ep_testing/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
my_env = os.environ.copy()
if self.os == OS.Windows: # my local comp didn't have cmake in path except in interact shells
my_env["PATH"] = install_root + ";" + my_env["PATH"]
my_check_call(self.verbose, [py, python_file_path], env=my_env)
idf_to_run = os.path.join(install_root, 'ExampleFiles', 'PythonPluginCustomOutputVariable.idf')
my_check_call(self.verbose, [py, python_file_path, '-D', idf_to_run], env=my_env)
print(' [DONE]!')
except EPTestingException as e:
print('Python API Wrapper Script failed!')
Expand Down
3 changes: 3 additions & 0 deletions ep_testing/tests/api_templates/python_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@
for t in [5.0, 15.0, 25.0]:
cp = glycol.specific_heat(state, t)
rho = glycol.density(state, t)
state2 = api.state_manager.new_state()
api.runtime.set_console_output_status(state2, False)
sys.exit(api.runtime.run_energyplus(state2, sys.argv[1:]))
7 changes: 7 additions & 0 deletions ep_testing/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from os import chdir
from tempfile import mkdtemp


class BaseTest:

def __init__(self):
self.verbose = False
temp_dir = mkdtemp()
print('{Sandbox Dir: \"' + temp_dir + '\"} ', end='')
chdir(temp_dir)

def name(self):
raise NotImplementedError('name() must be overridden by derived classes')
Expand Down
32 changes: 32 additions & 0 deletions ep_testing/tests/hvacdiagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
from subprocess import check_call, CalledProcessError, STDOUT

from ep_testing.exceptions import EPTestingException
from ep_testing.tests.base import BaseTest


class HVACDiagram(BaseTest):

def name(self):
return 'Test running 5ZoneAirCooled.idf, then HVACDiagram and make sure the SVG is created'

def run(self, install_root: str, verbose: bool, kwargs: dict):
idf_path = os.path.join(install_root, 'ExampleFiles', '5ZoneAirCooled.idf')
print('* Running test class "%s" on file "%s"... ' % (self.__class__.__name__, '5ZoneAirCooled.idf'), end='')
eplus_binary = os.path.join(install_root, 'energyplus')
dev_null = open(os.devnull, 'w')
try:
check_call([eplus_binary, '-D', idf_path], stdout=dev_null, stderr=STDOUT)
print(' [E+ FINISHED] ', end='')
except CalledProcessError:
raise EPTestingException('EnergyPlus failed!')
hvac_diagram_binary = os.path.join(install_root, 'PostProcess', 'HVAC-Diagram')
try:
check_call([hvac_diagram_binary], stdout=dev_null, stderr=STDOUT)
print(' [HVAC DIAGRAM FINISHED] ', end='')
except CalledProcessError:
raise EPTestingException('Transition failed!')
if os.path.exists('eplusout.svg'):
print(' [SVG FILE EXISTS] [DONE]!')
else:
raise EPTestingException('SVG Did not exist!')

0 comments on commit 72e6b2d

Please sign in to comment.