Skip to content

Commit

Permalink
unittest: Test the command line argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
solarnz committed Jun 8, 2014
1 parent 645df86 commit 269508d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions nose_watcher/nose_watcher.py
Expand Up @@ -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 |
Expand All @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_nose_watcher.py
Expand Up @@ -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'}))

Expand All @@ -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']
)

0 comments on commit 269508d

Please sign in to comment.