Merge #11291: Fix string concatenation to os.path.join and add exception case
a3ac7672ed
Fix string concatenation to os.path.join and add exception case (dongsamb)
Pull request description:
Solved some warnings for [Python PEP 8 convention](https://www.python.org/dev/peps/pep-0008/)
- [Method Names and Instance Variables](https://www.python.org/dev/peps/pep-0008/#method-names-and-instance-variables)
lowercase with words separated by underscores as necessary to improve readability.
- `testDir` to `test_dir`
- `inputData` to `input_data`
- ...
- [Blank Lines](https://www.python.org/dev/peps/pep-0008/#blank-lines)
Surround top-level function and class definitions with two blank lines.
- [Exception Names](https://www.python.org/dev/peps/pep-0008/#exception-names)
and added verification logic about referenced before assignment for `output_type`
Tree-SHA512: 346d08799f03077a2b7257ccdca123b4945b89dbf0677dba452d96b81ce186ec7b5dcdb10b8bb59cfce657a7aedbb7df64921036cbd1bf4ad8bd313d40faa796
This commit is contained in:
commit
a332a7d5a1
1 changed files with 8 additions and 4 deletions
|
@ -48,7 +48,7 @@ def main():
|
||||||
|
|
||||||
def bctester(testDir, input_basename, buildenv):
|
def bctester(testDir, input_basename, buildenv):
|
||||||
""" Loads and parses the input file, runs all tests and reports results"""
|
""" Loads and parses the input file, runs all tests and reports results"""
|
||||||
input_filename = testDir + "/" + input_basename
|
input_filename = os.path.join(testDir, input_basename)
|
||||||
raw_data = open(input_filename).read()
|
raw_data = open(input_filename).read()
|
||||||
input_data = json.loads(raw_data)
|
input_data = json.loads(raw_data)
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ def bctest(testDir, testObj, buildenv):
|
||||||
are not as expected. Error is caught by bctester() and reported.
|
are not as expected. Error is caught by bctester() and reported.
|
||||||
"""
|
"""
|
||||||
# Get the exec names and arguments
|
# Get the exec names and arguments
|
||||||
execprog = buildenv["BUILDDIR"] + "/src/" + testObj['exec'] + buildenv["EXEEXT"]
|
execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"])
|
||||||
execargs = testObj['args']
|
execargs = testObj['args']
|
||||||
execrun = [execprog] + execargs
|
execrun = [execprog] + execargs
|
||||||
|
|
||||||
|
@ -85,24 +85,28 @@ def bctest(testDir, testObj, buildenv):
|
||||||
stdinCfg = None
|
stdinCfg = None
|
||||||
inputData = None
|
inputData = None
|
||||||
if "input" in testObj:
|
if "input" in testObj:
|
||||||
filename = testDir + "/" + testObj['input']
|
filename = os.path.join(testDir, testObj["input"])
|
||||||
inputData = open(filename).read()
|
inputData = open(filename).read()
|
||||||
stdinCfg = subprocess.PIPE
|
stdinCfg = subprocess.PIPE
|
||||||
|
|
||||||
# Read the expected output data (if there is any)
|
# Read the expected output data (if there is any)
|
||||||
outputFn = None
|
outputFn = None
|
||||||
outputData = None
|
outputData = None
|
||||||
|
outputType = None
|
||||||
if "output_cmp" in testObj:
|
if "output_cmp" in testObj:
|
||||||
outputFn = testObj['output_cmp']
|
outputFn = testObj['output_cmp']
|
||||||
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
|
outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
|
||||||
try:
|
try:
|
||||||
outputData = open(testDir + "/" + outputFn).read()
|
outputData = open(os.path.join(testDir, outputFn)).read()
|
||||||
except:
|
except:
|
||||||
logging.error("Output file " + outputFn + " can not be opened")
|
logging.error("Output file " + outputFn + " can not be opened")
|
||||||
raise
|
raise
|
||||||
if not outputData:
|
if not outputData:
|
||||||
logging.error("Output data missing for " + outputFn)
|
logging.error("Output data missing for " + outputFn)
|
||||||
raise Exception
|
raise Exception
|
||||||
|
if not outputType:
|
||||||
|
logging.error("Output file %s does not have a file extension" % outputFn)
|
||||||
|
raise Exception
|
||||||
|
|
||||||
# Run the test
|
# Run the test
|
||||||
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
|
||||||
|
|
Loading…
Reference in a new issue