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

[BSD] Further support in tests #639

Merged
merged 1 commit into from Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion changelog.rst
Expand Up @@ -11,7 +11,7 @@ Changelog
- Fixed the ``build_ext`` command on macOS Catalina (`#628 <https://github.com/gorakhargosh/watchdog/pull/628>`__)
- Refactored ``dispatch()`` method of ``FileSystemEventHandler``,
``PatternMatchingEventHandler`` and ``RegexMatchingEventHandler``
- Improve tests support on non Windows/Linux platforms (`#633 <https://github.com/gorakhargosh/watchdog/pull/633>`__)
- Improve tests support on non Windows/Linux platforms (`#633 <https://github.com/gorakhargosh/watchdog/pull/633>`__, `#639 <https://github.com/gorakhargosh/watchdog/pull/639>`__)
- Added FreeBSD CI support (`#532 <https://github.com/gorakhargosh/watchdog/pull/532>`__)
- [BSD] Restore partial support (`#638 <https://github.com/gorakhargosh/watchdog/pull/638>`__)
- Thanks to our beloved contributors: @BoboTiG, @evilham
Expand Down
55 changes: 37 additions & 18 deletions tests/test_emitter.py
Expand Up @@ -236,23 +236,27 @@ def test_separate_consecutive_moves():
mv(p('dir1', 'a'), p('c'))
mv(p('b'), p('dir1', 'd'))

event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1', 'a')
assert isinstance(event, FileDeletedEvent)
dir_modif = (DirModifiedEvent, p('dir1'))
a_deleted = (FileDeletedEvent, p('dir1', 'a'))
d_created = (FileCreatedEvent, p('dir1', 'd'))

if not platform.is_windows():
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1')
assert isinstance(event, DirModifiedEvent)
expected = [a_deleted, dir_modif, d_created, dir_modif]

event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1', 'd')
assert isinstance(event, FileCreatedEvent)
if platform.is_windows():
expected = [a_deleted, d_created]

if not platform.is_windows():
if platform.is_bsd():
# Due to the way kqueue works, we can't really order
# 'Created' and 'Deleted' events in time, so creation queues first
expected = [d_created, a_deleted, dir_modif, dir_modif]

def _step(expected_step):
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1')
assert isinstance(event, DirModifiedEvent)
assert event.src_path == expected_step[1]
assert isinstance(event, expected_step[0])

for expected_step in expected:
_step(expected_step)


@pytest.mark.flaky(max_runs=5, min_passes=1, rerun_filter=rerun_filter)
Expand All @@ -267,8 +271,8 @@ def test_delete_self():
assert isinstance(event, FileDeletedEvent)


@pytest.mark.skipif(platform.is_windows(),
reason="Windows create another set of events for this test")
@pytest.mark.skipif(platform.is_windows() or platform.is_bsd(),
reason="Windows|BSD create another set of events for this test")
def test_fast_subdirectory_creation_deletion():
root_dir = p('dir1')
sub_dir = p('dir1', 'subdir1')
Expand Down Expand Up @@ -330,9 +334,10 @@ def test_recursive_on():
assert event.src_path == p('dir1', 'dir2', 'dir3')
assert isinstance(event, DirModifiedEvent)

event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1', 'dir2', 'dir3', 'a')
assert isinstance(event, FileModifiedEvent)
if not platform.is_bsd():
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1', 'dir2', 'dir3', 'a')
assert isinstance(event, FileModifiedEvent)


@pytest.mark.flaky(max_runs=5, min_passes=1, rerun_filter=rerun_filter)
Expand Down Expand Up @@ -380,6 +385,11 @@ def test_renaming_top_level_directory():
assert isinstance(event, DirMovedEvent)
assert event.src_path == p('a', 'b')

if platform.is_bsd():
event = event_queue.get(timeout=5)[0]
assert isinstance(event, DirModifiedEvent)
assert event.src_path == p()

open(p('a2', 'b', 'c'), 'a').close()

# DirModifiedEvent may emitted, but sometimes after waiting time is out.
Expand Down Expand Up @@ -481,6 +491,15 @@ def test_move_nested_subdirectories():
assert event.src_path == p('dir1/dir2/dir3', 'a')
assert isinstance(event, FileMovedEvent)

if platform.is_bsd():
event = event_queue.get(timeout=5)[0]
assert p(event.src_path) == p()
assert isinstance(event, DirModifiedEvent)

event = event_queue.get(timeout=5)[0]
assert p(event.src_path) == p('dir1')
assert isinstance(event, DirModifiedEvent)

touch(p('dir2/dir3', 'a'))

event = event_queue.get(timeout=5)[0]
Expand Down