/
options_unittest.py
32 lines (25 loc) · 1019 Bytes
/
options_unittest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import unittest
import options
class OptionsTestCase(unittest.TestCase):
def testExtract(self):
args = ['--A', 'foo', '--devtools_port', '2000', '--B=20',
'--no_sandbox', '--C', '30', 'baz']
opts = options.Options()
opts.ExtractArgs(args)
self.assertEqual(['--A', 'foo', '--B=20', '--C', '30', 'baz'], args)
self.assertEqual(2000, opts.devtools_port)
self.assertTrue(opts.no_sandbox)
def testParent(self):
opts = options.Options()
parser = argparse.ArgumentParser(parents=[opts.GetParentParser()])
parser.add_argument('--foo', type=int)
parsed_args = parser.parse_args(['--foo=4', '--devtools_port', '2000'])
self.assertEqual(4, parsed_args.foo)
opts.SetParsedArgs(parsed_args)
self.assertEqual(2000, opts.devtools_port)
if __name__ == '__main__':
unittest.main()