Skip to content

Commit

Permalink
add run_inputs to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gidden committed Apr 27, 2015
1 parent 9d07eb1 commit b2b6e51
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SET(cyclus_path ${CYCLUS_ROOT_DIR}/bin)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/run_inputs.py.in
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/run_inputs.py @ONLY)

SET(input_path ${PROJECT_SOURCE_DIR}/../input)
SET(input_path ${PROJECT_SOURCE_DIR}/input)
SET(cyclus_path ${CYCLUS_ROOT_DIR}/bin)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/run_inputs.py.in
${CMAKE_CURRENT_SOURCE_DIR}/run_inputs.py @ONLY)
Expand Down
74 changes: 39 additions & 35 deletions tests/run_inputs.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import subprocess
from subprocess import Popen, PIPE, STDOUT
import os
import re

def main():
"""This function finds input files, runs them, and prints a summary"""
flag = check_inputs()
input_path = "@input_path@"
cyclus_path = "@cyclus_path@/cyclus"

cyclus_path = "@cyclus_path@/cyclus"
input_path = "@input_path@"

def main_body(flag):
files, catalogs, catalognames = get_files(input_path)
copy_catalogs(catalogs,cyclus_path.strip("cyclus"))
summ = Summary()
Expand All @@ -20,7 +19,12 @@ def main():
summ.add_to_summary(file_to_test)
clean_catalogs(cyclus_path.strip("cyclus"),catalognames)
summ.print_summary()


def main():
"""This function finds input files, runs them, and prints a summary"""
flag = check_inputs()
main_body(flag)

def check_inputs():
"""This function checks the input arguments"""
if len(sys.argv) > 2:
Expand All @@ -38,19 +42,19 @@ def check_inputs():

def print_usage() :
"""This prints the proper way to treat the command line interface"""
print 'Usage: python run_inputs.py\n' + \
'Allowed Options : \n' + \
'-v arg output log verbosity. \n' + \
' \
Can be text: \n' + \
' \
LEV_ERROR (least verbose, default), LEV_WARN,\n' + \
' \
LEV_INFO1 (through 5), and LEV_DEBUG1 (through 5).\n' + \
' \
Or an integer:\n'+ \
' \
0 (LEV_ERROR equiv) through 11 (LEV_DEBUG5 equiv)\n'
print(""" Usage: python run_inputs.py\n
Allowed Options : \n
-v arg output log verbosity. \n
Can be text: \n
LEV_ERROR (least verbose, default), LEV_WARN,\n
LEV_INFO1 (through 5), and LEV_DEBUG1 (through 5).\n
Or an integer:\n
0 (LEV_ERROR equiv) through 11 (LEV_DEBUG5 equiv)\n""")

def get_files(path):
"""This function walks the 'path' tree and finds input files"""
Expand All @@ -70,10 +74,10 @@ def get_files(path):
inputs.append(os.path.join(root, name))
else :
files.remove(name)
print "The catalogs to be moved are:"
print catalogs
print "The files to be tested are:"
print inputs
print("The catalogs to be moved are:")
print(catalogs)
print("The files to be tested are:")
print(inputs)
return inputs, catalogs, catalognames

def copy_catalogs(catalogs,cyclus_path) :
Expand Down Expand Up @@ -103,11 +107,11 @@ class Summary():

def print_summary(self) :
"""Prints the summary"""
print "Input files passed = " + str(len(self.passed))
print "Input files failed = " + str(len(self.failed))
print "Failed input files : "
print("Input files passed = " + str(len(self.passed)))
print("Input files failed = " + str(len(self.failed)))
print("Failed input files : ")
for test in self.failed :
print test
print(test)

class TestFile():
"""An object representing the inputxml file to test"""
Expand All @@ -132,22 +136,22 @@ class TestFile():
shell=True, stdout=PIPE, stderr=STDOUT)
io_tuple = p.communicate()
output = io_tuple[0]
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
print(e)
return output
return str(output)

def no_errors(self, output):
"""returns true if there were no errors or segfaults running this TestFile"""
to_ret = True
print "Input file " + self.infile
print("Input file " + self.infile)
if re.search("No such file or directory",output) :
print "Cyclus executable not found in path."
print("Cyclus executable not found in path.")
elif re.search("ERROR",output) or re.search("Segmentation fault",output):
to_ret = False
print " resulted in errors: "
print output
print(" resulted in errors: ")
print(output)
else :
print " passed. "
print(" passed. ")
return to_ret

if __name__ == '__main__' : main()
13 changes: 13 additions & 0 deletions tests/test_run_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os
import subprocess

from nose.tools import assert_true

import run_inputs as ri

def test_inputs():
files, _, _ = ri.get_files(ri.input_path)
for f in files:
testf = ri.TestFile(ri.cyclus_path, f, "-v0")
testf.run()
yield assert_true, testf.passed

0 comments on commit b2b6e51

Please sign in to comment.