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

Side by Side Diff: server/base_utils_unittest.py

Issue 6246035: Merge remote branch 'cros/upstream' into master (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 months 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 __author__ = 'raphtee@google.com (Travis Miller)' 3 __author__ = 'raphtee@google.com (Travis Miller)'
4 4
5 import unittest 5 import unittest
6 import common 6 import common
7 from autotest_lib.server import utils 7 from autotest_lib.server import utils
8 8
9 9
10 class UtilsTest(unittest.TestCase): 10 class UtilsTest(unittest.TestCase):
11 11
12 def setUp(self): 12 def setUp(self):
13 # define out machines here 13 # define out machines here
14 self.machines = ['mach1', 'mach2', 'mach3', 'mach4', 'mach5', 14 self.machines = ['mach1', 'mach2', 'mach3', 'mach4', 'mach5',
15 'mach6', 'mach7'] 15 'mach6', 'mach7']
16 16
17 self.ntuples = [['mach1', 'mach2'], ['mach3', 'mach4'], 17 self.ntuples = [['mach1', 'mach2'], ['mach3', 'mach4'],
18 ['mach5', 'mach6']] 18 ['mach5', 'mach6']]
19 self.failures = [] 19 self.failures = []
20 self.failures.append(('mach7', "machine can not be tupled")) 20 self.failures.append(('mach7', "machine can not be tupled"))
21 21
22 22
23 def test_form_cell_mappings(self): 23 def test_form_cell_mappings(self):
24 (ntuples, failures) = utils.form_ntuples_from_machines(self.machines) 24 (ntuples, failures) = utils.form_ntuples_from_machines(self.machines)
25 self.assertEquals(self.ntuples, ntuples) 25 self.assertEquals(self.ntuples, ntuples)
26 self.assertEquals(self.failures, failures) 26 self.assertEquals(self.failures, failures)
27 27
28 28
29 # parse_machine() test cases
30 def test_parse_machine_good(self):
31 '''test that parse_machine() is outputting the correct data'''
32 gooddata = (('host', ('host', 'root', '', 22)),
33 ('host:21', ('host', 'root', '', 21)),
34 ('user@host', ('host', 'user', '', 22)),
35 ('user:pass@host', ('host', 'user', 'pass', 22)),
36 ('user:pass@host:1234', ('host', 'user', 'pass', 1234)),
37 )
38 for machine, result in gooddata:
39 self.assertEquals(utils.parse_machine(machine), result)
40
41
42 def test_parse_machine_override(self):
43 '''Test that parse_machine() defaults can be overridden'''
44 self.assertEquals(utils.parse_machine('host', 'bob', 'foo', 1234),
45 ('host', 'bob', 'foo', 1234))
46
47
48 def test_parse_machine_bad(self):
49 '''test that bad data passed to parse_machine() will raise an exception' ''
50 baddata = (('host:port', ValueError), # pass a non-integer string for port
51 ('host:22:33', ValueError), # pass two ports
52 (':22', ValueError), # neglect to pass a hostname #1
53 ('user@', ValueError), # neglect to pass a hostname #2
54 ('user@:22', ValueError), # neglect to pass a hostname #3
55 (':pass@host', ValueError), # neglect to pass a username
56 )
57 for machine, exception in baddata:
58 self.assertRaises(exception, utils.parse_machine, machine)
59
60
29 if __name__ == "__main__": 61 if __name__ == "__main__":
30 unittest.main() 62 unittest.main()
OLDNEW
« cli/job.py ('K') | « server/base_utils.py ('k') | server/control_segments/cleanup » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698