-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/unittests' into develop
- Loading branch information
Showing
5 changed files
with
138 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
__author__ = 'Chris Trotman' | ||
__email__ = 'chris@trotman.io' | ||
__version__ = '0.1.0' | ||
__version__ = '0.1.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
wheel | ||
nose | ||
mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# -*- coding: utf-8 -*- | ||
# -*- coding: utf-8 -*- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,121 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
test_nose-watcher | ||
---------------------------------- | ||
Tests for `nose-watcher` module. | ||
""" | ||
|
||
from collections import namedtuple | ||
import sys | ||
import unittest | ||
|
||
from nose_watcher import nose_watcher | ||
from mock import Mock, patch | ||
|
||
from nose_watcher.nose_watcher import WatcherPlugin | ||
|
||
|
||
class TestNoseWatcher(unittest.TestCase): | ||
|
||
def setUp(self): | ||
pass | ||
self.plugin = WatcherPlugin() | ||
self.plugin.testing = True | ||
self.plugin.call = Mock() | ||
|
||
|
||
class TestFileTypes(TestNoseWatcher): | ||
def test_file_types_py(self): | ||
self.assertTrue(self.plugin.check_files({'test.py'})) | ||
|
||
def test_file_types_pyx(self): | ||
self.assertTrue(self.plugin.check_files({'test.pyx'})) | ||
|
||
def test_file_types_pyc(self): | ||
self.assertFalse(self.plugin.check_files({'test.pyc'})) | ||
|
||
def test_file_types_py_and_pyc(self): | ||
self.assertTrue(self.plugin.check_files({'test.py', 'test.pyc'})) | ||
|
||
def test_file_types_pyc_and_txt(self): | ||
self.assertFalse(self.plugin.check_files({'test.txt', 'test.pyc'})) | ||
|
||
|
||
class TestArgumentParsing(TestNoseWatcher): | ||
def test_arguments(self): | ||
args_in = ['laa', '--with-%s' % WatcherPlugin.name, '--with-cover'] | ||
args_out = self.plugin.get_commandline_arguments(args_in) | ||
|
||
self.assertEqual( | ||
args_out, | ||
['laa', '--with-cover'] | ||
) | ||
|
||
def test_argument_parsing_from_sys_argv(self): | ||
self.assertEqual( | ||
self.plugin.get_commandline_arguments(), | ||
[a for a in sys.argv if a != '--with-watcher'] | ||
) | ||
|
||
|
||
class TestWatching(TestNoseWatcher): | ||
@patch('inotify.watcher.AutoWatcher') | ||
@patch('inotify.watcher.Threshold') | ||
@patch('select.poll') | ||
def test_watch_no_files_modified(self, poll_mock, threshold_patch, | ||
watcher_mock): | ||
threshold = Mock() | ||
threshold_patch.return_value = threshold | ||
threshold.return_value = True | ||
self.plugin.finalize(None) | ||
|
||
self.assertFalse(self.plugin.call.called) | ||
|
||
@patch('inotify.watcher.AutoWatcher') | ||
@patch('inotify.watcher.Threshold') | ||
@patch('select.poll') | ||
def test_watch_no_files_watched(self, poll_mock, threshold_patch, | ||
watcher_mock): | ||
threshold = Mock() | ||
threshold_patch.return_value = threshold | ||
threshold.return_value = True | ||
|
||
watcher = Mock() | ||
watcher_mock.return_value = watcher | ||
|
||
watcher.num_watches.return_value = False | ||
self.plugin.finalize(None) | ||
|
||
self.assertFalse(self.plugin.call.called) | ||
|
||
@patch('inotify.watcher.AutoWatcher') | ||
@patch('inotify.watcher.Threshold') | ||
@patch('select.poll') | ||
def test_watch_python_files_modified(self, poll_mock, threshold_patch, | ||
watcher_mock): | ||
threshold = Mock() | ||
threshold_patch.return_value = threshold | ||
threshold.return_value = True | ||
|
||
watcher = Mock() | ||
watcher_mock.return_value = watcher | ||
|
||
Event = namedtuple('Event', ['fullpath']) | ||
watcher.read.return_value = [ | ||
Event('aaa/python.py') | ||
] | ||
self.plugin.finalize(None) | ||
|
||
self.assertTrue(self.plugin.call.called) | ||
|
||
@patch('inotify.watcher.AutoWatcher') | ||
@patch('inotify.watcher.Threshold') | ||
@patch('select.poll') | ||
def test_watch_text_files_modified(self, poll_mock, threshold_patch, | ||
watcher_mock): | ||
threshold = Mock() | ||
threshold_patch.return_value = threshold | ||
threshold.return_value = True | ||
|
||
watcher = Mock() | ||
watcher_mock.return_value = watcher | ||
|
||
def test_something(self): | ||
pass | ||
Event = namedtuple('Event', ['fullpath']) | ||
watcher.read.return_value = [ | ||
Event('aaa/python.txt') | ||
] | ||
self.plugin.finalize(None) | ||
|
||
def tearDown(self): | ||
pass | ||
self.assertFalse(self.plugin.call.called) |