Skip to content

Commit

Permalink
chore: avoid mutable default values in class attributes (DEV-3234) (#764
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jnussbaum committed Jan 25, 2024
1 parent 6d339ed commit 1d9e5de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/dsp_tools/commands/id2iri.py
@@ -1,5 +1,6 @@
import copy
import json
from collections.abc import Mapping
from datetime import datetime
from pathlib import Path

Expand Down Expand Up @@ -61,7 +62,7 @@ def _parse_json_file(json_file: Path) -> dict[str, str]:

def _replace_resptrs(
tree: etree._Element,
mapping: dict[str, str],
mapping: Mapping[str, str],
used_mapping_entries: set[str],
) -> tuple[etree._Element, set[str]]:
"""
Expand Down Expand Up @@ -94,7 +95,7 @@ def _replace_resptrs(

def _replace_salsah_links(
tree: etree._Element,
mapping: dict[str, str],
mapping: Mapping[str, str],
used_mapping_entries: set[str],
) -> tuple[etree._Element, set[str]]:
"""
Expand Down Expand Up @@ -127,7 +128,7 @@ def _replace_salsah_links(

def _replace_ids_by_iris(
tree: etree._Element,
mapping: dict[str, str],
mapping: Mapping[str, str],
) -> etree._Element:
"""
Iterate over the <resptr> tags and the salsah-links of the <text> tags,
Expand Down Expand Up @@ -163,7 +164,7 @@ def _replace_ids_by_iris(

def _remove_resources_if_id_in_mapping(
tree: etree._Element,
mapping: dict[str, str],
mapping: Mapping[str, str],
) -> etree._Element:
"""
Remove all resources from the XML file if their ID is in the mapping.
Expand Down
3 changes: 1 addition & 2 deletions test/fast_xmlupload/test_fast_xmlupload.py
@@ -1,7 +1,6 @@
import shutil
import unittest
from pathlib import Path
from typing import ClassVar

import pytest

Expand All @@ -27,7 +26,7 @@ class TestFastXmlUpload(unittest.TestCase):
output_dir = "testdata/preprocessed_files"
xml_file = "testdata/xml-data/test-data-fast-xmlupload.xml"
json_file = "testdata/json-project/test-project-fast-xmlupload.json"
txt_files: ClassVar = ["processed_files.txt", "unprocessed_files.txt"]
txt_files = ("processed_files.txt", "unprocessed_files.txt")

@classmethod
def setUpClass(cls) -> None:
Expand Down
16 changes: 9 additions & 7 deletions test/unittests/commands/test_id2iri.py
@@ -1,7 +1,7 @@
import shutil
import unittest
from pathlib import Path
from typing import ClassVar
from types import MappingProxyType

import pytest
import regex
Expand All @@ -16,12 +16,14 @@

class TestIdToIri(unittest.TestCase):
tmp_dir = Path("testdata/tmp")
mapping: ClassVar = {
"test_thing_0": "http://rdfh.ch/082E/-lRvrg7tQI6aVpcTJbVrwg",
"test_thing_1": "http://rdfh.ch/082E/JK63OpYWTDWNYVOYFN7FdQ",
"test_thing_2": "http://rdfh.ch/082E/1l63Oasdfopiujlkmn78ak",
"test_thing_with_ark_1": "http://rdfh.ch/082E/qwasddoiu8_6flkjh67dss",
}
mapping = MappingProxyType(
{
"test_thing_0": "http://rdfh.ch/082E/-lRvrg7tQI6aVpcTJbVrwg",
"test_thing_1": "http://rdfh.ch/082E/JK63OpYWTDWNYVOYFN7FdQ",
"test_thing_2": "http://rdfh.ch/082E/1l63Oasdfopiujlkmn78ak",
"test_thing_with_ark_1": "http://rdfh.ch/082E/qwasddoiu8_6flkjh67dss",
}
)

@classmethod
def setUpClass(cls) -> None:
Expand Down
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from pathlib import Path
from test.unittests.commands.xmlupload.connection_mock import ConnectionMockBase
from typing import Any, ClassVar
from typing import Any

import pytest
from lxml import etree
Expand All @@ -24,7 +24,7 @@ def get(

@dataclass
class ConnectionMockWithResponses(ConnectionMockBase):
get_responses: ClassVar[list[dict[str, Any]]] = [
get_responses: tuple[dict[str, Any], ...] = (
{
"project": {
"ontologies": ["/testonto"],
Expand All @@ -46,14 +46,17 @@ class ConnectionMockWithResponses(ConnectionMockBase):
}
]
},
]
)
counter = 0

def get(
self,
route: str, # noqa: ARG002 (unused-method-argument)
headers: dict[str, str] | None = None, # noqa: ARG002 (unused-method-argument)
) -> dict[str, Any]:
return self.get_responses.pop(0)
response = self.get_responses[self.counter]
self.counter += 1
return response


def test_error_on_nonexistent_shortcode() -> None:
Expand Down

0 comments on commit 1d9e5de

Please sign in to comment.