示例#1
0
def test_renaming_top_level_directory():
    start_watching()

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

    mkdir(p('a', 'b'))
    event = event_queue.get(timeout=5)[0]
    assert isinstance(event, DirCreatedEvent)
    assert event.src_path == p('a', 'b')
    event = event_queue.get(timeout=5)[0]
    assert isinstance(event, DirModifiedEvent)
    assert event.src_path == p('a')

    mv(p('a'), p('a2'))
    event = event_queue.get(timeout=5)[0]
    assert event.src_path == p('a')
    event = event_queue.get(timeout=5)[0]
    assert isinstance(event, DirModifiedEvent)
    assert event.src_path == p()
    event = event_queue.get(timeout=5)[0]
    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 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.
    events = []
    while True:
        events.append(event_queue.get(timeout=5)[0])
        if event_queue.empty():
            break

    assert all([
        isinstance(e, (FileCreatedEvent, FileMovedEvent, DirModifiedEvent))
        for e in events
    ])

    for event in events:
        if isinstance(event, FileCreatedEvent):
            assert event.src_path == p('a2', 'b', 'c')
        elif isinstance(event, FileMovedEvent):
            assert event.dest_path == p('a2', 'b', 'c')
            assert event.src_path == p('a', 'b', 'c')
        elif isinstance(event, DirModifiedEvent):
            assert event.src_path == p('a2', 'b')
示例#2
0
def test_separate_consecutive_moves():
    mkdir(p('dir1'))
    touch(p('dir1', 'a'))
    touch(p('b'))
    start_watching(p('dir1'))
    mv(p('dir1', 'a'), p('c'))
    mv(p('b'), p('dir1', 'd'))

    dir_modif = (DirModifiedEvent, p('dir1'))
    a_deleted = (FileDeletedEvent, p('dir1', 'a'))
    d_created = (FileCreatedEvent, p('dir1', 'd'))

    expected = [a_deleted, dir_modif, d_created, dir_modif]

    if platform.is_windows():
        expected = [a_deleted, d_created]

    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 == expected_step[1]
        assert isinstance(event, expected_step[0])

    for expected_step in expected:
        _step(expected_step)
示例#3
0
def test_move_nested_subdirectories():
    mkdir(p('dir1/dir2/dir3'), parents=True)
    mkfile(p('dir1/dir2/dir3', 'a'))
    start_watching()
    mv(p('dir1/dir2'), p('dir2'))

    expect_event(DirMovedEvent(p('dir1', 'dir2'), p('dir2')))
    expect_event(DirModifiedEvent(p('dir1')))
    expect_event(DirModifiedEvent(p()))

    expect_event(DirMovedEvent(p('dir1', 'dir2', 'dir3'), p('dir2', 'dir3')))
    expect_event(FileMovedEvent(p('dir1', 'dir2', 'dir3', 'a'), p('dir2', 'dir3', 'a')))

    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]
    assert event.src_path == p('dir2/dir3', 'a')
    assert isinstance(event, FileModifiedEvent)
示例#4
0
def test_recursive_on():
    mkdir(p('dir1', 'dir2', 'dir3'), True)
    start_watching()
    touch(p('dir1', 'dir2', 'dir3', 'a'))

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

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

        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)
示例#5
0
def test_separate_consecutive_moves():
    mkdir(p('dir1'))
    mkfile(p('dir1', 'a'))
    mkfile(p('b'))
    start_watching(p('dir1'))
    mv(p('dir1', 'a'), p('c'))
    mv(p('b'), p('dir1', 'd'))

    dir_modif = DirModifiedEvent(p('dir1'))
    a_deleted = FileDeletedEvent(p('dir1', 'a'))
    d_created = FileCreatedEvent(p('dir1', 'd'))

    expected_events = [a_deleted, dir_modif, d_created, dir_modif]

    if platform.is_windows():
        expected_events = [a_deleted, d_created]

    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_events = [d_created, a_deleted, dir_modif, dir_modif]

    for expected_event in expected_events:
        expect_event(expected_event)
示例#6
0
    except UnsupportedLibc:
        from .polling import PollingObserver as Observer

elif platform.is_darwin():
    try:
        from .fsevents import FSEventsObserver as Observer
    except Exception:
        try:
            from .kqueue import KqueueObserver as Observer
            warnings.warn("Failed to import fsevents. Fall back to kqueue")
        except Exception:
            from .polling import PollingObserver as Observer
            warnings.warn(
                "Failed to import fsevents and kqueue. Fall back to polling.")

elif platform.is_bsd():
    from .kqueue import KqueueObserver as Observer

elif platform.is_windows():
    # TODO: find a reliable way of checking Windows version and import
    # polling explicitly for Windows XP
    try:
        from .read_directory_changes import WindowsApiObserver as Observer
    except Exception:
        from .polling import PollingObserver as Observer
        warnings.warn(
            "Failed to import read_directory_changes. Fall back to polling.")

else:
    from .polling import PollingObserver as Observer
示例#7
0
.. autoclass:: KeventDescriptor
   :members:
   :show-inheritance:

.. autoclass:: KeventDescriptorSet
   :members:
   :show-inheritance:

.. _Mac OS X File System Performance Guidelines: http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/FileSystem/Articles/TrackingChanges.html#//apple_ref/doc/uid/20001993-CJBJFIDD

"""

from __future__ import with_statement
from watchdog.utils import platform

if not platform.is_bsd() and not platform.is_darwin():
    raise ImportError

import threading
import errno
import sys
import stat
import os

# See the notes for this module in the documentation above ^.
#import select
# if not has_attribute(select, 'kqueue') or sys.version_info < (2, 7, 0):
if sys.version_info < (2, 7, 0):
    import select_backport as select
else:
    import select
示例#8
0
                             FileCreatedEvent, FileMovedEvent, DirDeletedEvent,
                             DirModifiedEvent, DirCreatedEvent, DirMovedEvent)
from watchdog.observers.api import ObservedWatch

if platform.is_linux():
    from watchdog.observers.inotify import (
        InotifyEmitter as Emitter,
        InotifyFullEmitter,
    )
elif platform.is_darwin():
    pytestmark = pytest.mark.skip("FIXME: issue #546.")
    from watchdog.observers.fsevents2 import FSEventsEmitter as Emitter
elif platform.is_windows():
    from watchdog.observers.read_directory_changes import (WindowsApiEmitter as
                                                           Emitter)
elif platform.is_bsd():
    from watchdog.observers.kqueue import (KqueueEmitter as Emitter)

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


@pytest.fixture(autouse=True)
def setup_teardown(tmpdir):
    global p, emitter, event_queue
    p = partial(os.path.join, tmpdir)
    event_queue = Queue()

    yield

    emitter.stop()
示例#9
0
.. autoclass:: KeventDescriptor
   :members:
   :show-inheritance:

.. autoclass:: KeventDescriptorSet
   :members:
   :show-inheritance:

.. _Mac OS X File System Performance Guidelines: http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/FileSystem/Articles/TrackingChanges.html#//apple_ref/doc/uid/20001993-CJBJFIDD

"""

from __future__ import with_statement
from watchdog.utils import platform

if not platform.is_bsd() and not platform.is_darwin():
    raise ImportError

import threading
import errno
import sys
import stat
import os

# See the notes for this module in the documentation above ^.
#import select
# if not has_attribute(select, 'kqueue') or sys.version_info < (2, 7, 0):
if sys.version_info < (2, 7, 0):
    import select_backport as select
else:
    import select
示例#10
0
cover_packages_bsd = [
    'watchdog.observers.kqueue_observer',
]
cover_packages_darwin = [
    'watchdog.observers.fsevents_observer',
    'watchdog.observers.kqueue_observer',
]
cover_packages_linux = [
    'watchdog.observers.inotify_observer',
]

if platform.is_windows():
    cover_packages.extend(cover_packages_windows)
elif platform.is_darwin():
    cover_packages.extend(cover_packages_darwin)
elif platform.is_bsd():
    cover_packages.extend(cover_packages_bsd)
elif platform.is_linux():
    cover_packages.extend(cover_packages_linux)


if __name__ == "__main__":
    config_path = os.path.join(parent_dir_path, 'nose.cfg')

    argv = [__file__]
    argv.append('--detailed-errors')
    argv.append('--with-coverage')
    # Coverage by itself generates more usable reports.
    #argv.append('--cover-erase')
    #argv.append('--cover-html')
    argv.append('--cover-package=%s' % ','.join(cover_packages))
示例#11
0
.. autoclass:: KeventDescriptor
   :members:
   :show-inheritance:

.. autoclass:: KeventDescriptorSet
   :members:
   :show-inheritance:

.. _Mac OS X File System Performance Guidelines: http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/FileSystem/Articles/TrackingChanges.html#//apple_ref/doc/uid/20001993-CJBJFIDD

"""

from __future__ import with_statement
from watchdog.utils import platform  # , has_attribute

if platform.is_bsd() or platform.is_darwin():
    import threading
    import errno
    import sys
    import stat
    import os

    # See the notes for this module in the documentation above ^.
    # import select
    # if not has_attribute(select, 'kqueue') or sys.version_info < (2, 7, 0):
    if sys.version_info < (2, 7, 0):
        import select_backport as select
    else:
        import select

    from pathtools.path import absolute_path
示例#12
0
    FileClosedEvent,
)
from watchdog.observers.api import ObservedWatch

if platform.is_linux():
    from watchdog.observers.inotify import (
        InotifyEmitter as Emitter,
        InotifyFullEmitter,
    )
elif platform.is_darwin():
    from watchdog.observers.fsevents import FSEventsEmitter as Emitter
elif platform.is_windows():
    from watchdog.observers.read_directory_changes import (
        WindowsApiEmitter as Emitter
    )
elif platform.is_bsd():
    from watchdog.observers.kqueue import (
        KqueueEmitter as Emitter
    )

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


if platform.is_darwin():
    # enable more verbose logs
    fsevents_logger = logging.getLogger("fsevents")
    fsevents_logger.setLevel(logging.DEBUG)


@pytest.fixture(autouse=True)
示例#13
0
    FileClosedEvent,
)
from watchdog.observers.api import ObservedWatch

if platform.is_linux():
    from watchdog.observers.inotify import (
        InotifyEmitter as Emitter,
        InotifyFullEmitter,
    )
elif platform.is_darwin():
    from watchdog.observers.fsevents import FSEventsEmitter as Emitter
elif platform.is_windows():
    from watchdog.observers.read_directory_changes import (
        WindowsApiEmitter as Emitter
    )
elif platform.is_bsd():
    from watchdog.observers.kqueue import (
        KqueueEmitter as Emitter
    )

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)


if platform.is_darwin():
    # enable more verbose logs
    fsevents_logger = logging.getLogger("fsevents")
    fsevents_logger.setLevel(logging.DEBUG)


@pytest.fixture(autouse=True)
示例#14
0
   :members:
   :show-inheritance:

.. autoclass:: KeventDescriptorSet
   :members:
   :show-inheritance:

.. _Mac OS X File System Performance Guidelines: http://developer.apple.com/library/ios/#documentation/Performance/Conceptual/FileSystem/Articles/TrackingChanges.html#//apple_ref/doc/uid/20001993-CJBJFIDD

"""

from __future__ import with_statement
from watchdog.utils import\
  platform #, has_attribute

if platform.is_bsd() or platform.is_darwin():
    import threading
    import errno
    import sys
    import stat
    import os

    # See the notes for this module in the documentation above ^.
    #import select
    #if not has_attribute(select, 'kqueue') or sys.version_info < (2, 7, 0):
    if sys.version_info < (2, 7, 0):
        import select_backport as select
    else:
        import select

    from pathtools.path import absolute_path