Skip to content

Commit 8e3375c

Browse files
Updated - fixed minors
1 parent f6e8c64 commit 8e3375c

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

rre-dataset-generator/src/model/query_rating_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ def to_dict(self) -> Dict[str, Any]:
7070
"query_id": self._id,
7171
"query_text": self._query,
7272
"doc_ratings": self._doc_id_to_rating_score
73-
}
73+
}
74+

rre-dataset-generator/tests/unit/test_data_store.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,68 +29,68 @@ def sample_store():
2929

3030
@pytest.fixture
3131
def set_tmp_file(tmp_path, monkeypatch):
32-
"""Fija la ruta del datastore a un archivo temporal y la devuelve."""
32+
"""Sets the datastore path to a temporary file and returns it."""
3333
path = tmp_path / "datastore.json"
3434
monkeypatch.setattr(data_store, "TMP_FILE", str(path), raising=False)
3535
return path
3636

3737

38-
def test_add_and_get_document(empty_store):
38+
def test_datastore_add_and_get_document__expects__retrieve(empty_store):
3939
doc = Document(id="dX", fields={"title": "New"})
4040
empty_store.add_document("dX", doc)
4141
assert empty_store.get_document("dX") == doc
4242

4343

44-
def test_add_duplicate_document_raises(empty_store):
44+
def test_datastore_add_duplicate_document__expects__raises_error(empty_store):
4545
doc = Document(id="d1", fields={"text": "some text"})
4646
empty_store.add_document("d1", doc)
4747
with pytest.raises(KeyError):
4848
empty_store.add_document("d1", doc)
4949

5050

51-
def test_add_query_rating_and_has_rating_flag(empty_store):
51+
def test_datastore_add_query__expect__query_rating_and_has_rating(empty_store):
5252
qid = empty_store.add_query("test", doc_id="d1")
53-
# centinela: sin rating aún
53+
# sentinel: without rating yet
5454
assert empty_store.has_rating_score(qid, "d1") is False
5555
empty_store.add_rating_score(qid, "d1", 1)
5656
assert empty_store.get_rating_score(qid, "d1") == 1
5757
assert empty_store.has_rating_score(qid, "d1") is True
5858

5959

60-
def test_add_query_same_text_returns_same_id_and_adds_doc(empty_store):
60+
def test_datastore_add_query__expect__same_text_returns_same_id_and_adds_doc(empty_store):
6161
qid1 = empty_store.add_query("Q", doc_id="d1")
62-
# mismo texto de query -> mismo id; añade doc_id nuevo
62+
# same query text -> same id; adds new doc_id
6363
qid2 = empty_store.add_query("Q", doc_id="d2")
6464
assert qid1 == qid2
6565
ctx = empty_store.get_query(qid1)
6666
assert set(ctx.get_doc_ids()) == {"d1", "d2"}
67-
# el nuevo doc todavía no tiene rating
67+
# the new doc still has no rating
6868
assert empty_store.has_rating_score(qid1, "d2") is False
6969

7070

71-
def test_save_raises_if_query_refs_missing_doc(empty_store, set_tmp_file):
72-
# referencia a doc inexistente -> save debe fallar
71+
def test_datastore_save__expect__raises_if_query_references_missing_doc(empty_store, set_tmp_file):
72+
# reference to non-existent doc -> save must fail
7373
qid = empty_store.add_query("missing-doc-case", doc_id="d_missing")
7474
with pytest.raises(KeyError):
7575
empty_store.save_tmp_file_content()
7676

7777

78-
def test_save_and_load_roundtrip(set_tmp_file):
78+
def test_datastore_save_and_load__expects__valid_happy_path(set_tmp_file):
7979
ds1 = DataStore(ignore_saved_data=True)
8080
doc = Document(id="d1", fields={"text": "some text"})
8181
ds1.add_document("d1", doc)
8282
qid = ds1.add_query("test", doc_id="d1")
8383
ds1.add_rating_score(qid, "d1", 1)
8484
ds1.save_tmp_file_content()
8585

86-
# Carga automática en __init__ porque ignore_saved_data=False
86+
# Auto load in __init__ because ignore_saved_data=False
8787
ds2 = DataStore(ignore_saved_data=False)
8888
assert ds2.get_query(qid).get_query_text() == "test"
8989
assert ds2.get_rating_score(qid, "d1") == 1
9090
assert ds2.get_document("d1") == doc
9191

9292

93-
def test_load_with_duplicate_query_text(set_tmp_file):
93+
def test_datastore_load__expects__error_on_duplicate_query_text(set_tmp_file):
9494
content = {
9595
"queries": {
9696
"q1": {"query_id": "q1", "query_text": "dup", "doc_ratings": {}},
@@ -105,18 +105,18 @@ def test_load_with_duplicate_query_text(set_tmp_file):
105105

106106

107107
@pytest.mark.parametrize("content", [
108-
# Mismatch outer (key) vs inner query_id -> debe fallar
108+
# Mismatch outer (key) vs inner query_id -> must fail
109109
{
110110
"queries": {"q1": {"query_id": "DIFF", "query_text": "x", "doc_ratings": {}}},
111111
"documents": {},
112112
},
113-
# Documento con id interno distinto al de la clave -> debe fallar
113+
# Document with internal id different from the key -> must fail
114114
{
115115
"queries": {},
116116
"documents": {"d1": {"id": "dX", "fields": {"text": "x"}}},
117117
},
118118
])
119-
def test_load_rejects_inconsistent_payloads(set_tmp_file, content):
119+
def test_datastore_load__expects__rejects_inconsistent_payloads(set_tmp_file, content):
120120
set_tmp_file.write_text(json.dumps(content), encoding="utf-8")
121121
ds = DataStore(ignore_saved_data=True)
122122
with pytest.raises(KeyError):

0 commit comments

Comments
 (0)