Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise NotImplementedError if using wrong class #135

Merged
merged 11 commits into from Feb 17, 2022
4 changes: 2 additions & 2 deletions docs/changelog.rst
@@ -1,8 +1,8 @@
Changelog
=========

Future
------
v3.6.0 (2022-02-17)
-------------------
- Fix pylint warning "Abstract class :class:`WindowsFileLock <filelock.WindowsFileLock>` with abstract methods instantiated"
:pr:`135` - by :user:`vonschultz`
- Fix pylint warning "Abstract class :class:`UnixFileLock <filelock.UnixFileLock>` with abstract methods instantiated"
Expand Down
19 changes: 3 additions & 16 deletions tests/test_filelock.py
Expand Up @@ -385,26 +385,13 @@ def decorated_method() -> None:
assert not lock.is_locked


@pytest.mark.skipif(sys.platform != "win32", reason="Tests behavior of UnixFileLock on Windows systems")
def test_unix_lock_on_windows(tmp_path: Path) -> None:
lock = UnixFileLock(str(tmp_path / "lockfile"))
def test_wrong_platform(tmp_path: Path) -> None:
lock_type = UnixFileLock if sys.platform == "win32" else WindowsFileLock
lock = lock_type(str(tmp_path / "lockfile"))

assert not inspect.isabstract( # noqa: SC200
vonschultz marked this conversation as resolved.
Show resolved Hide resolved
UnixFileLock
), "UnixFileLock must not be an abstract class, or pylint will complain in client code"
assert inspect.isabstract(BaseFileLock) # noqa: SC200

with pytest.raises(NotImplementedError):
lock.acquire()

with pytest.raises(NotImplementedError):
lock._release()


@pytest.mark.skipif(sys.platform == "win32", reason="Tests behavior of WindowsFileLock on non-Windows systems")
def test_windows_lock_on_unix(tmp_path: Path) -> None:
lock = WindowsFileLock(str(tmp_path / "lockfile"))

assert not inspect.isabstract( # noqa: SC200
WindowsFileLock
), "WindowsFileLock must not be an abstract class, or pylint will complain in client code"
Expand Down