mirror of
https://github.com/rendercv/rendercv.git
synced 2025-12-23 21:47:55 -05:00
Switch from pyright to ty (https://github.com/astral-sh/ty)
This commit is contained in:
@@ -187,7 +187,7 @@ class TestParseConnections:
|
||||
|
||||
connections = parse_connections(model)
|
||||
|
||||
icons = [c.fontawesome_icon for c in connections] # type: ignore
|
||||
icons = [c.fontawesome_icon for c in connections]
|
||||
assert icons == [
|
||||
fontawesome_icons["location"],
|
||||
fontawesome_icons["email"],
|
||||
@@ -208,7 +208,7 @@ class TestParseConnections:
|
||||
|
||||
connections = parse_connections(model)
|
||||
|
||||
icons = [c.fontawesome_icon for c in connections] # type: ignore
|
||||
icons = [c.fontawesome_icon for c in connections]
|
||||
assert icons == [
|
||||
fontawesome_icons["email"],
|
||||
fontawesome_icons["LinkedIn"],
|
||||
|
||||
@@ -194,13 +194,8 @@ class TestRenderEntryTemplates:
|
||||
current_date=Date(2024, 1, 1),
|
||||
)
|
||||
|
||||
assert (
|
||||
entry.main_column == "**Solo**" # pyright: ignore [reportAttributeAccessIssue]
|
||||
)
|
||||
assert (
|
||||
entry.date_and_location_column # pyright: ignore [reportAttributeAccessIssue]
|
||||
== ""
|
||||
)
|
||||
assert entry.main_column == "**Solo**" # ty: ignore[unresolved-attribute]
|
||||
assert entry.date_and_location_column == "" # ty: ignore[unresolved-attribute]
|
||||
|
||||
def test_populates_highlights_and_date_placeholders(self):
|
||||
entry = NormalEntry(
|
||||
@@ -218,8 +213,8 @@ class TestRenderEntryTemplates:
|
||||
current_date=Date(2024, 1, 1),
|
||||
)
|
||||
|
||||
assert entry.main_column == "**Project**\n- Alpha\n- Beta" # pyright: ignore [reportAttributeAccessIssue]
|
||||
assert entry.date_and_location_column == "Remote\nMay 2023" # pyright: ignore [reportAttributeAccessIssue]
|
||||
assert entry.main_column == "**Project**\n- Alpha\n- Beta" # ty: ignore[unresolved-attribute]
|
||||
assert entry.date_and_location_column == "Remote\nMay 2023" # ty: ignore[unresolved-attribute]
|
||||
|
||||
def test_formats_start_and_end_dates_in_custom_template(self):
|
||||
entry = NormalEntry(
|
||||
@@ -240,7 +235,7 @@ class TestRenderEntryTemplates:
|
||||
current_date=Date(2024, 1, 1),
|
||||
)
|
||||
|
||||
assert entry.main_column == "Jan 2020 / Mar 2021 / / Jan 2020 – Mar 2021" # pyright: ignore [reportAttributeAccessIssue]
|
||||
assert entry.main_column == "Jan 2020 / Mar 2021 / / Jan 2020 – Mar 2021" # ty: ignore[unresolved-attribute]
|
||||
|
||||
def test_handles_authors_doi_and_date_placeholders(self):
|
||||
entry = PublicationEntry(
|
||||
@@ -263,7 +258,7 @@ class TestRenderEntryTemplates:
|
||||
)
|
||||
|
||||
assert (
|
||||
entry.main_column # pyright: ignore [reportAttributeAccessIssue]
|
||||
entry.main_column # ty: ignore[unresolved-attribute]
|
||||
== "Alice, Bob | [10.1000/xyz123](https://doi.org/10.1000/xyz123) | Feb"
|
||||
" 2024"
|
||||
)
|
||||
@@ -289,7 +284,7 @@ class TestRenderEntryTemplates:
|
||||
)
|
||||
|
||||
assert (
|
||||
entry.main_column # pyright: ignore [reportAttributeAccessIssue]
|
||||
entry.main_column # ty: ignore[unresolved-attribute]
|
||||
== "Linked Item [example.com/page](https://example.com/page/)"
|
||||
)
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class TestProcessFields:
|
||||
fn, seen = recorder
|
||||
entry = EntryWithInt(name="Test", count=42)
|
||||
|
||||
process_fields(entry, [fn]) # pyright: ignore[reportArgumentType]
|
||||
process_fields(entry, [fn]) # ty: ignore[invalid-argument-type]
|
||||
|
||||
assert "Test" in seen
|
||||
assert "42" in seen
|
||||
@@ -118,12 +118,12 @@ class TestProcessModel:
|
||||
assert result.cv.headline == "Software Engineer @"
|
||||
|
||||
# Connections and last updated date are added to cv
|
||||
assert result.cv.connections == [ # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert result.cv.connections == [ # ty: ignore[unresolved-attribute]
|
||||
"[jane@example.com](mailto:jane@example.com)",
|
||||
"[janedoe.dev](https://janedoe.dev/)",
|
||||
]
|
||||
assert (
|
||||
result.cv.top_note == "*Last updated in Feb 2024*" # pyright: ignore[reportAttributeAccessIssue]
|
||||
result.cv.top_note == "*Last updated in Feb 2024*" # ty: ignore[unresolved-attribute]
|
||||
)
|
||||
|
||||
entry = result.cv.rendercv_sections[0].entries[0]
|
||||
@@ -157,13 +157,13 @@ class TestProcessModel:
|
||||
entry.date_and_location_column == "#strong[Remote]\nJan 2022 – Feb 2023"
|
||||
)
|
||||
# Connections rendered as Typst links with icons by default
|
||||
assert result.cv.connections[0].startswith("#link(") # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert "#connection-with-icon" in result.cv.connections[0] # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert result.cv.connections[0].startswith("#link(") # ty: ignore[unresolved-attribute]
|
||||
assert "#connection-with-icon" in result.cv.connections[0] # ty: ignore[unresolved-attribute]
|
||||
else:
|
||||
assert "- Improved Python performance" in entry.main_column
|
||||
assert entry.date_and_location_column == "Remote\nJan 2022 – Feb 2023"
|
||||
assert result.cv.connections[0].startswith("#link(") # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert "jane@example.com" in result.cv.connections[0] # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert result.cv.connections[0].startswith("#link(") # ty: ignore[unresolved-attribute]
|
||||
assert "jane@example.com" in result.cv.connections[0] # ty: ignore[unresolved-attribute]
|
||||
|
||||
def test_handles_cv_with_no_sections(self):
|
||||
cv_data = {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import copy
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -70,49 +71,49 @@ reversed_numbered_entry_dictionary = {
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def publication_entry() -> dict[str, str | list[str]]:
|
||||
def publication_entry() -> dict[str, Any]:
|
||||
"""Return a sample publication entry."""
|
||||
return copy.deepcopy(publication_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def experience_entry() -> dict[str, str]:
|
||||
def experience_entry() -> dict[str, Any]:
|
||||
"""Return a sample experience entry."""
|
||||
return copy.deepcopy(experience_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def education_entry() -> dict[str, str]:
|
||||
def education_entry() -> dict[str, Any]:
|
||||
"""Return a sample education entry."""
|
||||
return copy.deepcopy(education_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def normal_entry() -> dict[str, str]:
|
||||
def normal_entry() -> dict[str, Any]:
|
||||
"""Return a sample normal entry."""
|
||||
return copy.deepcopy(normal_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def one_line_entry() -> dict[str, str]:
|
||||
def one_line_entry() -> dict[str, Any]:
|
||||
"""Return a sample one line entry."""
|
||||
return copy.deepcopy(one_line_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bullet_entry() -> dict[str, str]:
|
||||
def bullet_entry() -> dict[str, Any]:
|
||||
"""Return a sample bullet entry."""
|
||||
return copy.deepcopy(bullet_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def numbered_entry() -> dict[str, str]:
|
||||
def numbered_entry() -> dict[str, Any]:
|
||||
"""Return a sample numbered entry."""
|
||||
return copy.deepcopy(numbered_entry_dictionary)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def reversed_numbered_entry() -> dict[str, str]:
|
||||
def reversed_numbered_entry() -> dict[str, Any]:
|
||||
"""Return a sample reversed numbered entry."""
|
||||
return copy.deepcopy(reversed_numbered_entry_dictionary)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
import pydantic
|
||||
import pytest
|
||||
|
||||
@@ -25,7 +27,7 @@ class TestCv:
|
||||
"sections": sections,
|
||||
}
|
||||
|
||||
cv = Cv(**input)
|
||||
cv = Cv.model_validate(input)
|
||||
|
||||
assert len(cv.rendercv_sections) == len(available_entry_type_names)
|
||||
for section in cv.rendercv_sections:
|
||||
@@ -45,10 +47,10 @@ class TestCv:
|
||||
}
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
Cv(**input)
|
||||
Cv.model_validate(input)
|
||||
|
||||
def test_rejects_invalid_entries(self):
|
||||
input = {"name": "John Doe", "sections": {}}
|
||||
input: dict[str, Any] = {"name": "John Doe", "sections": {}}
|
||||
input["sections"]["section_title"] = [
|
||||
{
|
||||
"this": "is",
|
||||
@@ -58,16 +60,16 @@ class TestCv:
|
||||
]
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
Cv(**input)
|
||||
Cv.model_validate(input)
|
||||
|
||||
def test_rejects_section_without_list(self):
|
||||
input = {"name": "John Doe", "sections": {}}
|
||||
input: dict[str, Any] = {"name": "John Doe", "sections": {}}
|
||||
input["sections"]["section_title"] = {
|
||||
"this section": "does not have a list of entries but a single entry."
|
||||
}
|
||||
|
||||
with pytest.raises(pydantic.ValidationError):
|
||||
Cv(**input)
|
||||
Cv.model_validate(input)
|
||||
|
||||
def test_phone_serialization(self):
|
||||
input_data = {"name": "John Doe", "phone": "+905419999999"}
|
||||
|
||||
@@ -86,7 +86,7 @@ class TestSocialNetwork:
|
||||
(
|
||||
"Bluesky",
|
||||
"myusername.bsky.social",
|
||||
"https://bsky.app/profile/myusername.bsky.social"
|
||||
"https://bsky.app/profile/myusername.bsky.social",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
|
||||
from rendercv.exception import RenderCVUserError
|
||||
@@ -136,7 +138,7 @@ class TestUpdateValueByLocation:
|
||||
assert original == {"name": "Jane"}
|
||||
|
||||
def test_deeply_nested_structure(self):
|
||||
initial = {
|
||||
initial: dict[str, Any] = {
|
||||
"cv": {
|
||||
"sections": {
|
||||
"education": [
|
||||
@@ -230,7 +232,7 @@ class TestApplyOverridesToDictionary:
|
||||
assert result is not original
|
||||
|
||||
def test_complex_cv_scenario(self):
|
||||
initial = {
|
||||
initial: dict[str, Any] = {
|
||||
"cv": {
|
||||
"name": "John Doe",
|
||||
"sections": {
|
||||
|
||||
@@ -289,7 +289,7 @@ class TestCreateNestedFieldSpec:
|
||||
|
||||
# Check that a variant class was created with default_factory
|
||||
assert field.default_factory is not None
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # pyright: ignore[reportArgumentType]
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # ty: ignore[invalid-argument-type]
|
||||
|
||||
# Instantiate to check default values
|
||||
instance = field.default_factory()
|
||||
@@ -311,7 +311,7 @@ class TestCreateNestedFieldSpec:
|
||||
|
||||
# Check that a variant class was created with default_factory
|
||||
assert field.default_factory is not None
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # pyright: ignore[reportArgumentType]
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # ty: ignore[invalid-argument-type]
|
||||
|
||||
# Instantiate to check default values
|
||||
instance = field.default_factory()
|
||||
@@ -352,7 +352,7 @@ class TestCreateNestedFieldSpec:
|
||||
|
||||
# Check that a variant class was created with default_factory
|
||||
assert field.default_factory is not None
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # pyright: ignore[reportArgumentType]
|
||||
assert issubclass(field.default_factory, pydantic.BaseModel) # ty: ignore[invalid-argument-type]
|
||||
|
||||
# Instantiate to check default values
|
||||
instance = field.default_factory()
|
||||
@@ -754,7 +754,7 @@ class TestCreateVariantPydanticModel:
|
||||
pydantic.Field(default=old_default, description=base_description),
|
||||
),
|
||||
}
|
||||
Base = pydantic.create_model("Base", **base_fields)
|
||||
Base = pydantic.create_model("Base", **base_fields) # ty: ignore[no-matching-overload]
|
||||
|
||||
VariantClass = create_variant_pydantic_model(
|
||||
variant_name="custom",
|
||||
@@ -1045,8 +1045,8 @@ class TestCreateNestedModelVariantModel:
|
||||
|
||||
# The variant should be created without errors
|
||||
instance = variant_class()
|
||||
assert instance.x == 100 # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert instance.y == 2 # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert instance.x == 100 # ty: ignore[unresolved-attribute]
|
||||
assert instance.y == 2 # ty: ignore[unresolved-attribute]
|
||||
# nonexistent_field should not be in the instance
|
||||
assert not hasattr(instance, "nonexistent_field")
|
||||
|
||||
@@ -1065,5 +1065,5 @@ class TestCreateNestedModelVariantModel:
|
||||
variant_class = create_nested_model_variant_model(ModelWithPlainDict, updates)
|
||||
|
||||
instance = variant_class()
|
||||
assert instance.metadata == {"new_key": "new_value"} # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert instance.count == 10 # pyright: ignore[reportAttributeAccessIssue]
|
||||
assert instance.metadata == {"new_key": "new_value"} # ty: ignore[unresolved-attribute]
|
||||
assert instance.count == 10 # ty: ignore[unresolved-attribute]
|
||||
|
||||
Reference in New Issue
Block a user