Bug 1513577 - [reftest] Refactor the runtests fixture to a more re-useable 'get_reftest' fixture, r=jmaher

This will make it easier for new tests to get a handle on a RefTest instance so
they can do a wider variety of unittesting.

Depends on D14300

Differential Revision: https://phabricator.services.mozilla.com/D14301

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Halberstadt 2018-12-14 16:42:56 +00:00
Родитель 70f627bfde
Коммит b44af2311d
1 изменённых файлов: 43 добавлений и 11 удалений

Просмотреть файл

@ -16,6 +16,20 @@ here = os.path.abspath(os.path.dirname(__file__))
setup_args = [False, 'reftest', 'reftest']
@pytest.fixture(scope='module')
def normalize():
"""A function that can take a relative path and append it to the 'files'
directory which contains the data necessary to run these tests.
"""
def inner(path):
if os.path.isabs(path):
return path
return os.path.join(here, 'files', path)
return inner
@pytest.fixture # noqa: F811
def parser(setup_test_harness):
setup_test_harness(*setup_args)
@ -24,18 +38,16 @@ def parser(setup_test_harness):
@pytest.fixture # noqa: F811
def runtests(setup_test_harness, binary, parser):
def get_reftest(setup_test_harness, binary, parser):
setup_test_harness(*setup_args)
runreftest = pytest.importorskip('runreftest')
harness_root = runreftest.SCRIPT_DIRECTORY
buf = StringIO()
build = parser.build_obj
options = vars(parser.parse_args([]))
options.update({
'app': binary,
'focusFilterMode': 'non-needs-focus',
'log_raw': [buf],
'suite': 'reftest',
})
@ -59,19 +71,39 @@ def runtests(setup_test_harness, binary, parser):
build.distdir, 'xpi-stage', 'specialpowers'),
})
def normalize(test):
if os.path.isabs(test):
return test
return os.path.join(here, 'files', test)
def inner(**opts):
options.update(opts)
config = Namespace(**options)
# This is pulled from `runreftest.run_test_harness` minus some error
# checking that isn't necessary in this context. It should stay roughly
# in sync.
reftest = runreftest.RefTest(config.suite)
parser.validate(config, reftest)
config.app = reftest.getFullPath(config.app)
assert os.path.exists(config.app)
if config.xrePath is None:
config.xrePath = os.path.dirname(config.app)
return reftest, config
return inner
@pytest.fixture # noqa: F811
def runtests(get_reftest, normalize):
def inner(*tests, **opts):
assert len(tests) > 0
tests = map(normalize, tests)
opts['tests'] = map(normalize, tests)
options['tests'] = tests
options.update(opts)
buf = StringIO()
opts['log_raw'] = [buf]
reftest, options = get_reftest(**opts)
result = reftest.runTests(options.tests, options)
result = runreftest.run_test_harness(parser, Namespace(**options))
out = json.loads('[' + ','.join(buf.getvalue().splitlines()) + ']')
buf.close()
return result, out