• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7import unittest
8import common
9from autotest_lib.site_utils import test_that
10
11
12class 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):
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(
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)
36        self.assertEqual(remote_argv,
37                         ['-b', 'some_board', '-i', 'some_image', '--args',
38                          'some_args', 'some_remote', 'test1', 'test2'])
39
40    def test_parse_arguments_internal_with_local_argument(self):
41        args, remote_argv = test_that._parse_arguments_internal(
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'])
53
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
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)
78
79
80if __name__ == '__main__':
81    unittest.main()
82