Skip to content

Commit

Permalink
Check test suite with mypy
Browse files Browse the repository at this point in the history
The test suite has a considerable number of calls to out code so it can
serve as some usage examples that should be type checked.
  • Loading branch information
lucc committed Dec 9, 2023
1 parent dddc98c commit e650297
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion khard/carddav_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def organisations(self) -> List[Union[List[str], Dict[str, List[str]]]]:
"""
return self._get_multi_property("ORG")

def _add_organisation(self, organisation: StrList) -> None:
def _add_organisation(self, organisation: Union[StrList, StrListDict]) -> None:
"""Add one ORG entry to the underlying vcard
:param organisation: the value to add
Expand Down
9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ packages = ['khard', 'khard.helpers']
write_to = "khard/version.py"

[tool.mypy]
packages = "khard"
packages = ["khard", "test"]
check_untyped_defs = true
disallow_untyped_calls = true
#disallow_untyped_defs = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unused_ignores = true
Expand All @@ -69,9 +70,15 @@ module = [
"validate",
"vobject",
"vobject.base",
"vobject.vcard",
]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "test.*"
check_untyped_defs = false
disallow_untyped_calls = false

[tool.pylint.main]
py-version = "3.8"
ignore-paths = ["khard/version.py"]
Expand Down
10 changes: 6 additions & 4 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ def mock_stream(name="stdout"):
return context_manager


def load_contact(path: str, abook: Optional[address_book.AddressBook] = None
) -> carddav_object.CarddavObject:
def load_contact(path: str) -> carddav_object.CarddavObject:
"""Load a contact from the fixture directory.
:param path: the file name (full, relative to cwd or the fixture dir)
:param abook:
"""
abook = address_book.VdirAddressBook("test", "/tmp")
if not os.path.exists(path):
path = os.path.join("test/fixture/vcards", path)
return carddav_object.CarddavObject.from_file(abook, path)
contact = carddav_object.CarddavObject.from_file(abook, path)
if contact is None:
raise FileNotFoundError(path)
return contact


class TmpAbook:
Expand Down
4 changes: 3 additions & 1 deletion test/test_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from vobject.vcard import Name

from khard.address_book import VdirAddressBook
from khard.carddav_object import CarddavObject
from khard.formatter import Formatter

Expand Down Expand Up @@ -57,7 +58,8 @@ class GetSpecialField(unittest.TestCase):
_name = Name(family='Family', given='Given', additional='Additional',
prefix='Prefix', suffix='Suffix')
_vcard = CarddavObject(vCard(fn="Formatted Name", n=_name,
nickname="Nickname"), None, "")
nickname="Nickname"),
VdirAddressBook("test", "/tmp"), "")

def _test_name(self, fmt, nick, parsable, expected):
f = Formatter(fmt, [], [], nick, parsable)
Expand Down
2 changes: 1 addition & 1 deletion test/test_vcard_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def _test_list_of_strings_as(self, key: str) -> None:
for item in components}
expected[key] = ["a", "b"]
index = components.index(key)
components = (*components[:index], ["a", "b"], *components[index+1:])
components = (*components[:index], ["a", "b"], *components[index+1:]) # type: ignore
wrapper._add_post_address('home', *components)
self.assertDictEqual(wrapper.post_addresses, {'home': [expected]})

Expand Down

0 comments on commit e650297

Please sign in to comment.