incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [4/10] git commit: [5703] Fix arg parsing and add test
Date Fri, 15 Feb 2013 22:46:13 GMT
[5703] Fix arg parsing and add test


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/0f59f64e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/0f59f64e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/0f59f64e

Branch: refs/heads/cj/5685
Commit: 0f59f64e6b4cee05877d72107b91e0e1cc50ab53
Parents: 224d54c
Author: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Authored: Wed Feb 13 17:51:17 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Wed Feb 13 17:51:17 2013 +0000

----------------------------------------------------------------------
 Allura/allura/scripts/scripttask.py    |    3 ++-
 Allura/allura/tests/test_scripttask.py |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0f59f64e/Allura/allura/scripts/scripttask.py
----------------------------------------------------------------------
diff --git a/Allura/allura/scripts/scripttask.py b/Allura/allura/scripts/scripttask.py
index 9dbe857..85626a1 100644
--- a/Allura/allura/scripts/scripttask.py
+++ b/Allura/allura/scripts/scripttask.py
@@ -29,6 +29,7 @@ To call as a task::
 
 import argparse
 import logging
+import shlex
 import sys
 
 from allura.lib.decorators import task
@@ -66,7 +67,7 @@ class ScriptTask(object):
             sys.stdout = Writer(log.info)
             sys.stderr = Writer(log.error)
             try:
-                options = cls.parser().parse_args(arg_string.split(' '))
+                options = cls.parser().parse_args(shlex.split(arg_string or ''))
             except SystemExit:
                 raise Exception("Error parsing args: '%s'" % arg_string)
             cls.execute(options)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/0f59f64e/Allura/allura/tests/test_scripttask.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_scripttask.py b/Allura/allura/tests/test_scripttask.py
new file mode 100644
index 0000000..a7c61bf
--- /dev/null
+++ b/Allura/allura/tests/test_scripttask.py
@@ -0,0 +1,24 @@
+import unittest
+import mock
+
+from allura.scripts.scripttask import ScriptTask
+
+
+class TestScriptTask(unittest.TestCase):
+    def setUp(self):
+        class TestScriptTask(ScriptTask):
+            _parser = mock.Mock()
+            @classmethod
+            def parser(cls):
+                return cls._parser
+        self.cls = TestScriptTask
+
+    @mock.patch('allura.scripts.scripttask.sys')
+    def test_arg_parsing(self, sys):
+        "Make sure string of args gets correctly tokenized."
+        parser = self.cls.parser()
+        self.cls._execute_task('--dir "My Dir"')
+        parser.parse_args.assert_called_once_with(['--dir', 'My Dir'])
+        parser.reset_mock()
+        self.cls._execute_task(None)
+        parser.parse_args.assert_called_once_with([])


Mime
View raw message