Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 1 | #!/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 Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 7 | import unittest |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 8 | import common |
| 9 | from autotest_lib.site_utils import test_that |
| 10 | |
Aviv Keshet | 30322f9 | 2013-07-18 13:21:52 -0700 | [diff] [blame] | 11 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 12 | class 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 Goodby | cbb5ba0 | 2015-08-11 11:26:53 -0700 | [diff] [blame] | 18 | 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 Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 29 | ['-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 Goodby | 079312e | 2015-08-05 12:43:04 -0700 | [diff] [blame] | 36 | self.assertEqual(remote_argv, |
| 37 | ['-b', 'some_board', '-i', 'some_image', '--args', |
| 38 | 'some_args', 'some_remote', 'test1', 'test2']) |
| 39 | |
Laurence Goodby | cbb5ba0 | 2015-08-11 11:26:53 -0700 | [diff] [blame] | 40 | def test_parse_arguments_internal_with_local_argument(self): |
| 41 | args, remote_argv = test_that._parse_arguments_internal( |
Laurence Goodby | 079312e | 2015-08-05 12:43:04 -0700 | [diff] [blame] | 42 | ['-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 Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 53 | |
Laurence Goodby | cbb5ba0 | 2015-08-11 11:26:53 -0700 | [diff] [blame] | 54 | 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 Prabhu | 68ee1c5 | 2017-07-05 10:21:18 -0700 | [diff] [blame] | 65 | 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 Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 78 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 79 | |
| 80 | if __name__ == '__main__': |
| 81 | unittest.main() |