Skip to content

Commit

Permalink
Cleaning up testing codebase, still more to do
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Apr 3, 2024
1 parent 040ee1d commit 0e6c542
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 171 deletions.
67 changes: 0 additions & 67 deletions scripts/package_tests/ep_testing/downloader.py

This file was deleted.

58 changes: 0 additions & 58 deletions scripts/package_tests/ep_testing/exceptions.py

This file was deleted.

27 changes: 13 additions & 14 deletions scripts/package_tests/ep_testing/tests/api.py
Expand Up @@ -62,7 +62,6 @@
from typing import List

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


Expand All @@ -78,7 +77,7 @@ def my_check_call(verbose: bool, command_line: List[str], **kwargs) -> None:
r = subprocess.run(command_line,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
if r.returncode != 0:
raise EPTestingException(
raise Exception(
f'Command {command_line} failed with exit status {r.returncode}!\n'
'stderr:\n'
f'{r.stderr.decode().strip()}'
Expand Down Expand Up @@ -113,7 +112,7 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
print('* Running test class "%s"... ' % self.__class__.__name__, end='')
if 'os' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
self.os = kwargs['os']
handle, python_file_path = mkstemp(suffix='.py')
with os.fdopen(handle, 'w') as f:
Expand All @@ -139,7 +138,7 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
idf_to_run = os.path.join(install_root, 'ExampleFiles', '1ZoneUncontrolled.idf') # PythonPluginCustomOutputVariable
my_check_call(self.verbose, [py, python_file_path, '-D', idf_to_run], env=my_env)
print(' [DONE]!')
except EPTestingException as e:
except Exception as e:
print('Python API Wrapper Script failed!')
raise e

Expand All @@ -153,7 +152,7 @@ def make_build_dir_and_build(cmake_build_dir: str, verbose: bool, this_os: int,
command_line = ['cmake', '..']
if this_os == OS.Windows:
if bitness not in ['x32', 'x64']:
raise EPTestingException('Bad bitness sent to make_build_dir_and_build, should be x32 or x64')
raise Exception('Bad bitness sent to make_build_dir_and_build, should be x32 or x64')
if msvc_version == 15:
if bitness == 'x64':
command_line.extend(['-G', 'Visual Studio 15 Win64'])
Expand All @@ -171,15 +170,15 @@ def make_build_dir_and_build(cmake_build_dir: str, verbose: bool, this_os: int,
elif bitness == 'x32':
command_line.extend(['-G', 'Visual Studio 17 2022', '-A', 'x86'])
else:
raise EPTestingException("Unknown msvc_version passed to make_build_dir_and_build")
raise Exception("Unknown msvc_version passed to make_build_dir_and_build")

my_check_call(verbose, command_line, cwd=cmake_build_dir, env=my_env)
command_line = ['cmake', '--build', '.']
if platform.system() == 'Windows':
command_line.extend(['--config', 'Release'])
my_check_call(verbose, command_line, env=my_env, cwd=cmake_build_dir)
print(' [COMPILED] ', end='')
except EPTestingException as e:
except Exception as e:
print("C API Wrapper Compilation Failed!")
raise e

Expand Down Expand Up @@ -228,9 +227,9 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
print('* Running test class "%s"... ' % self.__class__.__name__, end='')
if 'os' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
if 'bitness' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass bitness in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass bitness in kwargs' % self.__class__.__name__)
self.os = kwargs['os']
self.bitness = kwargs['bitness']
self.msvc_version = kwargs['msvc_version']
Expand All @@ -256,7 +255,7 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
new_binary_path = os.path.join(cmake_build_dir, 'Release', self.target_name + '.exe')
command_line = [new_binary_path]
my_check_call(self.verbose, command_line, cwd=install_root)
except EPTestingException as e:
except Exception as e:
print('C API Wrapper Execution failed!')
raise e
print(' [DONE]!')
Expand Down Expand Up @@ -287,7 +286,7 @@ def _api_script_content(install_path: str) -> str:
elif platform.system() == 'Darwin':
lib_file_name = '/libenergyplusapi.dylib'
else: # windows
raise EPTestingException('Dont call TestCAPIDelayedAccess._api_script_content for Windows')
raise Exception('Dont call TestCAPIDelayedAccess._api_script_content for Windows')
template_file = os.path.join(api_resource_dir(), 'delayed_cpp_source_linux_mac.cpp')
template = open(template_file).read()
return template.replace('{EPLUS_INSTALL_NO_SLASH}', install_path).replace('{LIB_FILE_NAME}', lib_file_name)
Expand All @@ -304,9 +303,9 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
print('* Running test class "%s"... ' % self.__class__.__name__, end='')
if 'os' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass os in kwargs' % self.__class__.__name__)
if 'bitness' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass bitness in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass bitness in kwargs' % self.__class__.__name__)
self.os = kwargs['os']
self.bitness = kwargs['bitness']
self.msvc_version = kwargs['msvc_version']
Expand Down Expand Up @@ -334,7 +333,7 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
my_env["PATH"] = install_root + ";" + my_env["PATH"]
try:
my_check_call(self.verbose, [built_binary_path], env=my_env)
except EPTestingException as e:
except Exception as e:
print("Delayed C API Wrapper execution failed")
raise e
print(' [DONE]!')
11 changes: 5 additions & 6 deletions scripts/package_tests/ep_testing/tests/documentation.py
Expand Up @@ -57,7 +57,6 @@
import os
from subprocess import check_call, CalledProcessError, STDOUT

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


Expand All @@ -68,9 +67,9 @@ def name(self):

def run(self, install_root: str, verbose: bool, kwargs: dict):
if 'pdf_file' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass pdf_file in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass pdf_file in kwargs' % self.__class__.__name__)
if 'version_string' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass version_string in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass version_string in kwargs' % self.__class__.__name__)
pdf_file = kwargs['pdf_file']
version_string = kwargs['version_string']
print('* Running test class "%s" on file "%s"... ' % (self.__class__.__name__, pdf_file), end='')
Expand All @@ -86,19 +85,19 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
)
print(' [PAGE1_EXTRACTED] ', end='')
except CalledProcessError:
raise EPTestingException('PdfTk Page 1 extraction failed!')
raise Exception('PdfTk Page 1 extraction failed!')
target_txt_path = target_pdf_path + '.txt'
try:
check_call(['pdftotext', target_pdf_path, target_txt_path], stdout=dev_null, stderr=STDOUT)
print(' [PAGE1_CONVERTED] ', end='')
except CalledProcessError:
raise EPTestingException('PdfToText Page 1 conversion failed!')
raise Exception('PdfToText Page 1 conversion failed!')
with open(target_txt_path) as f:
contents = f.read()
if version_string in contents:
print(' [FOUND VERSION STRING, DONE]!')
else:
raise EPTestingException(
raise Exception(
'Did not find matching version string in PDF front page, page contents = \n%s' % contents
)
os.chdir(saved_dir)
5 changes: 2 additions & 3 deletions scripts/package_tests/ep_testing/tests/energyplus.py
Expand Up @@ -57,7 +57,6 @@
import os
import subprocess

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


Expand All @@ -68,7 +67,7 @@ def name(self):

def run(self, install_root: str, verbose: bool, kwargs: dict):
if 'test_file' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass test_file in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass test_file in kwargs' % self.__class__.__name__)
test_file = kwargs['test_file']
print('* Running test class "%s" on file "%s"... ' % (self.__class__.__name__, test_file), end='')
eplus_binary = os.path.join(install_root, 'energyplus')
Expand All @@ -91,7 +90,7 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
if r.returncode == 0:
print(' [DONE]!')
else:
raise EPTestingException(
raise Exception(
'EnergyPlus failed!\n'
f'Command {cmd} failed with exit status {r.returncode}!\n'
'stderr:\n'
Expand Down
13 changes: 6 additions & 7 deletions scripts/package_tests/ep_testing/tests/expand_objects.py
Expand Up @@ -58,7 +58,6 @@
from shutil import copyfile
from subprocess import check_call, CalledProcessError, STDOUT

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


Expand All @@ -69,30 +68,30 @@ def name(self):

def run(self, install_root: str, verbose: bool, kwargs: dict):
if 'test_file' not in kwargs:
raise EPTestingException('Bad call to %s -- must pass test_file in kwargs' % self.__class__.__name__)
raise Exception('Bad call to %s -- must pass test_file in kwargs' % self.__class__.__name__)
test_file = kwargs['test_file']
print('* Running test class "%s" on file "%s"... ' % (self.__class__.__name__, test_file), end='')
original_idf_path = os.path.join(install_root, 'ExampleFiles', test_file)
target_idf_path = os.path.join(os.getcwd(), 'in.idf')
try:
copyfile(original_idf_path, target_idf_path)
except Exception as e:
raise EPTestingException(
raise Exception(
'Could not copy file for expansion, original file "%s", target file "%s", reason: %s' % (
original_idf_path, target_idf_path, str(e)
)
)
) from None
expand_objects_binary = os.path.join(install_root, 'ExpandObjects')
dev_null = open(os.devnull, 'w')
try:
check_call([expand_objects_binary], stdout=dev_null, stderr=STDOUT)
except CalledProcessError:
raise EPTestingException('ExpandObjects failed!')
raise Exception('ExpandObjects failed!') from None
expanded_idf_path = os.path.join(os.getcwd(), 'expanded.idf')
if os.path.exists(expanded_idf_path):
print(' [EXPANDED] ', end='')
else:
raise EPTestingException(
raise Exception(
'ExpandObjects did not produce an expanded idf at "%s", aborting' % expanded_idf_path
)
os.remove(target_idf_path)
Expand All @@ -102,4 +101,4 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
check_call([eplus_binary, '-D', target_idf_path], stdout=dev_null, stderr=STDOUT)
print(' [DONE]!')
except CalledProcessError:
raise EPTestingException('EnergyPlus failed!')
raise Exception('EnergyPlus failed!') from None
7 changes: 3 additions & 4 deletions scripts/package_tests/ep_testing/tests/hvacdiagram.py
Expand Up @@ -57,7 +57,6 @@
import os
from subprocess import check_call, CalledProcessError, STDOUT

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


Expand All @@ -75,14 +74,14 @@ def run(self, install_root: str, verbose: bool, kwargs: dict):
check_call([eplus_binary, '-D', idf_path], stdout=dev_null, stderr=STDOUT)
print(' [E+ FINISHED] ', end='')
except CalledProcessError:
raise EPTestingException('EnergyPlus failed!')
raise Exception('EnergyPlus failed!') from None
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!')
raise Exception('Transition failed!') from None
if os.path.exists('eplusout.svg'):
print(' [SVG FILE EXISTS] [DONE]!')
else:
raise EPTestingException('SVG Did not exist!')
raise Exception('SVG Did not exist!')

0 comments on commit 0e6c542

Please sign in to comment.