Skip to content

Commit

Permalink
Merge f60a43f into df0d014
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Nov 24, 2018
2 parents df0d014 + f60a43f commit b16f2f8
Show file tree
Hide file tree
Showing 24 changed files with 485 additions and 85 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ epregressions/files_to_run.txt
docs/_build
venv
.python-version
.coverage
EnergyPlusRegressionTool.egg-info
aa_testSuite_error.txt
htmlcov
2 changes: 1 addition & 1 deletion epregressions/builds/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class EPlusInstallDirectory(BaseBuildDirectoryStructure):

def __init__(self):
super().__init__()
super(EPlusInstallDirectory, self).__init__()
self.source_directory = None

def set_build_directory(self, build_directory):
Expand Down
4 changes: 3 additions & 1 deletion epregressions/builds/makefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class CMakeCacheMakeFileBuildDirectory(BaseBuildDirectoryStructure):

def __init__(self):
super().__init__()
super(CMakeCacheMakeFileBuildDirectory, self).__init__()
self.source_directory = None

def set_build_directory(self, build_directory):
Expand All @@ -23,6 +23,8 @@ def set_build_directory(self, build_directory):
self.source_directory = 'unknown - invalid build directory?'
return
cmake_cache_file = os.path.join(self.build_directory, 'CMakeCache.txt')
if not os.path.exists(cmake_cache_file):
raise Exception('Could not find cache file in build directory')
with open(cmake_cache_file, 'r') as f_cache:
for this_line in f_cache.readlines():
if 'CMAKE_HOME_DIRECTORY:INTERNAL=' in this_line:
Expand Down
5 changes: 3 additions & 2 deletions epregressions/builds/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class CMakeCacheVisualStudioBuildDirectory(BaseBuildDirectoryStructure):
"""

def __init__(self):
super().__init__()
super(CMakeCacheVisualStudioBuildDirectory, self).__init__()
self.source_directory = None
self.build_mode = 'Release'

Expand Down Expand Up @@ -74,7 +74,8 @@ def verify(self):
["Case %s Products Directory Exists? ", products_dir, exists]
)
build_mode_folder = 'Release'
release_folder_exists = os.path.join(self.build_directory, 'Products', build_mode_folder)
release_folder = os.path.join(self.build_directory, 'Products', build_mode_folder)
release_folder_exists = os.path.exists(release_folder)
if release_folder_exists:
self.set_build_mode(debug=False)
else:
Expand Down
66 changes: 0 additions & 66 deletions epregressions/diffs/html_data.py

This file was deleted.

69 changes: 60 additions & 9 deletions epregressions/diffs/table_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,58 @@
import os.path

from bs4 import BeautifulSoup, NavigableString, Tag
from epregressions.diffs import html_data

help_message = __doc__

path = os.path.dirname(__file__)
script_dir = os.path.abspath(path)

titlecss = """<!DOCTYPE html PUBLIC "-
//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head><title>%s</title> <style type="text/css"> %s </style>
<meta name="generator" content="BBEdit 8.2" /></head>
<body></body></html>
"""

titlehtml = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>%s</title>
<meta name="generator" content="BBEdit 8.2" />
</head>
<body>
</body>
</html>
"""

thecss = """td.big {
background-color: #FF969D;
}
td.small {
background-color: #FFBE84;
}
td.equal {
background-color: #CBFFFF;
}
td.table_size_error {
background-color: #FCFF97;
}
.big {
background-color: #FF969D;
}
.small {
background-color: #FFBE84;
}
"""


class Usage(Exception):
""" usage """
Expand All @@ -57,7 +102,7 @@ def __init__(self, msg):


def thresh_abs_rel_diff(abs_thresh, rel_thresh, x, y):
if (x == y):
if x == y:
return (0, 0, 'equal')
try:
fx = float(x)
Expand Down Expand Up @@ -320,13 +365,16 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file
comparingthis = 'Comparing<br> %s<br> vs<br> %s<br><hr>' % (inputfile1, inputfile2)

# Error soup
err_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- summary', html_data.thecss,), features='html.parser')
err_soup = BeautifulSoup(titlecss % (pagetitle + ' -- summary', thecss,),
features='html.parser')

# Abs diff soup
abs_diff_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- absolute differences', html_data.thecss,), features='html.parser')
abs_diff_soup = BeautifulSoup(titlecss % (pagetitle + ' -- absolute differences', thecss,),
features='html.parser')

# Rel diff soup
rel_diff_soup = BeautifulSoup(html_data.titlecss % (pagetitle + ' -- relative differences', html_data.thecss,), features='html.parser')
rel_diff_soup = BeautifulSoup(titlecss % (pagetitle + ' -- relative differences', thecss,),
features='html.parser')

# Make error table
tabletag = Tag(err_soup, name='table', attrs=[('border', '1')])
Expand Down Expand Up @@ -449,14 +497,16 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file
for h in horder1:
if h not in horder2:
continue
abs_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [(x_y_z[0],x_y_z[2]) for x_y_z in diff_dict[h]]
abs_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [
(x_y_z[0], x_y_z[2]) for x_y_z in diff_dict[h]]
hdict2soup(abs_diff_soup, uheading1, count_of_tables, abs_diff_dict.copy(), h_thresh_dict, horder1)

rel_diff_dict = {}
for h in horder1:
if h not in horder2:
continue
rel_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [(x_y_z[1],x_y_z[2]) for x_y_z in diff_dict[h]]
rel_diff_dict[h] = diff_dict[h] if (h == 'DummyPlaceholder' or h == 'Subcategory') else [
(x_y_z[1], x_y_z[2]) for x_y_z in diff_dict[h]]
hdict2soup(rel_diff_soup, uheading1, count_of_tables, rel_diff_dict.copy(), h_thresh_dict, horder1)

count_of_tables_diff += 1
Expand Down Expand Up @@ -487,8 +537,9 @@ def table_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file
"Case,TableCount,BigDiffCount,SmallDiffCount,EqualCount,StringDiffCount,SizeErrorCount,NotIn1Count,NotIn2Count\n")
with open(summary_file, 'a') as summarize:
summarize.write("%s,%s,%s,%s,%s,%s,%s,%s,%s\n" % (
case_name, count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal, count_of_string_diff,
count_of_size_error, count_of_not_in_1, count_of_not_in_2))
case_name, count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal,
count_of_string_diff,
count_of_size_error, count_of_not_in_1, count_of_not_in_2))

return ('', count_of_tables, count_of_big_diff, count_of_small_diff, count_of_equal, count_of_string_diff,
count_of_size_error, count_of_not_in_1, count_of_not_in_2)
Expand Down
8 changes: 3 additions & 5 deletions epregressions/energyplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ def execute_energyplus(build_tree, entry_name, test_run_directory,

# Run EPMacro as necessary
if os.path.exists('in.imf'):
print("IMF file exists")
with open('in.imf', 'rb') as f:
lines = f.readlines()
newlines = []
for line in lines:
encoded_line = line.decode('UTF-8', 'ignore')
if '##fileprefix' in encoded_line:
newlines.append('')
print("Replaced fileprefix line with a blank")
else:
newlines.append(encoded_line)
with open('in.imf', 'w') as f:
Expand All @@ -73,7 +71,7 @@ def execute_energyplus(build_tree, entry_name, test_run_directory,
os.remove('in.idf')
os.rename(file_to_run_here, 'in.idf')
else:
return [build_tree['build_dir'], entry_name, False, current_process().name]
return [build_tree['build_dir'], entry_name, False, False, current_process().name]

# Run ExpandObjects and process as necessary
expand_objects_run = subprocess.Popen(expandobjects, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down Expand Up @@ -162,8 +160,8 @@ def execute_energyplus(build_tree, entry_name, test_run_directory,
return [build_tree['build_dir'], entry_name, True, False, current_process().name]

except Exception as e:
f = open("aa_testSuite_error.txt", 'w')
print(e, file=f)
with open("aa_testSuite_error.txt", 'w') as f:
print(e, file=f)
return [build_tree['build_dir'], entry_name, False, False, current_process().name]

finally:
Expand Down
2 changes: 1 addition & 1 deletion epregressions/tests/builds/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from epregressions.builds.base import BaseBuildDirectoryStructure


class TestBaseWorkflowMethods(unittest.TestCase):
class TestBaseBuildMethods(unittest.TestCase):

def setUp(self):
self.base_build = BaseBuildDirectoryStructure()
Expand Down
38 changes: 38 additions & 0 deletions epregressions/tests/builds/test_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import tempfile
import unittest

from epregressions.builds.install import EPlusInstallDirectory


class TestEPInstallBuildMethods(unittest.TestCase):

def setUp(self):
self.build = EPlusInstallDirectory()
self.run_dir = tempfile.mkdtemp()

def test_set_build_directory_does_not_exist(self):
self.build.set_build_directory('hello')
self.assertIn('unknown', self.build.source_directory)

def test_set_build_directory_does_exist(self):
self.build.set_build_directory(self.run_dir)
self.assertEqual(self.run_dir, self.build.source_directory)

def test_verify_before_setting_build_directory(self):
with self.assertRaises(Exception):
self.build.verify()

def test_verify_but_nothing_exists(self):
self.build.set_build_directory(self.run_dir)
check = self.build.verify()
self.assertIsInstance(check, list)
self.assertGreaterEqual(len(check), 4) # there should be some errors

def test_get_build_tree_before_setting_build_directory(self):
with self.assertRaises(Exception):
self.build.get_build_tree()

def test_get_build_tree(self):
self.build.set_build_directory(self.run_dir)
tree = self.build.get_build_tree()
self.assertIsInstance(tree, dict)
59 changes: 59 additions & 0 deletions epregressions/tests/builds/test_makefile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import tempfile
import unittest

from epregressions.builds.makefile import CMakeCacheMakeFileBuildDirectory


class TestMakefileBuildMethods(unittest.TestCase):

def setUp(self):
self.build = CMakeCacheMakeFileBuildDirectory()
self.run_dir = tempfile.mkdtemp()
self.dummy_source_dir = '/dummy/source/dir'

def set_cache_file(self):
with open(os.path.join(self.run_dir, 'CMakeCache.txt'), 'w') as f:
f.write('HEY\n')
f.write('CMAKE_HOME_DIRECTORY:INTERNAL=%s\n' % self.dummy_source_dir)
f.write('HEY AGAIN\n')

def test_set_build_directory_does_not_exist(self):
self.build.set_build_directory('hello')
self.assertIn('unknown', self.build.source_directory)

def test_set_build_directory_does_exist_but_no_cache(self):
with self.assertRaises(Exception):
self.build.set_build_directory(self.run_dir)

def test_set_build_directory_does_exist_but_empty_cache(self):
with open(os.path.join(self.run_dir, 'CMakeCache.txt'), 'w') as f:
f.write('\n')
with self.assertRaises(Exception):
self.build.set_build_directory(self.run_dir)

def test_set_build_directory_and_has_cache(self):
self.set_cache_file()
self.build.set_build_directory(self.run_dir)
self.assertEqual(self.dummy_source_dir, self.build.source_directory)

def test_verify_before_setting_build_directory(self):
with self.assertRaises(Exception):
self.build.verify()

def test_verify_but_nothing_exists(self):
self.set_cache_file()
self.build.set_build_directory(self.run_dir)
check = self.build.verify()
self.assertIsInstance(check, list)
self.assertGreaterEqual(len(check), 4) # there should be some errors

def test_get_build_tree_before_setting_build_directory(self):
with self.assertRaises(Exception):
self.build.get_build_tree()

def test_get_build_tree(self):
self.set_cache_file()
self.build.set_build_directory(self.run_dir)
tree = self.build.get_build_tree()
self.assertIsInstance(tree, dict)
Loading

0 comments on commit b16f2f8

Please sign in to comment.