Changeset View
Changeset View
Standalone View
Standalone View
test/util/bitcoin-util-test.py
Show All 17 Lines | |||||
import os | import os | ||||
import pprint | import pprint | ||||
import subprocess | import subprocess | ||||
import sys | import sys | ||||
def main(): | def main(): | ||||
config = configparser.ConfigParser() | config = configparser.ConfigParser() | ||||
config.read_file(open(os.path.dirname(__file__) + "/../config.ini")) | config.read_file(open(os.path.join(os.path.dirname( | ||||
__file__), "../config.ini"), encoding="utf8")) | |||||
parser = argparse.ArgumentParser(description=__doc__) | parser = argparse.ArgumentParser(description=__doc__) | ||||
parser.add_argument('-v', '--verbose', action='store_true') | parser.add_argument('-v', '--verbose', action='store_true') | ||||
args = parser.parse_args() | args = parser.parse_args() | ||||
verbose = args.verbose | verbose = args.verbose | ||||
if verbose: | if verbose: | ||||
level = logging.DEBUG | level = logging.DEBUG | ||||
else: | else: | ||||
level = logging.ERROR | level = logging.ERROR | ||||
formatter = '%(asctime)s - %(levelname)s - %(message)s' | formatter = '%(asctime)s - %(levelname)s - %(message)s' | ||||
# Add the format/level to the logger | # Add the format/level to the logger | ||||
logging.basicConfig(format=formatter, level=level) | logging.basicConfig(format=formatter, level=level) | ||||
bctester(os.path.join(config["environment"]["SRCDIR"], "test", | bctester(os.path.join(config["environment"]["SRCDIR"], "test", | ||||
"util", "data"), "bitcoin-util-test.json", config["environment"]) | "util", "data"), "bitcoin-util-test.json", config["environment"]) | ||||
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 = os.path.join(testDir, input_basename) | input_filename = os.path.join(testDir, input_basename) | ||||
raw_data = open(input_filename).read() | raw_data = open(input_filename, encoding="utf8").read() | ||||
input_data = json.loads(raw_data) | input_data = json.loads(raw_data) | ||||
failed_testcases = [] | failed_testcases = [] | ||||
for testObj in input_data: | for testObj in input_data: | ||||
try: | try: | ||||
bctest(testDir, testObj, buildenv) | bctest(testDir, testObj, buildenv) | ||||
logging.info("PASSED: " + testObj["description"]) | logging.info("PASSED: " + testObj["description"]) | ||||
Show All 22 Lines | def bctest(testDir, testObj, buildenv): | ||||
execargs = testObj['args'] | execargs = testObj['args'] | ||||
execrun = [execprog] + execargs | execrun = [execprog] + execargs | ||||
# Read the input data (if there is any) | # Read the input data (if there is any) | ||||
stdinCfg = None | stdinCfg = None | ||||
inputData = None | inputData = None | ||||
if "input" in testObj: | if "input" in testObj: | ||||
filename = os.path.join(testDir, testObj["input"]) | filename = os.path.join(testDir, testObj["input"]) | ||||
inputData = open(filename).read() | inputData = open(filename, encoding="utf8").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 | outputType = None | ||||
if "output_cmp" in testObj: | if "output_cmp" in testObj: | ||||
outputFn = testObj['output_cmp'] | outputFn = testObj['output_cmp'] | ||||
# output type from file extension (determines how to compare) | # output type from file extension (determines how to compare) | ||||
outputType = os.path.splitext(outputFn)[1][1:] | outputType = os.path.splitext(outputFn)[1][1:] | ||||
try: | try: | ||||
outputData = open(os.path.join(testDir, outputFn)).read() | outputData = open(os.path.join(testDir, outputFn), | ||||
encoding="utf8").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: | if not outputType: | ||||
logging.error( | logging.error( | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |