Skip to content

Commit

Permalink
Tests: Add tests for polling FSMonitor
Browse files Browse the repository at this point in the history
  • Loading branch information
phdru authored and ljmccarthy committed Jul 4, 2018
1 parent 2d2044b commit 8b98134
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
12 changes: 12 additions & 0 deletions tests/test_1_create_delete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os, time
from utils import *
from fsmonitor import *
from fsmonitor.polling import FSMonitor as PollingFSMonitor

def test_1_create_delete():
fsm_test = FSMonitorTest()
Expand All @@ -12,3 +13,14 @@ def test_1_create_delete():

assert fsm_test.event_happened(FSEvent.Create, "x")
assert fsm_test.event_happened(FSEvent.Delete, "x")

def test_1_create_delete_polling():
fsm_test = FSMonitorTest(PollingFSMonitor)
w = fsm_test.add_dir_watch(tempdir)
touch(get_testpath("x"))
remove(get_testpath("x"))

time.sleep(0.1)

assert fsm_test.event_happened(FSEvent.Create, "x")
assert fsm_test.event_happened(FSEvent.Delete, "x")
13 changes: 13 additions & 0 deletions tests/test_2_create_not_delete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os, time
from utils import *
from fsmonitor import *
from fsmonitor.polling import FSMonitor as PollingFSMonitor

def test_2_create_not_delete():
fsm_test = FSMonitorTest()
Expand All @@ -13,3 +14,15 @@ def test_2_create_not_delete():

assert fsm_test.event_happened(FSEvent.Create, "x")
assert not fsm_test.event_happened(FSEvent.Delete, "x")

def test_2_create_not_delete_polling():
fsm_test = FSMonitorTest(PollingFSMonitor)
w = fsm_test.add_dir_watch(tempdir)
touch(get_testpath("x"))
fsm_test.remove_watch(w)
remove(get_testpath("x"))

time.sleep(0.1)

assert fsm_test.event_happened(FSEvent.Create, "x")
assert not fsm_test.event_happened(FSEvent.Delete, "x")
13 changes: 13 additions & 0 deletions tests/test_3_errorno_enoent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from utils import *
from fsmonitor import *
from fsmonitor.compat import PY3
from fsmonitor.polling import FSMonitor as PollingFSMonitor

def test_3_errorno_enoent():
fsm_test = FSMonitorTest()
Expand All @@ -14,3 +15,15 @@ def test_3_errorno_enoent():
assert e.errno == err_code
else:
assert False, "Expected exception"

def test_3_errorno_enoent_polling():
fsm_test = FSMonitorTest(PollingFSMonitor)
err_code = errno.ENOENT
if PY3 and sys.platform == "win32":
err_code = errno.ESRCH
try:
fsm_test.add_dir_watch("/this/path/does/not/exist")
except FSMonitorError as e:
assert e.errno == err_code
else:
assert False, "Expected exception"
5 changes: 3 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from fsmonitor import FSMonitorThread

class FSMonitorTest(object):
def __init__(self):
self.monitor = FSMonitorThread(self.__callback)
def __init__(self, fsmonitor_class=None):
self.monitor = FSMonitorThread(self.__callback,
fsmonitor_class=fsmonitor_class)
self._lock = threading.Lock()
self._events = []

Expand Down

0 comments on commit 8b98134

Please sign in to comment.