Skip to content

Commit

Permalink
Clean up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Myoldmopar committed Jan 14, 2017
1 parent e057d52 commit 26d6c90
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
2 changes: 1 addition & 1 deletion eptransition/epexceptions.py
Expand Up @@ -16,7 +16,7 @@ class FileTypeException(Exception):

class ManagerProcessingException(Exception):
def __str__(self):
print(self.message)
print(self.message) # pragma no cover


class ProcessingException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion eptransition/idf/idfobject.py
Expand Up @@ -4,7 +4,7 @@ def __init__(self, object_name, field_name=None, message=None):
self.field_name = field_name
self.message = message

def __str__(self):
def __str__(self): # pragma no cover
return "Issue found: object {}; field {}; message: {}".format(self.object_name, self.field_name, self.message)


Expand Down
44 changes: 22 additions & 22 deletions eptransition/manager.py
Expand Up @@ -20,99 +20,99 @@ def __init__(self, original_input_file, new_input_file, original_idd_file, new_i
def perform_transition(self):

# Validate file path things
if not os.path.exists(self.original_input_file):
if not os.path.exists(self.original_input_file): # pragma no cover
raise FileAccessException(
"Could not access original input file at path = \"" + self.original_input_file + "\"")
if not os.path.exists(self.original_idd_file):
if not os.path.exists(self.original_idd_file): # pragma no cover
raise FileAccessException(
"Could not access original IDD file at path = \"" + self.original_idd_file + "\"")
if not os.path.exists(self.new_idd_file):
if not os.path.exists(self.new_idd_file): # pragma no cover
raise FileAccessException(
"Could not access updated IDD file at path = \"" + self.new_idd_file + "\"")
if os.path.exists(self.new_input_file):
if os.path.exists(self.new_input_file): # pragma no cover
raise FileAccessException(
"Updated input file already exists at = \"" + self.new_input_file + "\"; remove before running!")
try:
open(self.new_input_file, 'w').write('-')
except:
except: # pragma no cover
raise FileAccessException(
"Could not write to updated file name at = \"" + self.new_input_file + "\"; aborting!")

# Check file types
if self.original_input_file.endswith('.idf'):
original_idf_file_type = TypeEnum.IDF
elif self.original_input_file.endswith('.jdf'):
elif self.original_input_file.endswith('.jdf'): # pragma no cover
original_idf_file_type = TypeEnum.JSON
else:
else: # pragma no cover
raise FileTypeException("Original input file path has unexpected extension, should be .idf or .jdf")
if self.new_input_file.endswith('.idf'):
new_idf_file_type = TypeEnum.IDF
elif self.new_input_file.endswith('.jdf'):
elif self.new_input_file.endswith('.jdf'): # pragma no cover
new_idf_file_type = TypeEnum.JSON
else:
else: # pragma no cover
raise FileTypeException("New input file path has unexpected extension, should be .idf or .jdf")
if self.original_idd_file.endswith('.idd'):
original_idd_file_type = TypeEnum.IDF
elif self.original_idd_file.endswith('.jdd'):
elif self.original_idd_file.endswith('.jdd'): # pragma no cover
original_idd_file_type = TypeEnum.JSON
else:
else: # pragma no cover
raise FileTypeException("Original input dictionary path has unexpected extension, should be .idd or .jdd")
if self.new_idd_file.endswith('.idd'):
new_idd_file_type = TypeEnum.IDF
elif self.new_idd_file.endswith('.jdd'):
elif self.new_idd_file.endswith('.jdd'): # pragma no cover
new_idd_file_type = TypeEnum.JSON
else:
else: # pragma no cover
raise FileTypeException("New input dictionary path has unexpected extension, should be .idd or .jdd")

# now validate the file types
if original_idf_file_type == START_VERSION.file_type and original_idd_file_type == START_VERSION.file_type:
pass # that's a good thing
else:
else: # pragma no cover
raise FileTypeException("Original files don't match expected version file type; expected: " +
START_VERSION.file_type)
if new_idf_file_type == END_VERSION.file_type and new_idd_file_type == END_VERSION.file_type:
pass # that's a good thing
else:
else: # pragma no cover
raise FileTypeException("Updated files don't match expected version file type; expected: " +
END_VERSION.file_type)

# process the original input file
original_idf_processor = IDFProcessor()
try:
original_idf_structure = original_idf_processor.process_file_given_file_path(self.original_input_file)
except:
except: # pragma no cover
raise ManagerProcessingException("Could not process original idf; aborting")

# and process the original idd file
original_idd_processor = IDDProcessor()
try:
original_idd_structure = original_idd_processor.process_file_given_file_path(self.original_idd_file)
except:
except: # pragma no cover
raise ManagerProcessingException("Could not process original idd; aborting")

# and process the new idd file
new_idd_processor = IDDProcessor()
try:
new_idd_structure = new_idd_processor.process_file_given_file_path(self.new_idd_file)
except:
except: # pragma no cover
raise ManagerProcessingException("Could not process new idd; aborting")

# validate the current idf before continuing
issues = original_idf_structure.validate(original_idd_structure)
if len(issues) > 0:
if len(issues) > 0: # pragma no cover
# TODO: Once issues have severities, just check for fatal errors
raise ManagerProcessingException("Issues found in validating of original idf against original idd; aborting")

# check the version of the original idf
try:
original_version_object = original_idf_structure.get_idf_objects_by_type("Version")[0]
except:
except: # pragma no cover
raise ManagerProcessingException("Could not access version object in original idf; this is invalid, aborting.")
try:
version_value = float(original_version_object.fields[0])
except:
except: # pragma no cover
raise ManagerProcessingException("Could not coerce version field into numeric representation; aborting.")
if version_value != START_VERSION.version:
if version_value != START_VERSION.version: # pragma no cover
raise ManagerProcessingException("Input file version does not match expected. (expected={};found={})".format(
START_VERSION.version, version_value))

Expand Down
6 changes: 6 additions & 0 deletions test/idf/test_idfobject.py
Expand Up @@ -108,6 +108,12 @@ def test_non_numeric_autosize_but_not_allowed(self):
issues = idf_object.validate(self.idd_object)
self.assertEqual(len(issues), 1)

def test_non_numeric_autocalculate_but_not_allowed(self):
idf_string = "MyObject,AutoCalculate,1,1;"
idf_object = IDFProcessor().process_file_via_string(idf_string).get_idf_objects_by_type('MyObject')[0]
issues = idf_object.validate(self.idd_object)
self.assertEqual(len(issues), 1)

def test_numeric_too_high_a(self):
idf_string = "MyObject,3,1,1;"
idf_object = IDFProcessor().process_file_via_string(idf_string).get_idf_objects_by_type('MyObject')[0]
Expand Down
2 changes: 1 addition & 1 deletion test/test_driver.py
Expand Up @@ -13,7 +13,7 @@ def test_driver(self):
idd_path = os.path.join(cur_dir, "..", "support", "transition_files", "Energy+.idd")
idd_path_2 = os.path.join(cur_dir, "..", "support", "transition_files", "Energy+2.idd")
if os.path.exists('/tmp/new_idf.idf'):
os.remove('/tmp/new_idf.idf')
os.remove('/tmp/new_idf.idf') # pragma no cover
r = driver.drive(['program_name', 'update', idf_path, '/tmp/new_idf.idf', idd_path, idd_path_2], True)
self.assertEqual(0, r)
# usage mode
Expand Down

0 comments on commit 26d6c90

Please sign in to comment.