Exemplo n.º 1
0
    def test_iter(self, tmp_path):
        file1 = tmp_path / "file1"
        file1.touch()

        with BasicWatcher([str(tmp_path)]) as watcher:
            it = IterateInThread(watcher)

            file2 = tmp_path / "file2"
            file2.touch()
            # Check that we get notified about file2
            _, event_type, path = next(it)
            print(event_type, path)
            while path != str(file2):
                # On MacOS, for whatever reason, we get events about
                # the creation of tmp_path and file1.  Skip them.
                _, event_type, path = next(it)
                print(event_type, path)

            file1_renamed = tmp_path / "file1_renamed"
            file1.rename(file1_renamed)
            # Check for notification of renamed file.
            while path != str(file1_renamed):
                # Depending on platform, we may get more than one
                # event for file1. (E.g. on Linux we get both a
                # 'created' and a 'closed' event.)
                # (Also, on MacOS, for reasons not understood,
                # we appear to get a 'created' event for file1.)
                _, event_type, path = next(it)
                print(event_type, path)

            assert it.queue.empty()
Exemplo n.º 2
0
 def test_raises_error_if_started_twice(self, paths):
     with BasicWatcher(paths) as watcher:
         with pytest.raises(RuntimeError, match="already started"):
             watcher.start()
Exemplo n.º 3
0
 def test_perverse_usage(self, paths):
     # This exercises a bug which occurred when BasicWatcher was
     # called with repeated (failing) values in observer_classes.
     observer_classes = (BrokenObserver, BrokenObserver, PollingObserver)
     with BasicWatcher(paths, observer_classes=observer_classes) as watcher:
         assert isinstance(watcher.observer, BaseObserver)
Exemplo n.º 4
0
 def test_default_observer_is_polling(self, paths, capsys):
     observer_classes = (BrokenObserver, BrokenObserver)
     with pytest.raises(OSError, match=r"crapout"):
         with BasicWatcher(paths, observer_classes=observer_classes):
             pass
     assert capsys.readouterr() == ("", "")
Exemplo n.º 5
0
 def test_default_observer_broken(self, paths, capsys):
     observer_classes = (BrokenObserver, PollingObserver)
     with BasicWatcher(paths, observer_classes=observer_classes) as watcher:
         assert watcher.observer.__class__ is PollingObserver
     assert "crapout" in capsys.readouterr().out
Exemplo n.º 6
0
 def test_creates_observer(self, paths):
     with BasicWatcher(paths) as watcher:
         assert isinstance(watcher.observer, BaseObserver)