You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by wi...@apache.org on 2014/07/22 20:00:45 UTC

git commit: AURORA-595: Do not rely upon pytest capsys since command line parameters alter outcome.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master fd60eab6f -> d71f4eb0e


AURORA-595: Do not rely upon pytest capsys since command line parameters alter outcome.

Testing Done:
./pants src/test/python/apache/aurora/common:test_cluster_option -s

Bugs closed: AURORA-595

Reviewed at https://reviews.apache.org/r/23817/


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

Branch: refs/heads/master
Commit: d71f4eb0eac0fbbd090e98b709d515413f173f62
Parents: fd60eab
Author: Brian Wickman <wi...@apache.org>
Authored: Tue Jul 22 11:00:20 2014 -0700
Committer: Brian Wickman <wi...@apache.org>
Committed: Tue Jul 22 11:00:20 2014 -0700

----------------------------------------------------------------------
 .../apache/aurora/client/commands/core.py       |  1 +
 .../apache/aurora/common/test_cluster_option.py | 42 +++++++++++++++-----
 2 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d71f4eb0/src/main/python/apache/aurora/client/commands/core.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/commands/core.py b/src/main/python/apache/aurora/client/commands/core.py
index 3c45ed4..b416999 100644
--- a/src/main/python/apache/aurora/client/commands/core.py
+++ b/src/main/python/apache/aurora/client/commands/core.py
@@ -64,6 +64,7 @@ from apache.aurora.common.aurora_job_key import AuroraJobKey
 from gen.apache.aurora.api.constants import ACTIVE_STATES, AURORA_EXECUTOR_NAME, CURRENT_API_VERSION
 from gen.apache.aurora.api.ttypes import ExecutorConfig, ResponseCode, ScheduleStatus
 
+
 class CoreCommandHook(object):
   """Limited version of the command hooks framework ported to clientv1 commands.
   Core command hooks can only be created by invoking "CoreCommandHook.register_hook"

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/d71f4eb0/src/test/python/apache/aurora/common/test_cluster_option.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/common/test_cluster_option.py b/src/test/python/apache/aurora/common/test_cluster_option.py
index 2213d8c..607a748 100644
--- a/src/test/python/apache/aurora/common/test_cluster_option.py
+++ b/src/test/python/apache/aurora/common/test_cluster_option.py
@@ -12,8 +12,9 @@
 # limitations under the License.
 #
 
+from optparse import OptionParser
+
 import pytest
-from twitter.common import options
 
 from apache.aurora.common.cluster import Cluster
 from apache.aurora.common.cluster_option import ClusterOption
@@ -43,18 +44,37 @@ def test_constructors():
     ClusterOption('--cluster', clusters=CLUSTER_LIST, cluster_provider=cluster_provider)
 
 
-def test_parsable(capsys):
-  parser = options.parser().options((
-    ClusterOption('--source_cluster', '-s', clusters=CLUSTER_LIST),
-    ClusterOption('--dest_cluster', clusters=CLUSTER_LIST),
-    ClusterOption('--cluster', cluster_provider=cluster_provider)))
+class MockOptionParser(OptionParser):
+  class Error(Exception): pass
+
+  def error(self, msg):
+    # per optparse documentation:
+    # Print a usage message incorporating 'msg' to stderr and exit.
+    # If you override this in a subclass, it should not return -- it
+    # should either exit or raise an exception.
+    raise self.Error(msg)
+
+
+def make_parser():
+  parser = MockOptionParser()
+  parser.add_option(ClusterOption('--source_cluster', '-s', clusters=CLUSTER_LIST))
+  parser.add_option(ClusterOption('--dest_cluster', clusters=CLUSTER_LIST))
+  parser.add_option(ClusterOption('--cluster', cluster_provider=cluster_provider))
+  return parser
+
 
-  values, _ = parser.parse(['--source_cluster=smf1-test', '--cluster=smf1-test'])
+def test_parsable():
+  parser = make_parser()
+  values, _ = parser.parse_args(['--source_cluster=smf1-test', '--cluster=smf1-test'])
   assert isinstance(values.source_cluster, Cluster)
   assert isinstance(values.cluster, Cluster)
 
-  with pytest.raises(SystemExit):
-    parser.parse(['--source_cluster=borg'])
 
-  out, err = capsys.readouterr()
-  assert 'error: borg is not a valid cluster for the --source_cluster option.' in err
+def test_not_parsable():
+  parser = make_parser()
+  try:
+    parser.parse_args(['--source_cluster=borg'])
+  except MockOptionParser.Error as e:
+    assert 'borg is not a valid cluster for the --source_cluster option.' in e.args[0]
+  else:
+    assert False, 'Expected OptionParser to raise on invalid cluster list.'