зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1630610 - Add setup function for pytest. r=sparky
Depends on D73154 Differential Revision: https://phabricator.services.mozilla.com/D73926
This commit is contained in:
Родитель
118aa2368b
Коммит
a8fc57d316
|
@ -0,0 +1,82 @@
|
|||
import json
|
||||
import pathlib
|
||||
import pytest
|
||||
from mozperftest.tests.support import temp_dir
|
||||
from mozperftest.metrics.notebook.perftestnotebook import PerftestNotebook
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def data():
|
||||
data_1 = {
|
||||
"browserScripts": [
|
||||
{"timings": {"firstPaint": 101}},
|
||||
{"timings": {"firstPaint": 102}},
|
||||
{"timings": {"firstPaint": 103}},
|
||||
],
|
||||
}
|
||||
|
||||
data_2 = {
|
||||
"browserScripts": [
|
||||
{"timings": {"firstPaint": 201}},
|
||||
{"timings": {"firstPaint": 202}},
|
||||
{"timings": {"firstPaint": 203}},
|
||||
],
|
||||
}
|
||||
|
||||
data_3 = {
|
||||
"browserScripts": [
|
||||
{"timings": {"firstPaint": 301}},
|
||||
{"timings": {"firstPaint": 302}},
|
||||
{"timings": {"firstPaint": 303}},
|
||||
],
|
||||
}
|
||||
|
||||
yield {"data_1": data_1, "data_2": data_2, "data_3": data_3}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def files(data):
|
||||
# Create a temporary directory.
|
||||
with temp_dir() as td:
|
||||
tmp_path = pathlib.Path(td)
|
||||
|
||||
dirs = {
|
||||
"resources": tmp_path / "resources",
|
||||
"output": tmp_path / "output",
|
||||
}
|
||||
|
||||
for d in dirs.values():
|
||||
d.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Create temporary data files for tests.
|
||||
def _create_temp_files(path, data):
|
||||
path.touch(exist_ok=True)
|
||||
path.write_text(data)
|
||||
return path.resolve().as_posix()
|
||||
|
||||
resources = {}
|
||||
json_1 = dirs["resources"] / "file_1.json"
|
||||
resources["file_1"] = _create_temp_files(json_1, json.dumps(data["data_1"]))
|
||||
|
||||
json_2 = dirs["resources"] / "file_2.json"
|
||||
resources["file_2"] = _create_temp_files(json_2, json.dumps(data["data_2"]))
|
||||
|
||||
txt_3 = dirs["resources"] / "file_3.txt"
|
||||
resources["file_3"] = _create_temp_files(txt_3, json.dumps(data["data_3"]))
|
||||
|
||||
output = dirs["output"] / "output.json"
|
||||
|
||||
yield resources, dirs, output.resolve().as_posix()
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def ptnbs(files):
|
||||
resources, dirs, output = files
|
||||
config = {"output": output}
|
||||
file_group_list = {"group_1": list(resources.values())}
|
||||
file_group_str = {"group_1": dirs["resources"].resolve().as_posix()}
|
||||
|
||||
yield {
|
||||
"ptnb_list": PerftestNotebook(file_group_list, config, sort_files=True),
|
||||
"ptnb_str": PerftestNotebook(file_group_str, config, sort_files=True),
|
||||
}
|
Загрузка…
Ссылка в новой задаче