Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_runner.py
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | def on_ci(): | ||||
return os.getenv('TRAVIS') == 'true' or os.getenv('TEAMCITY_VERSION') != None | return os.getenv('TRAVIS') == 'true' or os.getenv('TEAMCITY_VERSION') != None | ||||
def main(): | def main(): | ||||
# Read config generated by configure. | # Read config generated by configure. | ||||
config = configparser.ConfigParser() | config = configparser.ConfigParser() | ||||
configfile = os.path.join(os.path.abspath( | configfile = os.path.join(os.path.abspath( | ||||
os.path.dirname(__file__)), "..", "config.ini") | os.path.dirname(__file__)), "..", "config.ini") | ||||
config.read_file(open(configfile)) | config.read_file(open(configfile, encoding="utf8")) | ||||
src_dir = config["environment"]["SRCDIR"] | src_dir = config["environment"]["SRCDIR"] | ||||
build_dir = config["environment"]["BUILDDIR"] | build_dir = config["environment"]["BUILDDIR"] | ||||
tests_dir = os.path.join(src_dir, 'test', 'functional') | tests_dir = os.path.join(src_dir, 'test', 'functional') | ||||
# Parse arguments and pass through unrecognised args | # Parse arguments and pass through unrecognised args | ||||
parser = argparse.ArgumentParser(add_help=False, | parser = argparse.ArgumentParser(add_help=False, | ||||
usage='%(prog)s [test_runner.py options] [script options] [scripts]', | usage='%(prog)s [test_runner.py options] [script options] [scripts]', | ||||
▲ Show 20 Lines • Show All 491 Lines • ▼ Show 20 Lines | def _get_uncovered_rpc_commands(self): | ||||
coverage_ref_filename = os.path.join(self.dir, reference_filename) | coverage_ref_filename = os.path.join(self.dir, reference_filename) | ||||
coverage_filenames = set() | coverage_filenames = set() | ||||
all_cmds = set() | all_cmds = set() | ||||
covered_cmds = set() | covered_cmds = set() | ||||
if not os.path.isfile(coverage_ref_filename): | if not os.path.isfile(coverage_ref_filename): | ||||
raise RuntimeError("No coverage reference found") | raise RuntimeError("No coverage reference found") | ||||
with open(coverage_ref_filename, 'r') as f: | with open(coverage_ref_filename, 'r', encoding="utf8") as f: | ||||
all_cmds.update([i.strip() for i in f.readlines()]) | all_cmds.update([i.strip() for i in f.readlines()]) | ||||
for root, dirs, files in os.walk(self.dir): | for root, dirs, files in os.walk(self.dir): | ||||
for filename in files: | for filename in files: | ||||
if filename.startswith(coverage_file_prefix): | if filename.startswith(coverage_file_prefix): | ||||
coverage_filenames.add(os.path.join(root, filename)) | coverage_filenames.add(os.path.join(root, filename)) | ||||
for filename in coverage_filenames: | for filename in coverage_filenames: | ||||
with open(filename, 'r') as f: | with open(filename, 'r', encoding="utf8") as f: | ||||
covered_cmds.update([i.strip() for i in f.readlines()]) | covered_cmds.update([i.strip() for i in f.readlines()]) | ||||
return all_cmds - covered_cmds | return all_cmds - covered_cmds | ||||
def save_results_as_junit(test_results, file_name, time): | def save_results_as_junit(test_results, file_name, time): | ||||
""" | """ | ||||
Save tests results to file in JUnit format | Save tests results to file in JUnit format | ||||
Show All 37 Lines | class Timings(): | ||||
""" | """ | ||||
def __init__(self, timing_file): | def __init__(self, timing_file): | ||||
self.timing_file = timing_file | self.timing_file = timing_file | ||||
self.existing_timings = self.load_timings() | self.existing_timings = self.load_timings() | ||||
def load_timings(self): | def load_timings(self): | ||||
if os.path.isfile(self.timing_file): | if os.path.isfile(self.timing_file): | ||||
with open(self.timing_file) as f: | with open(self.timing_file, encoding="utf8") as f: | ||||
return json.load(f) | return json.load(f) | ||||
else: | else: | ||||
return [] | return [] | ||||
def get_merged_timings(self, new_timings): | def get_merged_timings(self, new_timings): | ||||
""" | """ | ||||
Return new list containing existing timings updated with new timings | Return new list containing existing timings updated with new timings | ||||
Tests that do not exists are not removed | Tests that do not exists are not removed | ||||
Show All 15 Lines | class Timings(): | ||||
def save_timings(self, test_results): | def save_timings(self, test_results): | ||||
# we only save test that have passed - timings for failed test might be | # we only save test that have passed - timings for failed test might be | ||||
# wrong (timeouts or early fails) | # wrong (timeouts or early fails) | ||||
passed_results = [t for t in test_results if t.status == 'Passed'] | passed_results = [t for t in test_results if t.status == 'Passed'] | ||||
new_timings = list(map(lambda t: {'name': t.name, 'time': t.time}, | new_timings = list(map(lambda t: {'name': t.name, 'time': t.time}, | ||||
passed_results)) | passed_results)) | ||||
merged_timings = self.get_merged_timings(new_timings) | merged_timings = self.get_merged_timings(new_timings) | ||||
with open(self.timing_file, 'w') as f: | with open(self.timing_file, 'w', encoding="utf8") as f: | ||||
json.dump(merged_timings, f, indent=True) | json.dump(merged_timings, f, indent=True) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |