1#!/usr/bin/python 2 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): 13 """Test autoserv_parser can parse command line correctly. 14 """ 15 16 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): 23 """Get the parser class. 24 """ 25 # 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): 31 """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'] 41 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() 49