Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1334)

Unified Diff: tests/gclient_utils_test.py

Issue 393001: Split scm-specific functions out of gclient_scm.py to scm.py. (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/gclient_test.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/gclient_utils_test.py
diff --git a/tests/gclient_utils_test.py b/tests/gclient_utils_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..339de38d20dd8fd3b3bc4bfc8ae9bd1c4b1fdf40
--- /dev/null
+++ b/tests/gclient_utils_test.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+# Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+import StringIO
+
+import gclient_utils
+from super_mox import SuperMoxTestBase
+
+class SubprocessCallAndFilterTestCase(SuperMoxTestBase):
+ def testSubprocessCallAndFilter(self):
+ command = ['boo', 'foo', 'bar']
+ in_directory = 'bleh'
+ fail_status = None
+ pattern = 'a(.*)b'
+ test_string = 'ahah\naccb\nallo\naddb\n'
+ class Mock(object):
+ stdout = StringIO.StringIO(test_string)
+ def wait(self):
+ pass
+ kid = Mock()
+ print("\n________ running 'boo foo bar' in 'bleh'")
+ for i in test_string:
+ gclient_utils.sys.stdout.write(i)
+ gclient_utils.subprocess.Popen(
+ command, bufsize=0, cwd=in_directory,
+ shell=(gclient_utils.sys.platform == 'win32'),
+ stdout=gclient_utils.subprocess.PIPE,
+ stderr=gclient_utils.subprocess.STDOUT).AndReturn(kid)
+ self.mox.ReplayAll()
+ compiled_pattern = re.compile(pattern)
+ line_list = []
+ capture_list = []
+ def FilterLines(line):
+ line_list.append(line)
+ match = compiled_pattern.search(line)
+ if match:
+ capture_list.append(match.group(1))
+ gclient_utils.SubprocessCallAndFilter(
+ command, in_directory,
+ True, True,
+ fail_status, FilterLines)
+ self.assertEquals(line_list, ['ahah', 'accb', 'allo', 'addb'])
+ self.assertEquals(capture_list, ['cc', 'dd'])
+
+
+if __name__ == '__main__':
+ import unittest
+ unittest.main()
+
+# vim: ts=2:sw=2:tw=80:et:
« no previous file with comments | « tests/gclient_test.py ('k') | tests/scm_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698