def test_metrics_diff_new_metric(): assert _show_diff( {"other.json": {"a.b.d": {"old": None, "new": "new"}}} ) == ( " Path Metric Value Change \n" "other.json a.b.d new diff not supported" )
def test_metrics_diff_with_old(): assert _show_diff( { "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 }, } }, old=True, ) == textwrap.dedent("""\ Path Metric Old New Change metrics.yaml a.b.c 1 2 1 metrics.yaml a.d.e 3 4 1 metrics.yaml x.b 5 6 1""")
def test_metrics_show_json_diff(): assert _show_diff( {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}} ) == ( " Path Metric Value Change\n" "metrics.json a.b.c 2 3 " )
def test_metrics_diff_markdown_empty(): assert _show_diff({}, markdown=True) == textwrap.dedent( """\ | Path | Metric | Old | New | Change | |--------|----------|-------|-------|----------| """ )
def test_metrics_diff_markdown(): assert _show_diff( { "metrics.yaml": { "x.b": { "old": 5, "new": 6 }, "a.d.e": { "old": 3, "new": 4, "diff": 1 }, "a.b.c": { "old": 1, "new": 2, "diff": 1 }, } }, markdown=True, ) == textwrap.dedent("""\ | Path | Metric | Value | Change | |--------------|----------|---------|--------------------| | metrics.yaml | a.b.c | 2 | 1 | | metrics.yaml | a.d.e | 4 | 1 | | metrics.yaml | x.b | 6 | diff not supported | """)
def test_metrics_diff_prec(): assert _show_diff( {"other.json": {"a.b": {"old": 0.0042, "new": 0.0043, "diff": 0.0001}}} ) == ( " Path Metric Value Change\n" "other.json a.b 0.0043 0.0001" )
def test_metrics_diff_deleted_metric(): assert _show_diff( {"other.json": {"a.b.d": {"old": "old", "new": None}}} ) == ( " Path Metric Value Change \n" "other.json a.b.d None diff not supported" )
def test_metrics_diff_no_path(): assert _show_diff( { "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 }, } }, no_path=True, ) == textwrap.dedent("""\ Metric Value Change a.b.c 2 1 a.d.e 4 1 x.b 6 1""")
def test_metrics_diff_deleted_metric(): assert _show_diff( {"other.json": {"a.b.d": {"old": "old", "new": None}}} ) == textwrap.dedent( """\ Path Metric Old New Change other.json a.b.d old — —""" )
def test_metrics_show_raw_diff(): assert _show_diff({"metrics": { "": { "old": "1", "new": "2" } }}) == (" Path Metric Value Change \n" "metrics 2 diff not supported")
def test_metrics_show_json_diff(): assert _show_diff( {"metrics.json": {"a.b.c": {"old": 1, "new": 2, "diff": 3}}} ) == textwrap.dedent( """\ Path Metric Old New Change metrics.json a.b.c 1 2 3""" )
def test_metrics_diff_deleted_metric(): assert _show_diff( {"other.json": {"a.b.d": {"old": "old", "new": None}}} ) == textwrap.dedent( """\ Path Metric Value Change other.json a.b.d None diff not supported""" )
def test_metrics_show_raw_diff(): assert _show_diff( {"metrics": {"": {"old": "1", "new": "2"}}} ) == textwrap.dedent( """\ Path Metric Value Change metrics 2 diff not supported""" )
def test_metrics_diff_prec(): assert _show_diff( {"other.json": {"a.b": {"old": 0.0042, "new": 0.0043, "diff": 0.0001}}} ) == textwrap.dedent( """\ Path Metric Value Change other.json a.b 0.0043 0.0001""" )
def test_metrics_show_raw_diff(): assert _show_diff( {"metrics": {"": {"old": "1", "new": "2"}}} ) == textwrap.dedent( """\ Path Metric Old New Change metrics 1 2 —""" )
def test_metrics_diff_new_metric(): assert _show_diff( {"other.json": {"a.b.d": {"old": None, "new": "new"}}} ) == textwrap.dedent( """\ Path Metric Old New Change other.json a.b.d — new —""" )
def test_metrics_diff_precision(): diff = { "other.json": { "a.b": { "old": 0.1234567, "new": 0.765432101234567, "diff": 0.641975401234567, } } } assert _show_diff(diff) == textwrap.dedent("""\ Path Metric Value Change other.json a.b 0.76543 0.64198""") assert _show_diff(diff, precision=10) == textwrap.dedent("""\ Path Metric Value Change other.json a.b 0.7654321012 0.6419754012""")
def test_metrics_diff_sorted(): assert _show_diff( { "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}, } } ) == textwrap.dedent( """\ Path Metric Value Change metrics.yaml a.b.c 2 1 metrics.yaml a.d.e 4 1 metrics.yaml x.b 6 1""" )
def test_metrics_diff_sorted(): assert _show_diff({ "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 }, } }) == (" Path Metric Value Change\n" "metrics.yaml a.b.c 2 1 \n" "metrics.yaml a.d.e 4 1 \n" "metrics.yaml x.b 6 1 ")
def test_metrics_diff_no_changes(): assert _show_diff({}) == ""