From e956ea93505a447ea9a770e7043f95cd19c196aa Mon Sep 17 00:00:00 2001 From: Emilie Delattre Date: Mon, 19 Sep 2022 15:53:05 +0200 Subject: [PATCH 1/4] Add topic field in Article --- src/bluesearch/database/article.py | 5 +++-- tests/unit/database/test_article.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bluesearch/database/article.py b/src/bluesearch/database/article.py index 6c95360a1..ebe76c94f 100644 --- a/src/bluesearch/database/article.py +++ b/src/bluesearch/database/article.py @@ -25,10 +25,10 @@ import string import unicodedata from abc import ABC, abstractmethod -from dataclasses import dataclass +from dataclasses import dataclass, field from io import StringIO from pathlib import Path -from typing import IO, Generator, Iterable, Optional, Sequence, Tuple +from typing import IO, Dict, Generator, Iterable, List, Optional, Sequence, Tuple from xml.etree.ElementTree import Element # nosec from zipfile import ZipFile @@ -1071,6 +1071,7 @@ class Article(DataClassJSONMixin): arxiv_id: Optional[str] = None doi: Optional[str] = None uid: Optional[str] = None + topics: Dict[str, Dict[str, List[str]]] = field(default_factory=dict) @classmethod def parse(cls, parser: ArticleParser) -> Article: diff --git a/tests/unit/database/test_article.py b/tests/unit/database/test_article.py index 73f8777ee..1659a7365 100644 --- a/tests/unit/database/test_article.py +++ b/tests/unit/database/test_article.py @@ -581,6 +581,8 @@ def test_parse(self): ): assert text == text_want + assert article.topics == dict() + def test_str(self): parser = SimpleTestParser() article = Article.parse(parser) From 1d128be914848481f4129a7c9481c8222a5cb22f Mon Sep 17 00:00:00 2001 From: Emilie Delattre Date: Mon, 19 Sep 2022 15:56:04 +0200 Subject: [PATCH 2/4] Rewrite dict as literal --- tests/unit/database/test_article.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/database/test_article.py b/tests/unit/database/test_article.py index 1659a7365..c4b7c7743 100644 --- a/tests/unit/database/test_article.py +++ b/tests/unit/database/test_article.py @@ -581,7 +581,7 @@ def test_parse(self): ): assert text == text_want - assert article.topics == dict() + assert article.topics == {} def test_str(self): parser = SimpleTestParser() From f70c1ffc0d28eda69602fe340b233b77c0f9a328 Mon Sep 17 00:00:00 2001 From: Emilie Delattre Date: Mon, 19 Sep 2022 16:29:54 +0200 Subject: [PATCH 3/4] Show that we can update dict into tests --- tests/unit/database/test_article.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/unit/database/test_article.py b/tests/unit/database/test_article.py index c4b7c7743..10c8e29cb 100644 --- a/tests/unit/database/test_article.py +++ b/tests/unit/database/test_article.py @@ -582,6 +582,9 @@ def test_parse(self): assert text == text_want assert article.topics == {} + test_dict = {"test_dict": ["this", "is", "a", "test"]} + article.topics.update(test_dict) + assert article.topics == test_dict def test_str(self): parser = SimpleTestParser() From 0eb57b8b73c24c7bd3b9e167cb07b53ff2c9db65 Mon Sep 17 00:00:00 2001 From: Emilie Delattre Date: Mon, 19 Sep 2022 16:54:42 +0200 Subject: [PATCH 4/4] Fix type --- tests/unit/database/test_article.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/database/test_article.py b/tests/unit/database/test_article.py index 10c8e29cb..0079ef2c1 100644 --- a/tests/unit/database/test_article.py +++ b/tests/unit/database/test_article.py @@ -582,7 +582,7 @@ def test_parse(self): assert text == text_want assert article.topics == {} - test_dict = {"test_dict": ["this", "is", "a", "test"]} + test_dict = {"article": {"topic_type": ["this", "is", "a", "list"]}} article.topics.update(test_dict) assert article.topics == test_dict