Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moving to unittest2.

Signed-off-by: Gora Khargosh <gora.khargosh@gmail.com>
  • Loading branch information...
commit 0ccd9f6d3c774b60152412ee6b134db8f512dfc6 1 parent 1523750
@gorakhargosh gorakhargosh authored
View
14 .coveragerc
@@ -0,0 +1,14 @@
+# .coveragerc to control coverage.py
+[run]
+branch = False
+
+source =
+ watchdog
+
+omit =
+ /*/tests/*
+
+[report]
+
+[html]
+directory = htmlcov
View
2  .gitignore
@@ -36,8 +36,8 @@ nbproject/
# Generated by tests.
.coverage
-.pythoscope/
htmlcov/
+.tox/
# From virtualenv.
include/
View
316 tests/test_watchdog_events.py
@@ -1,13 +1,9 @@
# -*- coding: utf-8 -*-
-# test_watchdog_events.py: tests for the watchdog.events module.
-from nose.tools import \
- assert_equal, \
- assert_true, \
- assert_false, \
- assert_not_equal
-from utils import assert_readonly_public_attributes
+import unittest2
+
+from tests.utils import list_attributes
from watchdog.utils import has_attribute
from pathtools.patterns import filter_paths
from watchdog.events import \
@@ -33,263 +29,252 @@
path_1 = '/path/xyz'
path_2 = '/path/abc'
-def assert_event_type(event, event_type):
- assert_true(event.event_type == event_type)
- #if event.event_type != event_type:
- # assert False, "%s: event.event_type is not %s" % (event, event_type)
-
-def assert_check_directory(handler, event):
- assert_false(handler.ignore_directories and event.is_directory)
- #if handler.ignore_directories and event.is_directory:
- # assert False, "Event %s should have been ignored by event.ignore_directories=True" % event
-
-class TestFileSystemEvent:
- def __init__(self):
- pass
+class TestFileSystemEvent(unittest2.TestCase):
def test___eq__(self):
event1 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
event2 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
- assert_true(event1.__eq__(event2))
+ self.assertTrue(event1.__eq__(event2))
def test___hash__(self):
event1 = FileSystemEvent(EVENT_TYPE_DELETED, path_1, False)
event2 = FileSystemEvent(EVENT_TYPE_DELETED, path_1, False)
event3 = FileSystemEvent(EVENT_TYPE_DELETED, path_2, False)
- assert_equal(event1.__hash__(), event2.__hash__())
- assert_not_equal(event1.__hash__(), event3.__hash__())
+ self.assertEqual(event1.__hash__(), event2.__hash__())
+ self.assertNotEqual(event1.__hash__(), event3.__hash__())
def test___init__(self):
event = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
- assert_equal(event.src_path, path_1)
- assert_equal(event.event_type, EVENT_TYPE_MODIFIED)
- assert_equal(event.is_directory, True)
+ self.assertEqual(event.src_path, path_1)
+ self.assertEqual(event.event_type, EVENT_TYPE_MODIFIED)
+ self.assertEqual(event.is_directory, True)
def test___ne__(self):
event1 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
event2 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_2, True)
- assert_true(event1.__ne__(event2))
+ self.assertTrue(event1.__ne__(event2))
def test___repr__(self):
event = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, False)
- assert_equal('<FileSystemEvent: event_type=%s, src_path=%s, is_directory=%s>' \
+ self.assertEqual(
+ '<FileSystemEvent: event_type=%s, src_path=%s, is_directory=%s>' \
% (EVENT_TYPE_MODIFIED, path_1, False), event.__repr__())
def test___str__(self):
event = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, False)
- assert_equal('<FileSystemEvent: event_type=%s, src_path=%s, is_directory=%s>' \
+ self.assertEqual(
+ '<FileSystemEvent: event_type=%s, src_path=%s, is_directory=%s>' \
% (EVENT_TYPE_MODIFIED, path_1, False), event.__str__())
def test_event_type(self):
event1 = FileSystemEvent(EVENT_TYPE_DELETED, path_1, False)
event2 = FileSystemEvent(EVENT_TYPE_CREATED, path_2, True)
- assert_equal(EVENT_TYPE_DELETED, event1.event_type)
- assert_equal(EVENT_TYPE_CREATED, event2.event_type)
+ self.assertEqual(EVENT_TYPE_DELETED, event1.event_type)
+ self.assertEqual(EVENT_TYPE_CREATED, event2.event_type)
def test_is_directory(self):
event1 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
event2 = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, False)
- assert_true(event1.is_directory)
- assert_false(event2.is_directory)
+ self.assertTrue(event1.is_directory)
+ self.assertFalse(event2.is_directory)
def test_src_path(self):
event1 = FileSystemEvent(EVENT_TYPE_CREATED, path_1, True)
event2 = FileSystemEvent(EVENT_TYPE_CREATED, path_2, False)
- assert_equal(path_1, event1.src_path)
- assert_equal(path_2, event2.src_path)
+ self.assertEqual(path_1, event1.src_path)
+ self.assertEqual(path_2, event2.src_path)
def test_behavior_readonly_public_attributes(self):
event = FileSystemEvent(EVENT_TYPE_MODIFIED, path_1, True)
- assert_readonly_public_attributes(event)
-
+ for prop in list_attributes(event):
+ assert_Raises(AttributeError, setattr, event, prop, None)
-class TestFileSystemMovedEvent:
- def __init__(self):
- pass
+class TestFileSystemMovedEvent(unittest2.TestCase):
def test___init__(self):
event = FileSystemMovedEvent(path_1, path_2, True)
- assert_equal(event.src_path, path_1)
- assert_equal(event.dest_path, path_2)
- assert_equal(event.event_type, EVENT_TYPE_MOVED)
- assert_equal(event.is_directory, True)
+ self.assertEqual(event.src_path, path_1)
+ self.assertEqual(event.dest_path, path_2)
+ self.assertEqual(event.event_type, EVENT_TYPE_MOVED)
+ self.assertEqual(event.is_directory, True)
def test___repr__(self):
event = FileSystemMovedEvent(path_1, path_2, True)
- assert_equal('<FileSystemMovedEvent: src_path=%s, dest_path=%s, is_directory=%s>' \
- % (path_1, path_2, True), event.__repr__())
+ self.assertEqual(
+ '<FileSystemMovedEvent: src_path=%s, dest_path=%s, ' \
+ 'is_directory=%s>' % (path_1, path_2, True), event.__repr__())
def test_dest_path(self):
event = FileSystemMovedEvent(path_1, path_2, True)
- assert_equal(path_2, event.dest_path)
+ self.assertEqual(path_2, event.dest_path)
def test_behavior_readonly_public_attributes(self):
event = FileSystemMovedEvent(path_2, path_1, True)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestFileDeletedEvent:
- def __init__(self):
- pass
+class TestFileDeletedEvent(unittest2.TestCase):
def test___init__(self):
event = FileDeletedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_DELETED, event.event_type)
- assert_false(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_DELETED, event.event_type)
+ self.assertFalse(event.is_directory)
def test___repr__(self):
event = FileDeletedEvent(path_1)
- assert_equal("<FileDeletedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<FileDeletedEvent: src_path=%s>" % \
+ path_1, event.__repr__())
# Behavior tests.
def test_behavior_readonly_public_attributes(self):
event = FileDeletedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
# Inherited properties.
def test_is_directory(self):
event1 = FileDeletedEvent(path_1)
- assert_false(event1.is_directory)
+ self.assertFalse(event1.is_directory)
-class TestFileModifiedEvent:
- def __init__(self):
- pass
+class TestFileModifiedEvent(unittest2.TestCase):
def test___init__(self):
event = FileModifiedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_MODIFIED, event.event_type)
- assert_false(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_MODIFIED, event.event_type)
+ self.assertFalse(event.is_directory)
def test___repr__(self):
event = FileModifiedEvent(path_1)
- assert_equal("<FileModifiedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<FileModifiedEvent: src_path=%s>" % \
+ path_1, event.__repr__())
# Behavior
def test_behavior_readonly_public_attributes(self):
event = FileModifiedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
# Inherited Properties
def test_is_directory(self):
event1 = FileModifiedEvent(path_1)
- assert_false(event1.is_directory)
+ self.assertFalse(event1.is_directory)
-class TestFileCreatedEvent:
- def __init__(self):
- pass
+class TestFileCreatedEvent(unittest2.TestCase):
def test___init__(self):
event = FileCreatedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_CREATED, event.event_type)
- assert_false(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_CREATED, event.event_type)
+ self.assertFalse(event.is_directory)
def test___repr__(self):
event = FileCreatedEvent(path_1)
- assert_equal("<FileCreatedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<FileCreatedEvent: src_path=%s>" % \
+ path_1, event.__repr__())
def test_behavior_readonly_public_attributes(self):
event = FileCreatedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestFileMovedEvent:
- def __init__(self):
- pass
+class TestFileMovedEvent(unittest2.TestCase):
def test___init__(self):
event = FileMovedEvent(path_1, path_2)
- assert_equal(path_1, event.src_path)
- assert_equal(path_2, event.dest_path)
- assert_equal(EVENT_TYPE_MOVED, event.event_type)
- assert_false(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(path_2, event.dest_path)
+ self.assertEqual(EVENT_TYPE_MOVED, event.event_type)
+ self.assertFalse(event.is_directory)
def test___repr__(self):
event = FileMovedEvent(path_1, path_2)
- assert_equal("<FileMovedEvent: src_path=%s, dest_path=%s>" % (path_1, path_2), event.__repr__())
+ self.assertEqual("<FileMovedEvent: src_path=%s, dest_path=%s>" % \
+ (path_1, path_2), event.__repr__())
def test_behavior_readonly_public_attributes(self):
event = FileMovedEvent(path_1, path_2)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestDirDeletedEvent:
- def __init__(self):
- pass
+class TestDirDeletedEvent(unittest2.TestCase):
def test___init__(self):
event = DirDeletedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_DELETED, event.event_type)
- assert_true(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_DELETED, event.event_type)
+ self.assertTrue(event.is_directory)
def test___repr__(self):
event = DirDeletedEvent(path_1)
- assert_equal("<DirDeletedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<DirDeletedEvent: src_path=%s>" % path_1,
+ event.__repr__())
def test_behavior_readonly_public_attributes(self):
event = DirDeletedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestDirModifiedEvent:
- def __init__(self):
- pass
+class TestDirModifiedEvent(unittest2.TestCase):
def test___init__(self):
event = DirModifiedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_MODIFIED, event.event_type)
- assert_true(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_MODIFIED, event.event_type)
+ self.assertTrue(event.is_directory)
def test___repr__(self):
event = DirModifiedEvent(path_1)
- assert_equal("<DirModifiedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<DirModifiedEvent: src_path=%s>" % path_1,
+ event.__repr__())
def test_behavior_readonly_public_attributes(self):
event = DirModifiedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestDirCreatedEvent:
- def __init__(self):
- pass
+class TestDirCreatedEvent(unittest2.TestCase):
def test___init__(self):
event = DirCreatedEvent(path_1)
- assert_equal(path_1, event.src_path)
- assert_equal(EVENT_TYPE_CREATED, event.event_type)
- assert_true(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(EVENT_TYPE_CREATED, event.event_type)
+ self.assertTrue(event.is_directory)
def test___repr__(self):
event = DirCreatedEvent(path_1)
- assert_equal("<DirCreatedEvent: src_path=%s>" % path_1, event.__repr__())
+ self.assertEqual("<DirCreatedEvent: src_path=%s>" % path_1,
+ event.__repr__())
def test_behavior_readonly_public_attributes(self):
event = DirCreatedEvent(path_1)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestDirMovedEvent:
- def __init__(self):
- pass
+class TestDirMovedEvent(unittest2.TestCase):
def test___init__(self):
event = DirMovedEvent(path_1, path_2)
- assert_equal(path_1, event.src_path)
- assert_equal(path_2, event.dest_path)
- assert_equal(EVENT_TYPE_MOVED, event.event_type)
- assert_true(event.is_directory)
+ self.assertEqual(path_1, event.src_path)
+ self.assertEqual(path_2, event.dest_path)
+ self.assertEqual(EVENT_TYPE_MOVED, event.event_type)
+ self.assertTrue(event.is_directory)
def test___repr__(self):
event = DirMovedEvent(path_1, path_2)
- assert_equal("<DirMovedEvent: src_path=%s, dest_path=%s>" % (path_1, path_2), event.__repr__())
+ self.assertEqual("<DirMovedEvent: src_path=%s, dest_path=%s>" % \
+ (path_1, path_2), event.__repr__())
def test_sub_moved_events(self):
mock_walker_path = [
@@ -323,17 +308,18 @@ def test_sub_moved_events(self):
def _mock_os_walker(path):
for root, directories, filenames in mock_walker_path:
yield (root, directories, filenames)
- calculated_events = set(dir_moved_event.sub_moved_events(_walker=_mock_os_walker))
- assert_equal(expected_events, calculated_events)
+ calculated_events = set(
+ dir_moved_event.sub_moved_events(_walker=_mock_os_walker)
+ )
+ self.assertEqual(expected_events, calculated_events)
def test_behavior_readonly_public_attributes(self):
event = DirMovedEvent(path_1, path_2)
- assert_readonly_public_attributes(event)
+ for prop in list_attributes(event):
+ self.assertRaises(AttributeError, setattr, event, prop, None)
-class TestFileSystemEventHandler:
- def __init__(self):
- pass
+class TestFileSystemEventHandler(unittest2.TestCase):
def test_dispatch(self):
dir_del_event = DirDeletedEvent('/path/blah.py')
@@ -356,21 +342,24 @@ def test_dispatch(self):
file_mov_event,
]
+ def assert_equal(a, b):
+ self.assertEqual(a, b)
+
class TestableEventHandler(FileSystemEventHandler):
def on_any_event(self, event):
assert True
def on_modified(self, event):
- assert_event_type(event, EVENT_TYPE_MODIFIED)
+ assert_equal(event.event_type, EVENT_TYPE_MODIFIED)
def on_deleted(self, event):
- assert_event_type(event, EVENT_TYPE_DELETED)
+ assert_equal(event.event_type, EVENT_TYPE_DELETED)
def on_moved(self, event):
- assert_event_type(event, EVENT_TYPE_MOVED)
+ assert_equal(event.event_type, EVENT_TYPE_MOVED)
def on_created(self, event):
- assert_event_type(event, EVENT_TYPE_CREATED)
+ assert_equal(event.event_type, EVENT_TYPE_CREATED)
handler = TestableEventHandler()
@@ -380,10 +369,7 @@ def on_created(self, event):
g_allowed_patterns = ["*.py", "*.txt"]
g_ignore_patterns = ["*.foo"]
-class TestPatternMatchingEventHandler:
- def __init__(self):
- pass
-
+class TestPatternMatchingEventHandler(unittest2.TestCase):
def test_dispatch(self):
# Utilities.
patterns = ['*.py', '*.txt']
@@ -397,7 +383,7 @@ def assert_patterns(event):
included_patterns=patterns,
excluded_patterns=ignore_patterns,
case_sensitive=False)
- assert_true(filtered_paths)
+ self.assertTrue(filtered_paths)
dir_del_event_match = DirDeletedEvent('/path/blah.py')
dir_del_event_not_match = DirDeletedEvent('/path/foobar')
@@ -457,28 +443,34 @@ def assert_patterns(event):
]
all_events = all_file_events + all_dir_events
+ def assert_check_directory(handler, event):
+ self.assertFalse(handler.ignore_directories and event.is_directory)
+
+ def assert_equal(a, b):
+ self.assertEqual(a, b)
+
class TestableEventHandler(PatternMatchingEventHandler):
def on_any_event(self, event):
assert_check_directory(self, event)
def on_modified(self, event):
assert_check_directory(self, event)
- assert_event_type(event, EVENT_TYPE_MODIFIED)
+ assert_equal(event.event_type, EVENT_TYPE_MODIFIED)
assert_patterns(event)
def on_deleted(self, event):
assert_check_directory(self, event)
- assert_event_type(event, EVENT_TYPE_DELETED)
+ assert_equal(event.event_type, EVENT_TYPE_DELETED)
assert_patterns(event)
def on_moved(self, event):
assert_check_directory(self, event)
- assert_event_type(event, EVENT_TYPE_MOVED)
+ assert_equal(event.event_type, EVENT_TYPE_MOVED)
assert_patterns(event)
def on_created(self, event):
assert_check_directory(self, event)
- assert_event_type(event, EVENT_TYPE_CREATED)
+ assert_equal(event.event_type, EVENT_TYPE_CREATED)
assert_patterns(event)
no_dirs_handler = TestableEventHandler(patterns=patterns,
@@ -495,26 +487,32 @@ def on_created(self, event):
def test___init__(self):
- handler1 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, True)
- handler2 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, False)
- assert_equal(handler1.patterns, g_allowed_patterns)
- assert_equal(handler1.ignore_patterns, g_ignore_patterns)
- assert_true(handler1.ignore_directories)
- assert_false(handler2.ignore_directories)
+ handler1 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, True)
+ handler2 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, False)
+ self.assertEqual(handler1.patterns, g_allowed_patterns)
+ self.assertEqual(handler1.ignore_patterns, g_ignore_patterns)
+ self.assertTrue(handler1.ignore_directories)
+ self.assertFalse(handler2.ignore_directories)
def test_ignore_directories(self):
- handler1 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, True)
- handler2 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, False)
- assert_true(handler1.ignore_directories)
- assert_false(handler2.ignore_directories)
+ handler1 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, True)
+ handler2 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, False)
+ self.assertTrue(handler1.ignore_directories)
+ self.assertFalse(handler2.ignore_directories)
def test_ignore_patterns(self):
- handler1 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, True)
- assert_equal(handler1.ignore_patterns, g_ignore_patterns)
+ handler1 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, True)
+ self.assertEqual(handler1.ignore_patterns, g_ignore_patterns)
def test_patterns(self):
- handler1 = PatternMatchingEventHandler(g_allowed_patterns, g_ignore_patterns, True)
- assert_equal(handler1.patterns, g_allowed_patterns)
+ handler1 = PatternMatchingEventHandler(g_allowed_patterns,
+ g_ignore_patterns, True)
+ self.assertEqual(handler1.patterns, g_allowed_patterns)
class _TestableEventHandler(LoggingEventHandler):
@@ -523,23 +521,21 @@ def on_any_event(self, event):
def on_modified(self, event):
super(_TestableEventHandler, self).on_modified(event)
- assert_event_type(event, EVENT_TYPE_MODIFIED)
+ self.assertEqual(event.event_type, EVENT_TYPE_MODIFIED)
def on_deleted(self, event):
super(_TestableEventHandler, self).on_deleted(event)
- assert_event_type(event, EVENT_TYPE_DELETED)
+ self.assertEqual(event.event_type, EVENT_TYPE_DELETED)
def on_moved(self, event):
super(_TestableEventHandler, self).on_moved(event)
- assert_event_type(event, EVENT_TYPE_MOVED)
+ self.assertEqual(event.event_type, EVENT_TYPE_MOVED)
def on_created(self, event):
super(_TestableEventHandler, self).on_created(event)
- assert_event_type(event, EVENT_TYPE_CREATED)
+ self.assertEqual(event.event_type, EVENT_TYPE_CREATED)
-class TestLoggingEventHandler:
- def __init__(self):
- pass
+class TestLoggingEventHandler(unittest2.TestCase):
def test_dispatch(self):
# Utilities.
@@ -567,9 +563,7 @@ def test_dispatch(self):
for event in all_events:
handler.dispatch(event)
-class TestGenerateSubMovedEventsFor:
- def __init__(self):
- pass
+class TestGenerateSubMovedEventsFor(unittest2.TestCase):
def test_generate_sub_moved_events_for(self):
mock_walker_path = [
@@ -601,6 +595,8 @@ def test_generate_sub_moved_events_for(self):
def _mock_os_walker(path):
for root, directories, filenames in mock_walker_path:
yield (root, directories, filenames)
- calculated_events = set(_generate_sub_moved_events_for(src_path, dest_path, _walker=_mock_os_walker))
- assert_equal(expected_events, calculated_events)
+ calculated_events = set(
+ _generate_sub_moved_events_for(
+ src_path, dest_path, _walker=_mock_os_walker))
+ self.assertEqual(expected_events, calculated_events)
View
12 tests/test_watchdog_observers.py
@@ -1,12 +0,0 @@
-# -*- coding: utf-8 -*-
-
-from nose import SkipTest
-
-class TestObserver:
- def __init__(self):
- pass
-
- def test___init__(self):
- # TODO: implement this test
- # observer = Observer()
- raise SkipTest
View
148 tests/test_watchdog_observers_api.py
@@ -1,12 +1,8 @@
# -*- coding: utf-8 -*-
import time
-from nose.tools import \
- assert_true, \
- assert_false, \
- assert_equal, \
- assert_raises
-from nose import SkipTest
+import unittest2
+
from watchdog.observers.api import \
BaseObserver, \
EventEmitter, \
@@ -15,25 +11,17 @@
EventQueue
from watchdog.events import LoggingEventHandler, FileModifiedEvent
-class TestObservedWatch:
+
+class TestObservedWatch(unittest2.TestCase):
def test___eq__(self):
watch1 = ObservedWatch('/foobar', True)
watch2 = ObservedWatch('/foobar', True)
watch_ne1 = ObservedWatch('/foo', True)
watch_ne2 = ObservedWatch('/foobar', False)
- assert_true(watch1.__eq__(watch2))
- assert_false(watch1.__eq__(watch_ne1))
- assert_false(watch1.__eq__(watch_ne2))
-
- def test___hash__(self):
- # observed_watch = ObservedWatch(path, recursive)
- # assert_equal(expected, observed_watch.__hash__())
- raise SkipTest # TODO: implement your test here
-
- def test___init__(self):
- # observed_watch = ObservedWatch(path, recursive)
- raise SkipTest # TODO: implement your test here
+ self.assertTrue(watch1.__eq__(watch2))
+ self.assertFalse(watch1.__eq__(watch_ne1))
+ self.assertFalse(watch1.__eq__(watch_ne2))
def test___ne__(self):
watch1 = ObservedWatch('/foobar', True)
@@ -41,67 +29,25 @@ def test___ne__(self):
watch_ne1 = ObservedWatch('/foo', True)
watch_ne2 = ObservedWatch('/foobar', False)
- assert_false(watch1.__ne__(watch2))
- assert_true(watch1.__ne__(watch_ne1))
- assert_true(watch1.__ne__(watch_ne2))
+ self.assertFalse(watch1.__ne__(watch2))
+ self.assertTrue(watch1.__ne__(watch_ne1))
+ self.assertTrue(watch1.__ne__(watch_ne2))
def test___repr__(self):
observed_watch = ObservedWatch('/foobar', True)
- assert_equal('<ObservedWatch: path=/foobar, is_recursive=True>', observed_watch.__repr__())
-
- def test_is_recursive(self):
- # observed_watch = ObservedWatch(path, recursive)
- # assert_equal(expected, observed_watch.is_recursive())
- raise SkipTest # TODO: implement your test here
+ self.assertEqual('<ObservedWatch: path=/foobar, is_recursive=True>',
+ observed_watch.__repr__())
- def test_path(self):
- # observed_watch = ObservedWatch(path, recursive)
- # assert_equal(expected, observed_watch.path())
- raise SkipTest # TODO: implement your test here
- def test_signature(self):
- # observed_watch = ObservedWatch(path, recursive)
- # assert_equal(expected, observed_watch.signature())
- raise SkipTest # TODO: implement your test here
-
-
-class TestEventEmitter:
+class TestEventEmitter(unittest2.TestCase):
def test___init__(self):
event_queue = EventQueue()
watch = ObservedWatch('/foobar', True)
event_emitter = EventEmitter(event_queue, watch, timeout=1)
event_emitter.queue_event(FileModifiedEvent('/foobar/blah'))
- def test_timeout(self):
- # event_emitter = EventEmitter(event_queue, watch, timeout)
- # assert_equal(expected, event_emitter.timeout())
- raise SkipTest # TODO: implement your test here
-
- def test_on_thread_exit(self):
- # event_emitter = EventEmitter(event_queue, watch, timeout)
- # assert_equal(expected, event_emitter.on_thread_exit())
- raise SkipTest # TODO: implement your test here
-
- def test_queue_events(self):
- # event_emitter = EventEmitter(event_queue, watch, timeout)
- # assert_equal(expected, event_emitter.queue_events(event_queue, watch, timeout))
- raise SkipTest # TODO: implement your test here
-
- def test_run(self):
- # event_emitter = EventEmitter(event_queue, watch, timeout)
- # assert_equal(expected, event_emitter.run())
- raise SkipTest # TODO: implement your test here
-
- def test_watch(self):
- # event_emitter = EventEmitter(event_queue, watch, timeout)
- # assert_equal(expected, event_emitter.watch())
- raise SkipTest # TODO: implement your test here
-
-class TestEventDispatcher:
- def test___init__(self):
- # event_dispatcher = EventDispatcher(timeout)
- raise SkipTest # TODO: implement your test here
+class TestEventDispatcher(unittest2.TestCase):
def test_dispatch_event(self):
event = FileModifiedEvent('/foobar')
watch = ObservedWatch('/path', True)
@@ -116,27 +62,8 @@ def dispatch_event(self, event, watch):
time.sleep(1)
event_dispatcher.stop()
- def test_event_queue(self):
- # event_dispatcher = EventDispatcher(timeout)
- # assert_equal(expected, event_dispatcher.event_queue())
- raise SkipTest # TODO: implement your test here
-
- def test_timeout(self):
- # event_dispatcher = EventDispatcher(timeout)
- # assert_equal(expected, event_dispatcher.timeout())
- raise SkipTest # TODO: implement your test here
- def test_on_thread_exit(self):
- # event_dispatcher = EventDispatcher(timeout)
- # assert_equal(expected, event_dispatcher.on_thread_exit())
- raise SkipTest # TODO: implement your test here
-
- def test_run(self):
- # event_dispatcher = EventDispatcher(timeout)
- # assert_equal(expected, event_dispatcher.run())
- raise SkipTest # TODO: implement your test here
-
-class TestBaseObserver:
+class TestBaseObserver(unittest2.TestCase):
def test_basic(self):
observer = BaseObserver(EventEmitter)
handler = LoggingEventHandler()
@@ -146,9 +73,10 @@ def test_basic(self):
observer.add_handler_for_watch(handler, watch)
observer.add_handler_for_watch(handler, watch)
observer.remove_handler_for_watch(handler, watch)
- assert_raises(KeyError, observer.remove_handler_for_watch, handler, watch)
+ self.assertRaises(KeyError,
+ observer.remove_handler_for_watch, handler, watch)
observer.unschedule(watch)
- assert_raises(KeyError, observer.unschedule, watch)
+ self.assertRaises(KeyError, observer.unschedule, watch)
watch = observer.schedule(handler, '/foobar', True)
@@ -157,43 +85,3 @@ def test_basic(self):
time.sleep(1)
observer.unschedule_all()
observer.stop()
-
- def test___init__(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- raise SkipTest # TODO: implement your test here
-
- def test_add_handler_for_watch(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.add_handler_for_watch(event_handler, watch))
- raise SkipTest # TODO: implement your test here
-
- def test_dispatch_event(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.dispatch_event(event, watch))
- raise SkipTest # TODO: implement your test here
-
- def test_on_thread_exit(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.on_thread_exit())
- raise SkipTest # TODO: implement your test here
-
- def test_remove_handler_for_watch(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.remove_handler_for_watch(event_handler, watch))
- raise SkipTest # TODO: implement your test here
-
- def test_schedule(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.schedule(event_handler, path, recursive))
- raise SkipTest # TODO: implement your test here
-
- def test_unschedule(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.unschedule(watch))
- raise SkipTest # TODO: implement your test here
-
- def test_unschedule_all(self):
- # base_observer = BaseObserver(emitter_class, timeout)
- # assert_equal(expected, base_observer.unschedule_all())
- raise SkipTest # TODO: implement your test here
-
View
34 tests/test_watchdog_observers_polling.py
@@ -1,6 +1,13 @@
# -*- coding: utf-8 -*-
import os
+import unittest2
+
+try:
+ import queue # IGNORE:F0401
+except ImportError:
+ import Queue as queue # IGNORE:F0401
+
from time import sleep
from tests.shell import \
mkdir, \
@@ -8,18 +15,12 @@
touch, \
rm, \
mv
-from nose import SkipTest
-from nose.tools import assert_equal
-from watchdog.events import DirModifiedEvent, DirCreatedEvent, FileCreatedEvent, \
+from watchdog.events import DirModifiedEvent, DirCreatedEvent, \
+ FileCreatedEvent, \
FileMovedEvent, FileModifiedEvent, DirMovedEvent, FileDeletedEvent, \
DirDeletedEvent
-try:
- import queue # IGNORE:F0401
-except ImportError:
- import Queue as queue # IGNORE:F0401
-
from watchdog.observers.api import ObservedWatch
from watchdog.observers.polling import PollingEmitter as Emitter
@@ -33,7 +34,8 @@ def p(*args):
"""
return os.path.join(temp_dir, *args)
-class TestPollingEmitter:
+
+class TestPollingEmitter(unittest2.TestCase):
def setup(self):
self.event_queue = queue.Queue()
self.watch = ObservedWatch(temp_dir, True)
@@ -110,16 +112,4 @@ def test___init__(self):
except queue.Empty:
break
- assert_equal(expected, got)
-
-
- def test_on_thread_exit(self):
- # polling_emitter = PollingEmitter(event_queue, watch, timeout)
- # assert_equal(expected, polling_emitter.on_thread_exit())
- raise SkipTest # TODO: implement your test here
-
- def test_queue_events(self):
- # polling_emitter = PollingEmitter(event_queue, watch, timeout)
- # assert_equal(expected, polling_emitter.queue_events(event_queue, watch, timeout))
- raise SkipTest # TODO: implement your test here
-
+ self.assertEqual(expected, got)
View
70 tests/test_watchdog_utils_bricks.py
@@ -1,70 +0,0 @@
-# -*- coding: utf-8 -*-
-
-import threading
-from nose.tools import \
- assert_equal, \
- assert_true
-
-try:
- import queue # IGNORE:F0401
-except ImportError:
- import Queue as queue # IGNORE:F0401
-
-from watchdog.events import DirModifiedEvent, FileModifiedEvent
-from watchdog.utils.bricks import OrderedSetQueue
-
-class TestOrderedSetQueue:
- def test_behavior_ordered_set(self):
- dir_mod_event = DirModifiedEvent("/path/x")
- file_mod_event = FileModifiedEvent('/path/y')
- event_list = [
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- file_mod_event,
- file_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- file_mod_event,
- file_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- dir_mod_event,
- file_mod_event,
- file_mod_event,
- file_mod_event,
- file_mod_event,
- ]
- event_set = set(event_list)
- event_queue = OrderedSetQueue()
- for event in event_list:
- event_queue.put(event)
-
- def event_consumer(in_queue):
- events = []
- while True:
- try:
- event = in_queue.get(block=True, timeout=0.2)
- events.append(event)
- in_queue.task_done()
- except queue.Empty:
- break
-
- # Check set behavior.
- assert_true(len(set(events)) == len(events))
- assert_equal(set(events), event_set)
-
- # Check order.
- assert_equal(events[0], dir_mod_event)
- assert_equal(events[1], file_mod_event)
-
- consumer_thread = threading.Thread(target=event_consumer, args=(event_queue,))
- consumer_thread.start()
- consumer_thread.join()
View
8 tests/utils.py
@@ -2,14 +2,6 @@
from __future__ import with_statement
-from nose.tools import assert_raises
-
-
-def assert_readonly_public_attributes(o):
- for prop in list_attributes(o, True):
- assert_raises(AttributeError, setattr, o, prop, None)
-
-
def list_attributes(o, only_public=True):
if only_public:
def isattribute(o, attribute):
Please sign in to comment.
Something went wrong with that request. Please try again.