From 232e953b148e1dd9259a34bcbc64aec1d7786e08 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Tue, 12 Jan 2021 20:32:57 +0100 Subject: [PATCH] pytest.approx with absolute eps --- spacy/tests/parser/test_parse.py | 72 ++++++++++++++++---------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/spacy/tests/parser/test_parse.py b/spacy/tests/parser/test_parse.py index 437cc760c..5b68bbc37 100644 --- a/spacy/tests/parser/test_parse.py +++ b/spacy/tests/parser/test_parse.py @@ -360,25 +360,25 @@ def test_beam_overfitting_IO(): head_scores = head_scores[0] label_scores = label_scores[0] # test label annotations: 0=nsubj, 2=dobj, 3=punct - assert label_scores[(0, "nsubj")] == pytest.approx(1.0, eps) - assert label_scores[(0, "dobj")] == pytest.approx(0.0, eps) - assert label_scores[(0, "punct")] == pytest.approx(0.0, eps) - assert label_scores[(2, "nsubj")] == pytest.approx(0.0, eps) - assert label_scores[(2, "dobj")] == pytest.approx(1.0, eps) - assert label_scores[(2, "punct")] == pytest.approx(0.0, eps) - assert label_scores[(3, "nsubj")] == pytest.approx(0.0, eps) - assert label_scores[(3, "dobj")] == pytest.approx(0.0, eps) - assert label_scores[(3, "punct")] == pytest.approx(1.0, eps) + assert label_scores[(0, "nsubj")] == pytest.approx(1.0, abs=eps) + assert label_scores[(0, "dobj")] == pytest.approx(0.0, abs=eps) + assert label_scores[(0, "punct")] == pytest.approx(0.0, abs=eps) + assert label_scores[(2, "nsubj")] == pytest.approx(0.0, abs=eps) + assert label_scores[(2, "dobj")] == pytest.approx(1.0, abs=eps) + assert label_scores[(2, "punct")] == pytest.approx(0.0, abs=eps) + assert label_scores[(3, "nsubj")] == pytest.approx(0.0, abs=eps) + assert label_scores[(3, "dobj")] == pytest.approx(0.0, abs=eps) + assert label_scores[(3, "punct")] == pytest.approx(1.0, abs=eps) # test head annotations: the root is token at index 1 - assert head_scores[(0, 0)] == pytest.approx(0.0, eps) - assert head_scores[(0, 1)] == pytest.approx(1.0, eps) - assert head_scores[(0, 2)] == pytest.approx(0.0, eps) - assert head_scores[(2, 0)] == pytest.approx(0.0, eps) - assert head_scores[(2, 1)] == pytest.approx(1.0, eps) - assert head_scores[(2, 2)] == pytest.approx(0.0, eps) - assert head_scores[(3, 0)] == pytest.approx(0.0, eps) - assert head_scores[(3, 1)] == pytest.approx(1.0, eps) - assert head_scores[(3, 2)] == pytest.approx(0.0, eps) + assert head_scores[(0, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores[(0, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores[(0, 2)] == pytest.approx(0.0, abs=eps) + assert head_scores[(2, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores[(2, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores[(2, 2)] == pytest.approx(0.0, abs=eps) + assert head_scores[(3, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores[(3, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores[(3, 2)] == pytest.approx(0.0, abs=eps) # Also test the results are still the same after IO with make_tempdir() as tmp_dir: @@ -392,21 +392,21 @@ def test_beam_overfitting_IO(): head_scores2 = head_scores2[0] label_scores2 = label_scores2[0] # check the results again - assert label_scores2[(0, "nsubj")] == pytest.approx(1.0, eps) - assert label_scores2[(0, "dobj")] == pytest.approx(0.0, eps) - assert label_scores2[(0, "punct")] == pytest.approx(0.0, eps) - assert label_scores2[(2, "nsubj")] == pytest.approx(0.0, eps) - assert label_scores2[(2, "dobj")] == pytest.approx(1.0, eps) - assert label_scores2[(2, "punct")] == pytest.approx(0.0, eps) - assert label_scores2[(3, "nsubj")] == pytest.approx(0.0, eps) - assert label_scores2[(3, "dobj")] == pytest.approx(0.0, eps) - assert label_scores2[(3, "punct")] == pytest.approx(1.0, eps) - assert head_scores2[(0, 0)] == pytest.approx(0.0, eps) - assert head_scores2[(0, 1)] == pytest.approx(1.0, eps) - assert head_scores2[(0, 2)] == pytest.approx(0.0, eps) - assert head_scores2[(2, 0)] == pytest.approx(0.0, eps) - assert head_scores2[(2, 1)] == pytest.approx(1.0, eps) - assert head_scores2[(2, 2)] == pytest.approx(0.0, eps) - assert head_scores2[(3, 0)] == pytest.approx(0.0, eps) - assert head_scores2[(3, 1)] == pytest.approx(1.0, eps) - assert head_scores2[(3, 2)] == pytest.approx(0.0, eps) + assert label_scores2[(0, "nsubj")] == pytest.approx(1.0, abs=eps) + assert label_scores2[(0, "dobj")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(0, "punct")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(2, "nsubj")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(2, "dobj")] == pytest.approx(1.0, abs=eps) + assert label_scores2[(2, "punct")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(3, "nsubj")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(3, "dobj")] == pytest.approx(0.0, abs=eps) + assert label_scores2[(3, "punct")] == pytest.approx(1.0, abs=eps) + assert head_scores2[(0, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores2[(0, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores2[(0, 2)] == pytest.approx(0.0, abs=eps) + assert head_scores2[(2, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores2[(2, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores2[(2, 2)] == pytest.approx(0.0, abs=eps) + assert head_scores2[(3, 0)] == pytest.approx(0.0, abs=eps) + assert head_scores2[(3, 1)] == pytest.approx(1.0, abs=eps) + assert head_scores2[(3, 2)] == pytest.approx(0.0, abs=eps)