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

Side by Side Diff: build/android/pylib/cmd_helper_test.py

Issue 812543002: Update from https://crrev.com/308331 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 unified diff | Download patch
« no previous file with comments | « build/android/pylib/cmd_helper.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Tests for the cmd_helper module.""" 5 """Tests for the cmd_helper module."""
6 6
7 import unittest 7 import unittest
8 import subprocess
8 9
9 from pylib import cmd_helper 10 from pylib import cmd_helper
10 11
11 # TODO(jbudorick) Make these tests run on the bots.
12
13 12
14 class CmdHelperSingleQuoteTest(unittest.TestCase): 13 class CmdHelperSingleQuoteTest(unittest.TestCase):
15 14
16 def testSingleQuote_basic(self): 15 def testSingleQuote_basic(self):
17 self.assertEquals('hello', 16 self.assertEquals('hello',
18 cmd_helper.SingleQuote('hello')) 17 cmd_helper.SingleQuote('hello'))
19 18
20 def testSingleQuote_withSpaces(self): 19 def testSingleQuote_withSpaces(self):
21 self.assertEquals("'hello world'", 20 self.assertEquals("'hello world'",
22 cmd_helper.SingleQuote('hello world')) 21 cmd_helper.SingleQuote('hello world'))
(...skipping 21 matching lines...) Expand all
44 43
45 def testDoubleQuote_withUnsafeChars(self): 44 def testDoubleQuote_withUnsafeChars(self):
46 self.assertEquals('''"hello\\"; rm -rf /"''', 45 self.assertEquals('''"hello\\"; rm -rf /"''',
47 cmd_helper.DoubleQuote('hello"; rm -rf /')) 46 cmd_helper.DoubleQuote('hello"; rm -rf /'))
48 47
49 def testSingleQuote_doExpand(self): 48 def testSingleQuote_doExpand(self):
50 test_string = 'hello $TEST_VAR' 49 test_string = 'hello $TEST_VAR'
51 cmd = 'TEST_VAR=world; echo %s' % cmd_helper.DoubleQuote(test_string) 50 cmd = 'TEST_VAR=world; echo %s' % cmd_helper.DoubleQuote(test_string)
52 self.assertEquals('hello world', 51 self.assertEquals('hello world',
53 cmd_helper.GetCmdOutput(cmd, shell=True).rstrip()) 52 cmd_helper.GetCmdOutput(cmd, shell=True).rstrip())
53
54
55 class CmdHelperIterCmdOutputLinesTest(unittest.TestCase):
56 """Test IterCmdOutputLines with some calls to the unix 'seq' command."""
57
58 def testIterCmdOutputLines_success(self):
59 for num, line in enumerate(
60 cmd_helper.IterCmdOutputLines(['seq', '10']), 1):
61 self.assertEquals(num, int(line))
62
63 def testIterCmdOutputLines_exitStatusFail(self):
64 with self.assertRaises(subprocess.CalledProcessError):
65 for num, line in enumerate(
66 cmd_helper.IterCmdOutputLines('seq 10 && false', shell=True), 1):
67 self.assertEquals(num, int(line))
68 # after reading all the output we get an exit status of 1
69
70 def testIterCmdOutputLines_exitStatusIgnored(self):
71 for num, line in enumerate(
72 cmd_helper.IterCmdOutputLines('seq 10 && false', shell=True,
73 check_status=False), 1):
74 self.assertEquals(num, int(line))
75
76 def testIterCmdOutputLines_exitStatusSkipped(self):
77 for num, line in enumerate(
78 cmd_helper.IterCmdOutputLines('seq 10 && false', shell=True), 1):
79 self.assertEquals(num, int(line))
80 # no exception will be raised because we don't attempt to read past
81 # the end of the output and, thus, the status never gets checked
82 if num == 10:
83 break
OLDNEW
« no previous file with comments | « build/android/pylib/cmd_helper.py ('k') | build/android/pylib/constants.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698