Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_runner.py
Show All 24 Lines | |||||
import tempfile | import tempfile | ||||
import re | import re | ||||
import logging | import logging | ||||
import xml.etree.ElementTree as ET | import xml.etree.ElementTree as ET | ||||
import json | import json | ||||
import threading | import threading | ||||
import multiprocessing | import multiprocessing | ||||
from queue import Queue, Empty | from queue import Queue, Empty | ||||
import unittest | |||||
# Formatting. Default colors to empty strings. | # Formatting. Default colors to empty strings. | ||||
BOLD, GREEN, RED, GREY = ("", ""), ("", ""), ("", ""), ("", "") | BOLD, GREEN, RED, GREY = ("", ""), ("", ""), ("", ""), ("", "") | ||||
try: | try: | ||||
# Make sure python thinks it can write unicode to its stdout | # Make sure python thinks it can write unicode to its stdout | ||||
"\u2713".encode("utf_8").decode(sys.stdout.encoding) | "\u2713".encode("utf_8").decode(sys.stdout.encoding) | ||||
TICK = "✓ " | TICK = "✓ " | ||||
CROSS = "✖ " | CROSS = "✖ " | ||||
Show All 27 Lines | if os.name != 'nt' or sys.getwindowsversion() >= (10, 0, 14393): | ||||
BOLD = ('\033[0m', '\033[1m') | BOLD = ('\033[0m', '\033[1m') | ||||
GREEN = ('\033[0m', '\033[0;32m') | GREEN = ('\033[0m', '\033[0;32m') | ||||
RED = ('\033[0m', '\033[0;31m') | RED = ('\033[0m', '\033[0;31m') | ||||
GREY = ('\033[0m', '\033[1;30m') | GREY = ('\033[0m', '\033[1;30m') | ||||
TEST_EXIT_PASSED = 0 | TEST_EXIT_PASSED = 0 | ||||
TEST_EXIT_SKIPPED = 77 | TEST_EXIT_SKIPPED = 77 | ||||
TEST_FRAMEWORK_MODULES = [ | |||||
"script", | |||||
] | |||||
NON_SCRIPTS = [ | NON_SCRIPTS = [ | ||||
# These are python files that live in the functional tests directory, but | # These are python files that live in the functional tests directory, but | ||||
# are not test scripts. | # are not test scripts. | ||||
"combine_logs.py", | "combine_logs.py", | ||||
"create_cache.py", | "create_cache.py", | ||||
"test_runner.py", | "test_runner.py", | ||||
] | ] | ||||
▲ Show 20 Lines • Show All 269 Lines • ▼ Show 20 Lines | except (OSError, subprocess.SubprocessError): | ||||
pass | pass | ||||
# Warn if there is a cache directory | # Warn if there is a cache directory | ||||
cache_dir = os.path.join(build_dir, "test", "cache") | cache_dir = os.path.join(build_dir, "test", "cache") | ||||
if os.path.isdir(cache_dir): | if os.path.isdir(cache_dir): | ||||
print("{}WARNING!{} There is a cache directory here: {}. If tests fail unexpectedly, try deleting the cache directory.".format( | print("{}WARNING!{} There is a cache directory here: {}. If tests fail unexpectedly, try deleting the cache directory.".format( | ||||
BOLD[1], BOLD[0], cache_dir)) | BOLD[1], BOLD[0], cache_dir)) | ||||
# Test Framework Tests | |||||
print("Running Unit Tests for Test Framework Modules") | |||||
test_framework_tests = unittest.TestSuite() | |||||
for module in TEST_FRAMEWORK_MODULES: | |||||
test_framework_tests.addTest( | |||||
unittest.TestLoader().loadTestsFromName( | |||||
"test_framework.{}".format(module))) | |||||
result = unittest.TextTestRunner( | |||||
verbosity=1, failfast=True).run(test_framework_tests) | |||||
if not result.wasSuccessful(): | |||||
logging.debug( | |||||
"Early exiting after failure in TestFramework unit tests") | |||||
sys.exit(False) | |||||
flags = ['--cachedir={}'.format(cache_dir)] + args | flags = ['--cachedir={}'.format(cache_dir)] + args | ||||
if enable_coverage: | if enable_coverage: | ||||
coverage = RPCCoverage() | coverage = RPCCoverage() | ||||
flags.append(coverage.flag) | flags.append(coverage.flag) | ||||
logging.debug( | logging.debug( | ||||
"Initializing coverage directory at {}".format(coverage.dir)) | "Initializing coverage directory at {}".format(coverage.dir)) | ||||
else: | else: | ||||
▲ Show 20 Lines • Show All 282 Lines • ▼ Show 20 Lines | def check_script_prefixes(all_scripts): | ||||
EXPECTED_VIOLATION_COUNT = 16 | EXPECTED_VIOLATION_COUNT = 16 | ||||
# LEEWAY is provided as a transition measure, so that pull-requests | # LEEWAY is provided as a transition measure, so that pull-requests | ||||
# that introduce new tests that don't conform with the naming | # that introduce new tests that don't conform with the naming | ||||
# convention don't immediately cause the tests to fail. | # convention don't immediately cause the tests to fail. | ||||
LEEWAY = 0 | LEEWAY = 0 | ||||
good_prefixes_re = re.compile( | good_prefixes_re = re.compile( | ||||
"(abc_)?(example|feature|interface|mempool|mining|p2p|rpc|wallet|tool|framework_test)_") | "(abc_)?(example|feature|interface|mempool|mining|p2p|rpc|wallet|tool)_") | ||||
bad_script_names = [ | bad_script_names = [ | ||||
script for script in all_scripts if good_prefixes_re.match(script) is None] | script for script in all_scripts if good_prefixes_re.match(script) is None] | ||||
if len(bad_script_names) < EXPECTED_VIOLATION_COUNT: | if len(bad_script_names) < EXPECTED_VIOLATION_COUNT: | ||||
print( | print( | ||||
"{}HURRAY!{} Number of functional tests violating naming convention reduced!".format( | "{}HURRAY!{} Number of functional tests violating naming convention reduced!".format( | ||||
BOLD[1], | BOLD[1], | ||||
BOLD[0])) | BOLD[0])) | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |