diff --git a/nose_watcher/nose_watcher.py b/nose_watcher/nose_watcher.py index f6b20fb..6f736a8 100755 --- a/nose_watcher/nose_watcher.py +++ b/nose_watcher/nose_watcher.py @@ -15,9 +15,6 @@ class WatcherPlugin(Plugin): # The name of the plugin name = PLUGIN_NAME - # The arguments we want to run nose with again. - args = [a for a in sys.argv if a != '--with-%s' % PLUGIN_NAME] - # The inotify events we want to listen for inotify_events = ( inotify.IN_ATTRIB | inotify.IN_CLOSE_WRITE | inotify.IN_CREATE | @@ -30,12 +27,21 @@ class WatcherPlugin(Plugin): python_files = ('.py', '.pyx') def call(self): - Popen(self.args).wait() + args = self.get_commandline_arguments() + Popen(args).wait() def check_files(self, files): return any(f.endswith(self.python_files) for f in files) - def print_status(self): + def get_commandline_arguments(self, argv=None): + if argv is None: + argv = sys.argv + + # The arguments we want to run nose with again. + args = [a for a in argv if a != '--with-%s' % PLUGIN_NAME] + return args + + def print_status(self): # pragma:nocover print('Watching for changes...\n') def finalize(self, result): diff --git a/tests/test_nose_watcher.py b/tests/test_nose_watcher.py index 9e60d7d..afa28f0 100644 --- a/tests/test_nose_watcher.py +++ b/tests/test_nose_watcher.py @@ -12,6 +12,8 @@ def setUp(self): self.plugin = WatcherPlugin() self.plugin.call = Mock() + +class TestFileTypes(TestNoseWatcher): def test_file_types_py(self): self.assertTrue(self.plugin.check_files({'test.py'})) @@ -26,3 +28,14 @@ def test_file_types_py_and_pyc(self): 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'] + )