Esempio n. 1
0
def test_diff_sorted():
    td = diff_table(
        {
            "metrics.yaml": {
                "x.b": {
                    "old": 5,
                    "new": 6,
                    "diff": 1
                },
                "a.d.e": {
                    "old": 3,
                    "new": 4,
                    "diff": 1
                },
                "a.b.c": {
                    "old": 1,
                    "new": 2,
                    "diff": 1
                },
            }
        },
        "Metric",
    )
    assert list(td) == [
        ["metrics.yaml", "a.b.c", "1", "2", "1"],
        ["metrics.yaml", "a.d.e", "3", "4", "1"],
        ["metrics.yaml", "x.b", "5", "6", "1"],
    ]
Esempio n. 2
0
def test_no_path():
    td = diff_table(
        {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}},
        title="Metric",
        no_path=True,
    )
    assert td.as_dict() == [
        {"Metric": "a.b.c", "Old": "1", "New": "2", "Change": "3"}
    ]
Esempio n. 3
0
def test_do_not_show_changes():
    td = diff_table(
        {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}},
        title="Metric",
        show_changes=False,
    )
    assert td.as_dict() == [
        {"Path": "metrics.json", "Metric": "a.b.c", "Old": "1", "New": "2"}
    ]
Esempio n. 4
0
def test_diff_falsey_values():
    diff = {"metrics.yaml": {"x.b": {"old": 0, "new": 0.0, "diff": 0.0}}}
    td = diff_table(diff, "Metric")
    assert td.as_dict() == [{
        "Path": "metrics.yaml",
        "Metric": "x.b",
        "Old": "0",
        "New": "0.0",
        "Change": "0.0",
    }]
Esempio n. 5
0
def test_diff_list(composite, expected):
    td = diff_table(
        {"params.yaml": {"a.b.c": {"old": 1, "new": composite}}}, "Param"
    )
    assert td.as_dict() == [
        {
            "Path": "params.yaml",
            "Param": "a.b.c",
            "Old": "1",
            "New": expected,
            "Change": "-",
        }
    ]
Esempio n. 6
0
def test_diff_old_deleted():
    td = diff_table(
        {"metric.json": {"a.b.d": {"old": "old", "new": None}}}, title="Metric"
    )
    assert td.as_dict() == [
        {
            "Path": "metric.json",
            "Metric": "a.b.d",
            "Old": "old",
            "New": "-",
            "Change": "-",
        }
    ]
Esempio n. 7
0
def test_diff_new():
    td = diff_table(
        {"param.json": {"a.b.d": {"old": None, "new": "new"}}}, title="Param"
    )
    assert td.as_dict() == [
        {
            "Path": "param.json",
            "Param": "a.b.d",
            "Old": "-",
            "New": "new",
            "Change": "-",
        }
    ]
Esempio n. 8
0
def test_diff_table(title):
    td = diff_table(
        {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}},
        title=title,
    )
    assert td.as_dict() == [
        {
            "Path": "metrics.json",
            title: "a.b.c",
            "Old": "1",
            "New": "2",
            "Change": "3",
        }
    ]
Esempio n. 9
0
def test_diff_table_with_value_column():
    td = diff_table(
        {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}},
        title="Metric",
        old=False,
    )
    assert td.as_dict() == [
        {
            "Path": "metrics.json",
            "Metric": "a.b.c",
            "Value": "2",
            "Change": "3",
        }
    ]
Esempio n. 10
0
def test_diff_unsupported_diff_message(extra, expected):
    td = diff_table(
        {"metrics.json": {"": {"old": "1", "new": "2"}}},
        title="Metric",
        **extra
    )
    assert td.as_dict() == [
        {
            "Path": "metrics.json",
            "Metric": "",
            "Old": "1",
            "New": "2",
            "Change": expected,
        }
    ]
Esempio n. 11
0
def test_diff_table_rounding():
    diff = {
        "metrics.json": {
            "a.b.c": {"old": 1.1234, "new": 2.2345, "diff": 3.3456}
        }
    }
    td = diff_table(diff, title="Metric", precision=3, round_digits=True)
    assert td.as_dict() == [
        {
            "Path": "metrics.json",
            "Metric": "a.b.c",
            "Old": "1.123",
            "New": "2.235",
            "Change": "3.346",
        }
    ]
Esempio n. 12
0
def test_diff_table_precision():
    diff = {
        "metrics.json": {
            "a.b.c": {
                "old": 1.1234,
                "new": 2.2345,
                "diff": 3.3456
            }
        }
    }
    td = diff_table(diff, title="Metric", precision=3)
    assert td.as_dict() == [{
        "Path": "metrics.json",
        "Metric": "a.b.c",
        "HEAD": "1.12",
        "workspace": "2.23",
        "Change": "3.35",
    }]