Skip to content

Commit

Permalink
Merge 29189b0 into df0d014
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Nov 25, 2018
2 parents df0d014 + 29189b0 commit 36d8f8d
Show file tree
Hide file tree
Showing 40 changed files with 1,432 additions and 371 deletions.
8 changes: 6 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[flake8]
ignore = D203
ignore =
D203,
C901
exclude =
.git,
__pycache__,
epregressions/diffs/math_diff.py,
epregressions/diffs/mycsv.py,
epregressions/diffs/table_diff.py,
epregressions/diffs/thresh_dict.py,
old,
build,
dist
max-complexity = 20
max-line-length = 120
max-line-length = 120
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
19 changes: 14 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@

os: linux
language: python
python:
- 2.7
- 3.6

addons:
apt:
Expand All @@ -18,8 +15,20 @@ install:
- pip install --upgrade pip
- pip install -r requirements.txt

matrix:
include:
- name: "2.7 Unit Test"
python: "2.7"
env: TEST_COMMAND=test
- name: "3.6 Unit Tests"
python: "3.6"
env: TEST_COMMAND=test
- name: "3.6 Code Quality"
python: "3.6"
env: TEST_COMMAND=flake8

script:
- coverage run setup.py test
- coverage run setup.py $TEST_COMMAND

after_success:
- coveralls
- test $TEST_COMMAND = "test" && coveralls
2 changes: 1 addition & 1 deletion docs/run_cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ provided here verbatim:
Create EnergyPlus test file inputs for a specific configuration. Can be
executed in 2 ways: 1: Arguments can be passed from the command line, such as
`./build_files_to_run.py -r 3 -w' .. Most useful for scripting, or 2: An
argument class can be created using the FileListArgsBuilderForGUI class and
argument class can be created using the FileListBuilderArgs class and
passed into a FileListBuilder instance .. Most useful for UIs

optional arguments:
Expand Down
65 changes: 35 additions & 30 deletions epregressions/build_files_to_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def __init__(self, csv_row):
self.underscore = (self.filename[0] == '_')


class FileListArgsBuilderForGUI:
class FileListBuilderArgs:
"""The FileListBuilder class accepts arguments in the form created by the argparse library, as this was originally
called by the command line only. This class provides an alternate way to create those arguments."""

def __init__(self):
# establish defaults
Expand All @@ -47,9 +49,11 @@ class FileListBuilder(object):

def __init__(self, _args):

self.config = _args

# if the 'all' argument is present, turn on all the rest
if _args.all:
_args.extinterface, _args.underscore, _args.weatherless = [True, True, True]
if self.config.all:
self.config.extinterface, self.config.underscore, self.config.weatherless = [True, True, True]

# initialize callbacks to None
self.callback_func_print = None
Expand All @@ -61,12 +65,12 @@ def __init__(self, _args):
self.input_files_eliminated = None
self.input_files_found_not_listed = None

def set_callbacks(self, callback_print, callback_init, callback_increment):
def set_callbacks(self, callback_print, callback_init, callback_increment): # pragma: no cover
self.callback_func_print = callback_print
self.callback_func_init = callback_init
self.callback_func_increment = callback_increment

def build_verified_list(self, these_args):
def build_verified_list(self):

self.my_print("Starting to build file list")

Expand All @@ -80,12 +84,12 @@ def build_verified_list(self, these_args):
self.selected_input_file_set = []

# for convenience, count the number of rows first, this should be a cheap operation anyway
with open(these_args.master_data_file) as csvfile:
with open(self.config.master_data_file) as csvfile:
num_lines_approx = csvfile.read().count('\n')
self.my_init(num_lines_approx + 1)

# get all rows of data
with open(these_args.master_data_file) as csvfile:
with open(self.config.master_data_file) as csvfile:
reader = csv.reader(csvfile)
row_num = 0
for row in reader:
Expand All @@ -105,12 +109,12 @@ def build_verified_list(self, these_args):
self.input_files_found_not_listed = set()

# if we are verifying using input file directories,
if these_args.verify:
if self.config.verify:

self.my_print("Verifying idf list using directory: %s" % these_args.verify)
self.my_print("Verifying idf list using directory: %s" % self.config.verify)

# read in the files in the directory and remove the extensions
files_in_this_dir = self.read_input_files_in_dir(these_args.verify)
files_in_this_dir = self.read_input_files_in_dir(self.config.verify)
files_no_extensions = [os.path.splitext(infile)[0] for infile in files_in_this_dir]
just_filenames = [infile.split(os.sep)[-1] for infile in files_no_extensions]

Expand All @@ -123,10 +127,11 @@ def build_verified_list(self, these_args):
self.input_files_eliminated.add(infile)

# include a report of files found in the directory not represented in the file list
just_filenames_from_csv = [x.filename for x in self.selected_input_file_set]
for infile in just_filenames:

# if the file found by globbing is missing from the csv dataset
if infile in self.selected_input_file_set:
if infile not in just_filenames_from_csv:
# add it to the report
self.input_files_found_not_listed.add(infile)

Expand All @@ -144,11 +149,11 @@ def build_verified_list(self, these_args):

return success, self.selected_input_file_set, self.input_files_eliminated, self.input_files_found_not_listed

def print_file_list_to_file(self, _args):
def print_file_list_to_file(self):

# if we aren't running in the gui, we need to go ahead and down select and write to the output file
if not _args.gui:
with open(_args.output_file, 'w') as outfile:
if not self.config.gui:
with open(self.config.output_file, 'w') as outfile:
files = []
for i in self.selected_input_file_set:
if i.has_weather_file:
Expand All @@ -160,7 +165,7 @@ def print_file_list_to_file(self, _args):
files.append(object_to_add)
json_object = {'files_to_run': files}
outfile.write(json.dumps(json_object, indent=2))
print("File list build complete")
self.my_print("File list build complete")

@staticmethod
def read_input_files_in_dir(directory):
Expand All @@ -170,51 +175,51 @@ def read_input_files_in_dir(directory):
files_in_dir.extend(glob.glob(directory + os.sep + extension))
return files_in_dir

def down_select_idf_list(self, _args):
def down_select_idf_list(self):

idf_list = self.selected_input_file_set

# now trim off any of the specialties if the switches are false (by default)
if not _args.extinterface: # only include those without external interface dependencies
if not self.config.extinterface: # only include those without external interface dependencies
idf_list = [idf for idf in idf_list if not idf.external_interface]
if not _args.weatherless: # only include those that DO have weather files
if not self.config.weatherless: # only include those that DO have weather files
idf_list = [idf for idf in idf_list if idf.has_weather_file]
if not _args.underscore: # only include those that don't start with an underscore
if not self.config.underscore: # only include those that don't start with an underscore
idf_list = [idf for idf in idf_list if not idf.underscore]
# do random down selection as necessary:
if _args.random > 0:
if len(idf_list) <= _args.random: # just take all of them
if self.config.random > 0:
if len(idf_list) <= self.config.random: # just take all of them
pass
else: # down select randomly
indeces_to_take = sorted(random.sample(range(len(idf_list)), _args.random))
indeces_to_take = sorted(random.sample(range(len(idf_list)), self.config.random))
idf_list = [idf_list[i] for i in indeces_to_take]
# return the trimmed list
self.selected_input_file_set = idf_list
return idf_list

def my_init(self, num_files):
def my_init(self, num_files): # pragma: no cover
if self.callback_func_init:
self.callback_func_init(num_files)

def my_increment(self):
def my_increment(self): # pragma: no cover
if self.callback_func_increment:
self.callback_func_increment()

def my_print(self, msg):
def my_print(self, msg): # pragma: no cover
if self.callback_func_print:
self.callback_func_print(msg)
else:
print(msg)


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover

# parse command line arguments
parser = argparse.ArgumentParser(
description="""
Create EnergyPlus test file inputs for a specific configuration. Can be executed in 2 ways:
1: Arguments can be passed from the command line, such as `%s -r 3 -w' .. Most useful for scripting, or
2: An argument class can be created using the FileListArgsBuilderForGUI class and
2: An argument class can be created using the FileListBuilderArgs class and
passed into a FileListBuilder instance .. Most useful for UIs""" % sys.argv[0]
)
parser.add_argument(
Expand Down Expand Up @@ -275,10 +280,10 @@ def my_print(self, msg):
# In a script, we will just let the class instance hang on to the values and write out the list file

# build a base file list verified with any directories requested
this_builder.build_verified_list(args)
this_builder.build_verified_list()

# down select the idf list based on command line arguments
this_builder.down_select_idf_list(args)
this_builder.down_select_idf_list()

# and go ahead and print to the output file
this_builder.print_file_list_to_file(args)
this_builder.print_file_list_to_file()
2 changes: 1 addition & 1 deletion epregressions/builds/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class KnownBuildTypes:
Installation = "install"


class BaseBuildDirectoryStructure:
class BaseBuildDirectoryStructure(object):
def __init__(self):
self.build_directory = None
self.run = None
Expand Down
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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -100,4 +102,3 @@ def get_build_tree(self):
'weather_dir': os.path.join(self.source_directory, 'weather'),
'data_sets_dir': os.path.join(self.source_directory, 'datasets')
}

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.

4 changes: 2 additions & 2 deletions epregressions/diffs/math_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,10 @@ def math_diff(thresh_dict, inputfile1, inputfile2, abs_diff_file, rel_diff_file,
for h in hset_sdiff:
if h in hset1:
mycsv.writecsv([['Not comparing field %s, which appears in input files <%s>, but not <%s>' % (
h, inputfile1, inputfile2)]], err_file, 'ab');
h, inputfile1, inputfile2)]], err_file, 'ab')
else:
mycsv.writecsv([['Not comparing field %s, which appears in input files <%s>, but not <%s>' % (
h, inputfile2, inputfile1)]], err_file, 'ab');
h, inputfile2, inputfile1)]], err_file, 'ab')

# convert time matrix to dictionary (both time matrices should be identical here)
tdict = matrix2hdict(time1)
Expand Down
Loading

0 comments on commit 36d8f8d

Please sign in to comment.