Skip to content

Commit

Permalink
Linter/formatter changes (min. Python now 3.9)
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Nov 1, 2024
1 parent 50cb371 commit 465b534
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 42 deletions.
12 changes: 6 additions & 6 deletions src/voc4cat/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from itertools import chain
from pathlib import Path
from typing import Dict, Literal, Union
from typing import Literal, Union

import pyshacl
from colorama import Fore, Style
Expand Down Expand Up @@ -242,10 +242,10 @@ def rdf_to_excel(
modified=holder["modified"],
creator=holder["creator"],
publisher=holder["publisher"],
version=holder.get("versionInfo", None),
provenance=holder.get("provenance", None),
custodian=holder.get("custodian", None),
pid=holder.get("pid", None),
version=holder.get("versionInfo"),
provenance=holder.get("provenance"),
custodian=holder.get("custodian"),
pid=holder.get("pid"),
)
cs.to_excel(wb)

Expand Down Expand Up @@ -366,7 +366,7 @@ def rdf_to_excel(
return dest


def format_log_msg(result: Dict, colored: bool = False) -> str:
def format_log_msg(result: dict, colored: bool = False) -> str:
from rdflib.namespace import SH

formatted_msg = ""
Expand Down
3 changes: 1 addition & 2 deletions src/voc4cat/convert_043.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import List, Tuple

from curies import Converter
from openpyxl import Workbook
Expand Down Expand Up @@ -51,7 +50,7 @@ def extract_concepts_and_collections(
s: Worksheet,
prefix_converter: Converter,
vocab_name: str = "",
) -> Tuple[List[models.Concept], List[models.Collection]]:
) -> tuple[list[models.Concept], list[models.Collection]]:
concepts = []
collections = []
# Iterating over the concept page and the additional concept page
Expand Down
3 changes: 2 additions & 1 deletion src/voc4cat/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import logging
import re
from typing import Any, ClassVar, Generator
from collections.abc import Generator
from typing import Any, ClassVar

import base32_crockford
from pydantic import BaseConfig, HttpUrl
Expand Down
30 changes: 15 additions & 15 deletions src/voc4cat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import os
from itertools import chain
from typing import List, Union
from typing import Union

from curies import Converter
from openpyxl import Workbook
Expand Down Expand Up @@ -289,19 +289,19 @@ def to_excel(self, wb: Workbook):

class Concept(BaseModel):
uri: AnyHttpUrl
pref_label: Union[str, List[str]]
alt_labels: List[str] = []
pl_language_code: List[str] = []
definition: Union[str, List[str]]
def_language_code: List[str] = []
children: List[AnyHttpUrl] = []
pref_label: Union[str, list[str]]
alt_labels: list[str] = []
pl_language_code: list[str] = []
definition: Union[str, list[str]]
def_language_code: list[str] = []
children: list[AnyHttpUrl] = []
source_vocab: AnyHttpUrl | None = None
provenance: str | None = None
related_match: List[AnyHttpUrl] = []
close_match: List[AnyHttpUrl] = []
exact_match: List[AnyHttpUrl] = []
narrow_match: List[AnyHttpUrl] = []
broad_match: List[AnyHttpUrl] = []
related_match: list[AnyHttpUrl] = []
close_match: list[AnyHttpUrl] = []
exact_match: list[AnyHttpUrl] = []
narrow_match: list[AnyHttpUrl] = []
broad_match: list[AnyHttpUrl] = []
vocab_name: str = Field("", exclude=True)

# We validate with a reusable (external) validators. With a pre-validator,
Expand Down Expand Up @@ -477,7 +477,7 @@ class Collection(BaseModel):
uri: AnyHttpUrl
pref_label: str
definition: str
members: List[AnyHttpUrl]
members: list[AnyHttpUrl]
provenance: str | None = None
vocab_name: str = Field("", exclude=True)

Expand Down Expand Up @@ -528,8 +528,8 @@ def to_excel(self, wb: Workbook, row_no: int):

class Vocabulary(BaseModel):
concept_scheme: ConceptScheme
concepts: List[Concept]
collections: List[Collection]
concepts: list[Concept]
collections: list[Collection]

def to_graph(self):
g = self.concept_scheme.to_graph()
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def datadir():
return Path(__file__).resolve().parent / "data"


@pytest.fixture()
@pytest.fixture
def temp_config():
"""
Provides a temporary config that can be safely changed in test functions.
Expand Down
1 change: 1 addition & 0 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CS_SIMPLE,
CS_SIMPLE_TURTLE,
)

from voc4cat.checks import Voc4catError
from voc4cat.cli import main_cli
from voc4cat.utils import ConversionError
Expand Down
10 changes: 7 additions & 3 deletions tests/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest
from rdflib import RDF, SKOS, Graph

from voc4cat.checks import (
Voc4catError,
check_for_removed_iris,
Expand Down Expand Up @@ -263,9 +264,12 @@ def test_check_for_removed_iris( # noqa: PLR0913
)
config.load_config(config=config.IDRANGES)

with caplog.at_level(logging.ERROR), pytest.raises(
Voc4catError,
match=r"Forbidden removal of 1 concepts\/collections detected. See log for IRIs.",
with (
caplog.at_level(logging.ERROR),
pytest.raises(
Voc4catError,
match=r"Forbidden removal of 1 concepts\/collections detected. See log for IRIs.",
),
):
check_for_removed_iris(original, reduced)
assert log_text in caplog.text
Expand Down
8 changes: 6 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

import pytest

from voc4cat.checks import Voc4catError
from voc4cat.cli import main_cli, run_cli_app

Expand Down Expand Up @@ -105,8 +106,11 @@ def test_valid_config(monkeypatch, datadir, caplog, tmp_path, temp_config):
def test_invalid_outdir(monkeypatch, datadir, tmp_path, caplog):
monkeypatch.chdir(datadir)
shutil.copy(datadir / "README.md", tmp_path)
with caplog.at_level(logging.ERROR), pytest.raises(
Voc4catError, match="Outdir must be a directory but it is a file."
with (
caplog.at_level(logging.ERROR),
pytest.raises(
Voc4catError, match="Outdir must be a directory but it is a file."
),
):
main_cli(["transform", "--outdir", str(tmp_path / "README.md"), CS_SIMPLE])
assert "Outdir must be a directory but it is a file." in caplog.text
3 changes: 2 additions & 1 deletion tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from pathlib import Path

import pytest
import voc4cat
from test_cli import (
CS_CYCLES,
CS_CYCLES_TURTLE,
CS_SIMPLE,
)

import voc4cat
from voc4cat.checks import Voc4catError
from voc4cat.cli import main_cli

Expand Down
1 change: 1 addition & 0 deletions tests/test_dag_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from voc4cat.checks import Voc4catError
from voc4cat.dag_util import (
dag_from_indented_text,
Expand Down
13 changes: 8 additions & 5 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from test_cli import (
CS_CYCLES_TURTLE,
)

from voc4cat.checks import Voc4catError
from voc4cat.cli import main_cli

Expand All @@ -32,9 +33,10 @@ def test_build_docs_pylode_ci_no_git(monkeypatch, datadir, tmp_path, caplog):
shutil.copy(datadir / "valid_idranges.toml", dst / "idranges.toml")
outdir = dst / "pylode"

with caplog.at_level(logging.ERROR), mock.patch(
"voc4cat.gh_index.subprocess"
) as subprocess:
with (
caplog.at_level(logging.ERROR),
mock.patch("voc4cat.gh_index.subprocess") as subprocess,
):
subprocess.Popen.return_value.returncode = 1
main_cli(
["docs", "--force", "--style", "pylode", "--outdir", str(outdir), str(dst)]
Expand All @@ -51,8 +53,9 @@ def test_build_docs_pylode_ci_no_config(monkeypatch, datadir, tmp_path, caplog):
shutil.copy(datadir / CS_CYCLES_TURTLE, dst)
outdir = dst / "pylode"

with caplog.at_level(logging.ERROR), pytest.raises(
Voc4catError, match="Config file not found"
with (
caplog.at_level(logging.ERROR),
pytest.raises(Voc4catError, match="Config file not found"),
):
main_cli(
["docs", "--force", "--style", "pylode", "--outdir", str(outdir), str(dst)]
Expand Down
1 change: 1 addition & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from pydantic import BaseModel, ValidationError

from voc4cat.fields import Orcid, Ror


Expand Down
8 changes: 5 additions & 3 deletions tests/test_merge_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from test_cli import CS_CYCLES_TURTLE, CS_SIMPLE_TURTLE

from voc4cat.merge_vocab import main_cli


Expand Down Expand Up @@ -61,9 +62,10 @@ def test_main_merge_split_vocab_dir(datadir, tmp_path, caplog):
shutil.copy(datadir / CS_SIMPLE_TURTLE, ttl_inbox / "splitvoc")
shutil.copy(datadir / CS_SIMPLE_TURTLE, vocab / "splitvoc")

with caplog.at_level(logging.DEBUG), mock.patch(
"voc4cat.merge_vocab.subprocess"
) as subprocess:
with (
caplog.at_level(logging.DEBUG),
mock.patch("voc4cat.merge_vocab.subprocess") as subprocess,
):
subprocess.Popen.return_value.returncode = 1
exit_code = main_cli([str(ttl_inbox), str(vocab)])
assert "Entering directory" in caplog.text
Expand Down
1 change: 1 addition & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
from pydantic.error_wrappers import ValidationError
from rdflib import Graph

from voc4cat import config
from voc4cat.models import Concept, ConceptScheme, reset_curies

Expand Down
3 changes: 2 additions & 1 deletion tests/test_template043.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from unittest import mock

import pytest
import voc4cat
from rdflib import SKOS, Graph, Literal, URIRef, compare

import voc4cat
from voc4cat import convert
from voc4cat.utils import ConversionError

Expand Down
8 changes: 6 additions & 2 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
CS_SIMPLE,
CS_SIMPLE_TURTLE,
)

from voc4cat.checks import Voc4catError
from voc4cat.cli import main_cli

Expand Down Expand Up @@ -671,8 +672,11 @@ def test_join_with_invalid_envvar(monkeypatch, datadir, tmp_path, caplog):
# join files again as test
cmd = ["transform", "-v", "--join"]
cmd.append(str(tmp_path))
with caplog.at_level(logging.ERROR), pytest.raises(
Voc4catError, match="Invalid environment variable VOC4CAT_VERSION"
with (
caplog.at_level(logging.ERROR),
pytest.raises(
Voc4catError, match="Invalid environment variable VOC4CAT_VERSION"
),
):
main_cli(cmd)
assert 'Invalid environment variable VOC4CAT_VERSION "2.0"' in caplog.text
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from openpyxl import Workbook, load_workbook
from openpyxl.worksheet.table import Table

from voc4cat.utils import adjust_length_of_tables, split_and_tidy


Expand Down

0 comments on commit 465b534

Please sign in to comment.