Skip to content

Commit

Permalink
Allow musl libc's -1 error message during testing
Browse files Browse the repository at this point in the history
Closes #920
  • Loading branch information
kurtmckee committed Oct 11, 2022
1 parent 21e9f4c commit 255d1e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog.rst
Expand Up @@ -11,6 +11,8 @@ Changelog
- [documentation] HTML documentation builds are now tested for errors.
- [fsevents2] The fsevents2 observer is now deprecated.
- [watchmedo] Handle shutdown events from ``SIGHUP`` (`#912 <https://github.com/gorakhargosh/watchdog/pull/912>`__)
- [tests] The error message returned by musl libc for error code ``-1`` is now allowed.
(`#920 <https://github.com/gorakhargosh/watchdog/issues/920>`_)
- Thanks to our beloved contributors: @kurtmckee @babymastodon

2.1.9
Expand Down
16 changes: 9 additions & 7 deletions tests/test_inotify_c.py
Expand Up @@ -135,18 +135,20 @@ def inotify_rm_watch(fd, wd):
assert inotify_fd.wds == [2, 3] # Only 1 is removed explicitly


@pytest.mark.parametrize("error, pattern", [
(errno.ENOSPC, "inotify watch limit reached"),
(errno.EMFILE, "inotify instance limit reached"),
(errno.ENOENT, "No such file or directory"),
(-1, "Unknown error -1"),
@pytest.mark.parametrize("error, patterns", [
(errno.ENOSPC, ("inotify watch limit reached",)),
(errno.EMFILE, ("inotify instance limit reached",)),
(errno.ENOENT, ("No such file or directory",)),
# Error messages for -1 are undocumented
# and vary between libc implementations.
(-1, ("Unknown error -1", "No error information")),
])
def test_raise_error(error, pattern):
def test_raise_error(error, patterns):
with patch.object(ctypes, "get_errno", new=lambda: error):
with pytest.raises(OSError) as exc:
Inotify._raise_error()
assert exc.value.errno == error
assert pattern in str(exc.value)
assert any(pattern in str(exc.value) for pattern in patterns)


def test_non_ascii_path():
Expand Down

0 comments on commit 255d1e4

Please sign in to comment.