Esempio n. 1
0
def test_transform(data):
    tfm = SingleJsonRetriever()

    expected_result = [{
        "data": [
            {
                "value": 101,
                "xaxis": 1
            },
            {
                "value": 102,
                "xaxis": 1
            },
            {
                "value": 103,
                "xaxis": 1
            },
        ],
        "subtest":
        "browserScripts.timings.firstPaint",
    }]

    actual_result = tfm.transform(data["data_1"])

    assert actual_result == expected_result
def test_process(files):
    files, _, _ = files
    file_1 = files["file_1"]
    file_2 = files["file_2"]

    tfm = SingleJsonRetriever()
    tfm.files = [file_1, file_2]

    expected_result = [{
        "data": [
            {
                "value": 101,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 102,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 103,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 201,
                "xaxis": 2,
                "file": file_2
            },
            {
                "value": 202,
                "xaxis": 2,
                "file": file_2
            },
            {
                "value": 203,
                "xaxis": 2,
                "file": file_2
            },
        ],
        "subtest":
        "browserScripts.timings.firstPaint",
        "name":
        "group_1",
    }]

    actual_result = tfm.process("group_1")

    assert actual_result == expected_result
Esempio n. 3
0
def test_merge(data):
    tfm = SingleJsonRetriever()
    sde = tfm.transform(data["data_1"])
    sde.extend(tfm.transform(data["data_2"]))

    expected_result = [{
        "data": [
            {
                "value": 101,
                "xaxis": 1
            },
            {
                "value": 102,
                "xaxis": 1
            },
            {
                "value": 103,
                "xaxis": 1
            },
            {
                "value": 201,
                "xaxis": 2
            },
            {
                "value": 202,
                "xaxis": 2
            },
            {
                "value": 203,
                "xaxis": 2
            },
        ],
        "subtest":
        "browserScripts.timings.firstPaint",
    }]

    actual_result = tfm.merge(sde)

    assert actual_result == expected_result
Esempio n. 4
0
def test_process(ptnbs, files):
    # Temporary resource files.
    files, _, output = files
    file_1 = files["file_1"]
    file_2 = files["file_2"]

    # Create expected output.
    expected_output = [{
        "data": [
            {
                "value": 101,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 102,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 103,
                "xaxis": 1,
                "file": file_1
            },
            {
                "value": 201,
                "xaxis": 2,
                "file": file_2
            },
            {
                "value": 202,
                "xaxis": 2,
                "file": file_2
            },
            {
                "value": 203,
                "xaxis": 2,
                "file": file_2
            },
        ],
        "name":
        "group_1",
        "subtest":
        "browserScripts.timings.firstPaint",
    }]

    ptnb = ptnbs["ptnb_str"]

    # Set a custom transformer.
    ptnb.transformer = Transformer([], SingleJsonRetriever())

    # Create expected result.
    expected_result = {
        "data": expected_output,
        "file-output": output,
    }

    # Check return value.
    actual_result = ptnb.process()
    assert actual_result == expected_result

    # Check output file.
    with pathlib.Path(output).open() as f:
        actual_output = json.load(f)

    assert expected_output == actual_output