Skip to content

Commit

Permalink
test: fix type hinting on test_jujuversion tests (canonical#1011)
Browse files Browse the repository at this point in the history
* Fix the type hint.

If a string is passed, we'll convert it to a JujuVersion, so the correct type is JujuVersion|str.

* Ignore type warning.

This is a dict(str, str) but it's not worth defining that and making the decorator call messy in this specific test case.

* Avoid backsliding on static checks.
  • Loading branch information
tonyandrewmeyer authored Sep 22, 2023
1 parent fa60525 commit 8c09aa2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ops/jujuversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __eq__(self, other: Union[str, 'JujuVersion']) -> bool:
and self.build == other.build
and self.patch == other.patch)

def __lt__(self, other: 'JujuVersion') -> bool:
def __lt__(self, other: Union[str, 'JujuVersion']) -> bool:
if self is other:
return False
if isinstance(other, str):
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ docstring-convention = "google"

[tool.pyright]
include = ["ops/*.py", "ops/_private/*.py",
"test/test_log.py",
"test/test_infra.py",
"test/test_jujuversion.py",
"test/test_log.py",
]
pythonVersion = "3.8" # check no python > 3.8 features are used
pythonPlatform = "All"
Expand Down
2 changes: 1 addition & 1 deletion test/test_jujuversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_parsing(self):
self.assertEqual(v.patch, patch)
self.assertEqual(v.build, build)

@unittest.mock.patch('os.environ', new={})
@unittest.mock.patch('os.environ', new={}) # type: ignore
def test_from_environ(self):
# JUJU_VERSION is not set
v = ops.JujuVersion.from_environ()
Expand Down

0 comments on commit 8c09aa2

Please sign in to comment.