MCPcopy Create free account
hub / github.com/ElementsProject/elements / bctest

Function bctest

test/util/test_runner.py:67–160  ·  view source on GitHub ↗

Runs a single test, comparing output and RC to expected output and RC. Raises an error if input can't be read, executable fails, or output/RC are not as expected. Error is caught by bctester() and reported.

(testDir, testObj, buildenv)

Source from the content-addressed store, hash-verified

65 sys.exit(0)
66
67def bctest(testDir, testObj, buildenv):
68 """Runs a single test, comparing output and RC to expected output and RC.
69
70 Raises an error if input can't be read, executable fails, or output/RC
71 are not as expected. Error is caught by bctester() and reported.
72 """
73 # Get the exec names and arguments
74 execprog = os.path.join(buildenv["BUILDDIR"], "src", testObj["exec"] + buildenv["EXEEXT"])
75 execargs = testObj['args']
76 execrun = [execprog] + execargs
77
78 # Read the input data (if there is any)
79 stdinCfg = None
80 inputData = None
81 if "input" in testObj:
82 filename = os.path.join(testDir, testObj["input"])
83 inputData = open(filename, encoding="utf8").read()
84 stdinCfg = subprocess.PIPE
85
86 # Read the expected output data (if there is any)
87 outputFn = None
88 outputData = None
89 outputType = None
90 if "output_cmp" in testObj:
91 outputFn = testObj['output_cmp']
92 outputType = os.path.splitext(outputFn)[1][1:] # output type from file extension (determines how to compare)
93 try:
94 outputData = open(os.path.join(testDir, outputFn), encoding="utf8").read()
95 except:
96 logging.error("Output file " + outputFn + " cannot be opened")
97 raise
98 if not outputData:
99 logging.error("Output data missing for " + outputFn)
100 raise Exception
101 if not outputType:
102 logging.error("Output file %s does not have a file extension" % outputFn)
103 raise Exception
104
105 # Run the test
106 proc = subprocess.Popen(execrun, stdin=stdinCfg, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
107 try:
108 outs = proc.communicate(input=inputData)
109 except OSError:
110 logging.error("OSError, Failed to execute " + execprog)
111 raise
112
113 if outputData:
114 data_mismatch, formatting_mismatch = False, False
115 # Parse command output and expected output
116 try:
117 a_parsed = parse_output(outs[0], outputType)
118 except Exception as e:
119 logging.error('Error parsing command output as %s: %s' % (outputType, e))
120 raise
121 try:
122 b_parsed = parse_output(outputData, outputType)
123 except Exception as e:
124 logging.error('Error parsing expected output %s as %s: %s' % (outputFn, outputType, e))

Callers 1

bctesterFunction · 0.85

Calls 3

parse_outputFunction · 0.85
joinMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected