зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1683912 Add unit test for FrameworkGatherer._urls r=sparky,perftest-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D101449
This commit is contained in:
Родитель
60ec5ad1db
Коммит
582cf18b70
|
@ -200,29 +200,46 @@ def perfdocs_sample():
|
|||
from test_perfdocs import (
|
||||
SAMPLE_TEST,
|
||||
SAMPLE_CONFIG,
|
||||
DYNAMIC_SAMPLE_CONFIG,
|
||||
SAMPLE_INI,
|
||||
temp_dir,
|
||||
temp_file,
|
||||
)
|
||||
|
||||
with temp_dir() as tmpdir:
|
||||
suite_dir = os.path.join(tmpdir, "suite")
|
||||
raptor_dir = os.path.join(tmpdir, "raptor")
|
||||
raptor_suitedir = os.path.join(tmpdir, "raptor", "suite")
|
||||
raptor_another_suitedir = os.path.join(tmpdir, "raptor", "another_suite")
|
||||
perfdocs_dir = os.path.join(tmpdir, "perfdocs")
|
||||
os.mkdir(perfdocs_dir)
|
||||
os.mkdir(suite_dir)
|
||||
os.mkdir(raptor_dir)
|
||||
os.mkdir(raptor_suitedir)
|
||||
os.mkdir(raptor_another_suitedir)
|
||||
|
||||
with temp_file(
|
||||
"perftest.ini", tempdir=suite_dir, content="[perftest_sample.js]"
|
||||
) as tmpmanifest, temp_file(
|
||||
"raptor_example1.ini", tempdir=raptor_suitedir, content=SAMPLE_INI
|
||||
) as tmpexample1manifest, temp_file(
|
||||
"raptor_example2.ini", tempdir=raptor_another_suitedir, content=SAMPLE_INI
|
||||
) as tmpexample2manifest, temp_file(
|
||||
"perftest_sample.js", tempdir=suite_dir, content=SAMPLE_TEST
|
||||
) as tmptest, temp_file(
|
||||
"config.yml", tempdir=perfdocs_dir, content=SAMPLE_CONFIG
|
||||
) as tmpconfig, temp_file(
|
||||
"config_2.yml", tempdir=perfdocs_dir, content=DYNAMIC_SAMPLE_CONFIG
|
||||
) as tmpconfig_2, temp_file(
|
||||
"index.rst", tempdir=perfdocs_dir, content="{documentation}"
|
||||
) as tmpindex:
|
||||
yield {
|
||||
"top_dir": tmpdir.replace("\\", "\\\\"),
|
||||
"manifest": tmpmanifest,
|
||||
"example1_manifest": tmpexample1manifest,
|
||||
"example2_manifest": tmpexample2manifest,
|
||||
"test": tmptest,
|
||||
"config": tmpconfig,
|
||||
"config_2": tmpconfig_2,
|
||||
"index": tmpindex,
|
||||
}
|
||||
|
|
|
@ -74,7 +74,17 @@ suites:
|
|||
suite:
|
||||
description: "Performance tests from the 'suite' folder."
|
||||
tests:
|
||||
Example: ""
|
||||
Example: "Performance test Example from suite."
|
||||
another_suite:
|
||||
description: "Performance tests from the 'another_suite' folder."
|
||||
tests:
|
||||
Example: "Performance test Example from another_suite."
|
||||
"""
|
||||
|
||||
|
||||
SAMPLE_INI = """
|
||||
[Example]
|
||||
test_url = Example_url
|
||||
"""
|
||||
|
||||
|
||||
|
@ -472,6 +482,64 @@ def test_perfdocs_framework_gatherers(logger, structured_logger, perfdocs_sample
|
|||
assert manifest == perfdocs_sample["manifest"]
|
||||
|
||||
|
||||
@mock.patch("perfdocs.logger.PerfDocLogger")
|
||||
def test_perfdocs_framework_gatherers_urls(logger, structured_logger, perfdocs_sample):
|
||||
top_dir = perfdocs_sample["top_dir"]
|
||||
setup_sample_logger(logger, structured_logger, top_dir)
|
||||
|
||||
from perfdocs.gatherer import frameworks
|
||||
from perfdocs.verifier import Verifier
|
||||
from perfdocs.generator import Generator
|
||||
from perfdocs.utils import read_yaml
|
||||
|
||||
# This test is only for raptor
|
||||
gatherer = frameworks["raptor"]
|
||||
with open(perfdocs_sample["config"], "w") as f:
|
||||
f.write(DYNAMIC_SAMPLE_CONFIG.format("raptor"))
|
||||
|
||||
fg = gatherer(perfdocs_sample["config_2"], top_dir)
|
||||
fg.get_suite_list = mock.Mock()
|
||||
fg.get_suite_list.return_value = {
|
||||
"suite": [perfdocs_sample["example1_manifest"]],
|
||||
"another_suite": [perfdocs_sample["example2_manifest"]],
|
||||
}
|
||||
|
||||
v = Verifier(top_dir)
|
||||
gn = Generator(v, generate=True, workspace=top_dir)
|
||||
|
||||
# Check to make sure that if a test is present under multiple
|
||||
# suties the urls are generated correctly for the test under
|
||||
# every suite
|
||||
for suite, suitetests in fg.get_test_list().items():
|
||||
url = fg._urls.get(suite)
|
||||
assert url is not None
|
||||
assert url[0]["test_name"] == "Example"
|
||||
assert url[0]["url"] == "Example_url"
|
||||
|
||||
perfdocs_tree = gn._perfdocs_tree[0]
|
||||
yaml_content = read_yaml(
|
||||
os.path.join(os.path.join(perfdocs_tree["path"], perfdocs_tree["yml"]))
|
||||
)
|
||||
suites = yaml_content["suites"]
|
||||
|
||||
# Check that the sections for each suite are generated correctly
|
||||
for suite_name, suite_details in suites.items():
|
||||
gn._verifier._gatherer = mock.Mock(framework_gatherers={"raptor": gatherer})
|
||||
section = gn._verifier._gatherer.framework_gatherers[
|
||||
"raptor"
|
||||
].build_suite_section(fg, suite_name, suites.get(suite_name)["description"])
|
||||
assert suite_name.capitalize() == section[0]
|
||||
assert suite_name in section[2]
|
||||
|
||||
tests = suites.get(suite_name).get("tests", {})
|
||||
for test_name in tests.keys():
|
||||
desc = gn._verifier._gatherer.framework_gatherers[
|
||||
"raptor"
|
||||
].build_test_description(fg, test_name, tests[test_name], suite_name)
|
||||
assert suite_name in desc[0]
|
||||
assert test_name in desc[0]
|
||||
|
||||
|
||||
def test_perfdocs_logger_failure(config, paths):
|
||||
from perfdocs.logger import PerfDocLogger
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче