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/12/18 01:40:27 UTC

incubator-aurora git commit: get_client_version should never be allowed to run unpatched in test.

Repository: incubator-aurora
Updated Branches:
  refs/heads/master ab18bd0eb -> 9042c56a3


get_client_version should never be allowed to run unpatched in test.

get_client_version tries to get the PEX-INFO of sys.argv[0], which is
usually pants when running tests (!) if the format of PEX-INFO changes to a
new version of pants (as is the case for pants 0.0.25), then tests will
start failing with an inscrutible error.  instead, just patch
get_client_version to something sensible.

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


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

Branch: refs/heads/master
Commit: 9042c56a3d3f7693d927a1e318f12076aecfaebe
Parents: ab18bd0
Author: Brian Wickman <wi...@apache.org>
Authored: Wed Dec 17 16:40:21 2014 -0800
Committer: Brian Wickman <wi...@apache.org>
Committed: Wed Dec 17 16:40:21 2014 -0800

----------------------------------------------------------------------
 .../apache/aurora/client/cli/test_help.py       | 53 +++++++++-----------
 1 file changed, 24 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/9042c56a/src/test/python/apache/aurora/client/cli/test_help.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_help.py b/src/test/python/apache/aurora/client/cli/test_help.py
index 1576edc..2fef282 100644
--- a/src/test/python/apache/aurora/client/cli/test_help.py
+++ b/src/test/python/apache/aurora/client/cli/test_help.py
@@ -29,18 +29,26 @@ class TestHelp(unittest.TestCase):
     self.transcript = []
     self.err_transcript = []
 
-  def mock_print(self, str):
-    for str in str.split('\n'):
-      self.transcript.append(str)
+  def mock_print(self, output, indent=0):
+    self.transcript.extend(output.splitlines())
 
-  def mock_print_err(self, str):
-    for str in str.split('\n'):
-      self.err_transcript.append(str)
+  def mock_print_err(self, output, indent=0):
+    self.err_transcript.extend(output.splitlines())
+
+  @contextlib.contextmanager
+  def standard_mocks(self):
+    with contextlib.nested(
+        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
+            side_effect=self.mock_print),
+        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_err',
+            side_effect=self.mock_print_err),
+        patch('apache.aurora.client.cli.get_client_version', return_value='0.0.test')):
+
+      yield
 
   def test_all_help(self):
     for noun in self.cmd.registered_nouns:
-      with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-          side_effect=self.mock_print):
+      with self.standard_mocks():
         self.cmd.execute(['help', noun])
         assert 'Usage for noun "%s":' % noun in self.transcript
         assert self.err_transcript == []
@@ -52,11 +60,10 @@ class TestHelp(unittest.TestCase):
           self.transcript = []
 
   def test_help(self):
-    with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-        side_effect=self.mock_print):
+    with self.standard_mocks():
       self.cmd.execute(['help'])
-      print(self.transcript)
       assert len(self.transcript) > 10
+      assert self.transcript[0] == 'Aurora Client version 0.0.test'
       assert self.transcript[1] == 'Usage:'
       assert '==Commands for jobs' in self.transcript
       assert '==Commands for quotas' in self.transcript
@@ -66,8 +73,7 @@ class TestHelp(unittest.TestCase):
     for plugin in self.cmd.plugins:
       if plugin.get_options() is not None:
         plugin_options += [p for p in plugin.get_options()]
-    with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-        side_effect=self.mock_print):
+    with self.standard_mocks():
       for noun in self.cmd.registered_nouns:
         for verb in self.cmd.nouns.get(noun).verbs.keys():
           self.transcript = []
@@ -80,8 +86,7 @@ class TestHelp(unittest.TestCase):
     for plugin in self.cmd.plugins:
       if plugin.get_options() is not None:
         plugin_options += [p for p in plugin.get_options()]
-    with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-               side_effect=self.mock_print):
+    with self.standard_mocks():
       for noun in self.cmd.registered_nouns:
         for verb in self.cmd.nouns.get(noun).verbs.keys():
           self.transcript = []
@@ -91,8 +96,7 @@ class TestHelp(unittest.TestCase):
             assert not any(line.endswith('=str') for line in self.transcript)
 
   def test_help_noun(self):
-    with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-        side_effect=self.mock_print):
+    with self.standard_mocks():
       self.cmd.execute(['help', 'job'])
       assert len(self.transcript) > 10
       assert self.transcript[0] == 'Usage for noun "job":' in self.transcript
@@ -101,8 +105,7 @@ class TestHelp(unittest.TestCase):
       assert any('job list' in t for t in self.transcript)
 
   def test_help_verb(self):
-    with patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-        side_effect=self.mock_print):
+    with self.standard_mocks():
       assert self.cmd.execute(['help', 'job', 'status']) == EXIT_OK
       assert len(self.transcript) > 5
       assert self.transcript[0] == 'Usage for verb "job status":' in self.transcript
@@ -112,11 +115,7 @@ class TestHelp(unittest.TestCase):
       assert any('status' for t in self.transcript)
 
   def test_help_unknown_noun(self):
-    with contextlib.nested(
-        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-            side_effect=self.mock_print),
-        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_err',
-            side_effect=self.mock_print_err)):
+    with self.standard_mocks():
       assert self.cmd.execute(['help', 'nothing']) == EXIT_INVALID_PARAMETER
       assert len(self.transcript) == 0
       assert len(self.err_transcript) == 2
@@ -124,11 +123,7 @@ class TestHelp(unittest.TestCase):
       assert "Valid nouns" in self.err_transcript[1]
 
   def test_help_unknown_verb(self):
-    with contextlib.nested(
-        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_out',
-            side_effect=self.mock_print),
-        patch('apache.aurora.client.cli.client.AuroraCommandLine.print_err',
-            side_effect=self.mock_print_err)):
+    with self.standard_mocks():
       assert self.cmd.execute(['help', 'job', 'nothing']) == EXIT_INVALID_PARAMETER
       assert len(self.transcript) == 0
       assert len(self.err_transcript) == 2