From 54c62668526cd0d812871600208cbc357bbdab12 Mon Sep 17 00:00:00 2001 From: Kernc Date: Sat, 13 Feb 2021 01:55:04 +0100 Subject: [PATCH 1/2] =?UTF-8?q?TST:=20Make=20test=5Flinking=5Fnaisc=5Fexec?= =?UTF-8?q?utable=20deterministic=20on=20CI=20=F0=9F=98=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_linking.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/test_linking.py b/tests/test_linking.py index 7b8fdb4..fc1b11b 100644 --- a/tests/test_linking.py +++ b/tests/test_linking.py @@ -3,10 +3,12 @@ from pathlib import Path import pytest +from bson import ObjectId from pytest_httpserver import HTTPServer from pytest_httpserver.httpserver import Response import app.linking.ops +from app.db import get_db_sync from app.settings import _Settings pytestmark = pytest.mark.asyncio @@ -61,12 +63,17 @@ async def test_linking_remote_endpoint(client, example_id, monkeypatch, httpserv async def test_linking_naisc_executable(client, example_id, monkeypatch, httpserver, example_entry_ids): + entry_id = example_entry_ids[0] + with get_db_sync() as db: + entry = db.entry.find_one({'_id': ObjectId(entry_id)}) + sense_id = entry['senses'][0]['id'] + linking_result = [{ 'source_entry': example_entry_ids[0], 'target_entry': example_entry_ids[0], 'linking': [{ - 'source_sense': 'cat-n-1', - 'target_sense': 'cat-n-1', + 'source_sense': sense_id, + 'target_sense': sense_id, 'type': 'exact', 'score': 0.8, }], From fb07eaabc56ef5fa2b9c79cbdf87a4bc135af8da Mon Sep 17 00:00:00 2001 From: Kernc Date: Sat, 13 Feb 2021 02:02:19 +0100 Subject: [PATCH 2/2] Hard-code the sense id values in _mock_naisc script The underlying issue is RDFLib's Turtle serializer not outputting statements in consistent order. --- tests/_mock_naisc.py | 5 +++-- tests/test_linking.py | 11 ++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/tests/_mock_naisc.py b/tests/_mock_naisc.py index e8939c4..209e65b 100755 --- a/tests/_mock_naisc.py +++ b/tests/_mock_naisc.py @@ -6,8 +6,9 @@ file1, file2 = sys.argv[1:3] text1 = open(file1).read() text2 = open(file2).read() - sense_id1 = re.search(r':sense <(.+?)>', text1).group(1) # type: ignore - sense_id2 = re.search(r':sense <(.+?)>', text2).group(1) # type: ignore + # Find 'cat-n-1' sense in both texts + sense_id1 = re.search(r':sense <(.+?-n-1)>', text1).group(1) # type: ignore + sense_id2 = re.search(r':sense <(.+?-n-1)>', text2).group(1) # type: ignore print(f'<{file1}#{sense_id1}> ' f' ' f'<{file2}#{sense_id2}> . # 0.8000') diff --git a/tests/test_linking.py b/tests/test_linking.py index fc1b11b..7b8fdb4 100644 --- a/tests/test_linking.py +++ b/tests/test_linking.py @@ -3,12 +3,10 @@ from pathlib import Path import pytest -from bson import ObjectId from pytest_httpserver import HTTPServer from pytest_httpserver.httpserver import Response import app.linking.ops -from app.db import get_db_sync from app.settings import _Settings pytestmark = pytest.mark.asyncio @@ -63,17 +61,12 @@ async def test_linking_remote_endpoint(client, example_id, monkeypatch, httpserv async def test_linking_naisc_executable(client, example_id, monkeypatch, httpserver, example_entry_ids): - entry_id = example_entry_ids[0] - with get_db_sync() as db: - entry = db.entry.find_one({'_id': ObjectId(entry_id)}) - sense_id = entry['senses'][0]['id'] - linking_result = [{ 'source_entry': example_entry_ids[0], 'target_entry': example_entry_ids[0], 'linking': [{ - 'source_sense': sense_id, - 'target_sense': sense_id, + 'source_sense': 'cat-n-1', + 'target_sense': 'cat-n-1', 'type': 'exact', 'score': 0.8, }],