blob: 5cbdf8e67ec7051260df34085845246bbac53648 [file] [log] [blame]
Mike Frysingerd03e6b52019-08-03 12:49:01 -04001#!/usr/bin/python2
mbligh374f3412009-05-13 21:29:45 +00002
3"""Tests for autoserv_parser."""
4
5import sys
6import unittest
7
8import common
9from autotest_lib.server import autoserv_parser
10
11
12class autoserv_parser_test(unittest.TestCase):
Dan Shi888cfca2015-07-31 15:49:00 -070013 """Test autoserv_parser can parse command line correctly.
14 """
15
mbligh374f3412009-05-13 21:29:45 +000016 def setUp(self):
17 self.orig_sys_argv = sys.argv
18
19 def tearDown(self):
20 sys.argv = self.orig_sys_argv
21
22 def _get_parser(self):
Dan Shi888cfca2015-07-31 15:49:00 -070023 """Get the parser class.
24 """
mbligh374f3412009-05-13 21:29:45 +000025 # We resort to this vile hack because autoserv_parser is bad
26 # enough to instantiate itself and replace its own class definition
27 # with its instance at module import time. Disgusting.
28 return autoserv_parser.autoserv_parser.__class__()
29
30 def test_control_file_args(self):
Dan Shi888cfca2015-07-31 15:49:00 -070031 """Test the parser can parse args and unknown args correctly.
32 """
33 sys.argv = ['autoserv', '--args', '-y -z foo --hello', 'controlfile']
34 parser = self._get_parser()
35 parser.parse_args()
36 self.assertEqual(['controlfile', '-y', '-z', 'foo', '--hello'],
37 parser.args)
38
39 sys.argv = ['autoserv', '--args', '-y -z foo --hello', '--unknown_arg',
40 'unknown_arg_val', 'controlfile']
mbligh374f3412009-05-13 21:29:45 +000041 parser = self._get_parser()
42 parser.parse_args()
43 self.assertEqual(['controlfile', '-y', '-z', 'foo', '--hello'],
44 parser.args)
45
46
47if __name__ == '__main__':
48 unittest.main()