blob: 050bf0eae9af5077f687d730843973f7e491cb19 [file] [log] [blame]
Aviv Keshetd4a04302013-04-30 15:48:30 -07001#!/usr/bin/python
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5# pylint: disable-msg=C0111
6
Simran Basi14622bb2015-11-25 13:23:40 -08007import unittest
Aviv Keshetd4a04302013-04-30 15:48:30 -07008import common
9from autotest_lib.site_utils import test_that
10
Aviv Keshet30322f92013-07-18 13:21:52 -070011
Aviv Keshetd4a04302013-04-30 15:48:30 -070012class TestThatUnittests(unittest.TestCase):
13 def test_validate_arguments(self):
14 # Deferred until validate_arguments allows for lab runs.
15 pass
16
17 def test_parse_arguments(self):
Laurence Goodbycbb5ba02015-08-11 11:26:53 -070018 args = test_that.parse_arguments(
19 ['-b', 'some_board', '-i', 'some_image', '--args', 'some_args',
20 'some_remote', 'test1', 'test2'])
21 self.assertEqual('some_board', args.board)
22 self.assertEqual('some_image', args.build)
23 self.assertEqual('some_args', args.args)
24 self.assertEqual('some_remote', args.remote)
25 self.assertEqual(['test1', 'test2'], args.tests)
26
27 def test_parse_arguments_internal(self):
28 args, remote_argv = test_that._parse_arguments_internal(
Aviv Keshetd4a04302013-04-30 15:48:30 -070029 ['-b', 'some_board', '-i', 'some_image', '--args', 'some_args',
30 'some_remote', 'test1', 'test2'])
31 self.assertEqual('some_board', args.board)
32 self.assertEqual('some_image', args.build)
33 self.assertEqual('some_args', args.args)
34 self.assertEqual('some_remote', args.remote)
35 self.assertEqual(['test1', 'test2'], args.tests)
Laurence Goodby079312e2015-08-05 12:43:04 -070036 self.assertEqual(remote_argv,
37 ['-b', 'some_board', '-i', 'some_image', '--args',
38 'some_args', 'some_remote', 'test1', 'test2'])
39
Laurence Goodbycbb5ba02015-08-11 11:26:53 -070040 def test_parse_arguments_internal_with_local_argument(self):
41 args, remote_argv = test_that._parse_arguments_internal(
Laurence Goodby079312e2015-08-05 12:43:04 -070042 ['-b', 'some_board', '-i', 'some_image', '-w', 'server:port',
43 '--args', 'some_args', 'some_remote', 'test1', 'test2'])
44 self.assertEqual('server:port', args.web)
45 self.assertEqual('some_board', args.board)
46 self.assertEqual('some_image', args.build)
47 self.assertEqual('some_args', args.args)
48 self.assertEqual('some_remote', args.remote)
49 self.assertEqual(['test1', 'test2'], args.tests)
50 self.assertEqual(remote_argv,
51 ['-b', 'some_board', '-i', 'some_image', '--args',
52 'some_args', 'some_remote', 'test1', 'test2'])
Aviv Keshetd4a04302013-04-30 15:48:30 -070053
Laurence Goodbycbb5ba02015-08-11 11:26:53 -070054 def test_parse_arguments_with_local_argument(self):
55 args = test_that.parse_arguments(
56 ['-b', 'some_board', '-i', 'some_image', '-w', 'server:port',
57 '--args', 'some_args', 'some_remote', 'test1', 'test2'])
58 self.assertEqual('server:port', args.web)
59 self.assertEqual('some_board', args.board)
60 self.assertEqual('some_image', args.build)
61 self.assertEqual('some_args', args.args)
62 self.assertEqual('some_remote', args.remote)
63 self.assertEqual(['test1', 'test2'], args.tests)
64
Prathmesh Prabhu68ee1c52017-07-05 10:21:18 -070065 def test_parse_arguments_lab_run_requires_build(self):
66 """Running against :lab: requires certain extra arguments."""
67 args = test_that.parse_arguments(['-b', 'some_board', ':lab:', 'test1'])
68 with self.assertRaises(ValueError):
69 test_that.validate_arguments(args)
70
71 def test_parse_arguments_lab_run_disallows_suite_args(self):
72 """Running against :lab: requires certain extra arguments."""
73 args = test_that.parse_arguments([
74 '-b', 'some_board', '-i', 'some_image', '--args', 'some_args',
75 ':lab:', 'test1'])
76 with self.assertRaises(ValueError):
77 test_that.validate_arguments(args)
Aviv Keshetd4a04302013-04-30 15:48:30 -070078
Aviv Keshetd4a04302013-04-30 15:48:30 -070079
80if __name__ == '__main__':
81 unittest.main()