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

Fix tests on macOS #729

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 deletions tests/test_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
InotifyFullEmitter,
)
elif platform.is_darwin():
pytestmark = pytest.mark.skip("FIXME: issue #546.")
from watchdog.observers.fsevents import FSEventsEmitter as Emitter
elif platform.is_windows():
from watchdog.observers.read_directory_changes import (
Expand Down Expand Up @@ -77,11 +76,16 @@ def start_watching(path=None, use_full_emitter=False, recursive=True):
else:
emitter = Emitter(event_queue, ObservedWatch(path, recursive=recursive))

emitter.start()

if platform.is_darwin():
# FSEvents will report old events (like create for mkdtemp in test
# setup. Waiting for a considerable time seems to 'flush' the events.
time.sleep(10)
emitter.start()

time.sleep(15)
while not event_queue.empty():
event_queue.get()
time.sleep(2)


def rerun_filter(exc, *args):
Expand Down Expand Up @@ -117,11 +121,6 @@ def test_create_wrong_encoding():
assert event.src_path == p('a_\udce4')
assert isinstance(event, FileCreatedEvent)

if not platform.is_windows():
event = event_queue.get(timeout=5)[0]
assert os.path.normpath(event.src_path) == os.path.normpath(p(''))
assert isinstance(event, DirModifiedEvent)


@pytest.mark.flaky(max_runs=5, min_passes=1, rerun_filter=rerun_filter)
def test_delete():
Expand Down Expand Up @@ -286,7 +285,7 @@ def test_delete_self():
if platform.is_darwin():
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1')
assert isinstance(event, FileDeletedEvent)
assert isinstance(event, DirDeletedEvent)


@pytest.mark.skipif(platform.is_windows() or platform.is_bsd(),
Expand Down Expand Up @@ -352,13 +351,14 @@ def test_recursive_on():
assert event.src_path == p('dir1', 'dir2', 'dir3')
assert isinstance(event, DirModifiedEvent)

if not platform.is_bsd():
if platform.is_linux():
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)
@pytest.mark.skipif(platform.is_darwin(), reason="macOS watches are always recursive")
def test_recursive_off():
mkdir(p('dir1'))
start_watching(recursive=False)
Expand Down Expand Up @@ -399,9 +399,12 @@ def test_renaming_top_level_directory():
assert isinstance(event, DirModifiedEvent)
assert event.src_path == p()

event = event_queue.get(timeout=5)[0]
assert isinstance(event, DirMovedEvent)
assert event.src_path == p('a', 'b')
if not platform.is_darwin():
# recursive rename events are currently not generated, see TODOs
event = event_queue.get(timeout=5)[0]
assert isinstance(event, DirMovedEvent)
assert event.src_path == p('a', 'b')
assert event.dest_path == p('a2', 'b')

if platform.is_bsd():
event = event_queue.get(timeout=5)[0]
Expand Down Expand Up @@ -501,13 +504,15 @@ def test_move_nested_subdirectories():
assert p(event.src_path, '') == p('')
assert isinstance(event, DirModifiedEvent)

event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1/dir2/dir3')
assert isinstance(event, DirMovedEvent)
if not platform.is_darwin():
# recursive rename events are currently not generated, see TODOs
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1/dir2/dir3')
assert isinstance(event, DirMovedEvent)

event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1/dir2/dir3', 'a')
assert isinstance(event, FileMovedEvent)
event = event_queue.get(timeout=5)[0]
assert event.src_path == p('dir1/dir2/dir3', 'a')
assert isinstance(event, FileMovedEvent)

if platform.is_bsd():
event = event_queue.get(timeout=5)[0]
Expand Down