comparison tests/unit.py @ 65:2a2e9aee5bc6

refactor completed and tests pass again
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 28 Mar 2012 08:37:01 -0700
parents f7dc5cf2540c
children 0804a706d6bf
comparison
equal deleted inserted replaced
64:a8013bd3126a 65:2a2e9aee5bc6
26 """test command line interface""" 26 """test command line interface"""
27 27
28 example = ExampleConfiguration() 28 example = ExampleConfiguration()
29 29
30 # parse command line arguments 30 # parse command line arguments
31 options, args = example.parse(['-a', 'ts', '--develop', '-e', '/home/jhammel/bin/firefox']) 31 options, args = example.parse_args(['-a', 'ts', '--develop', '-e', '/home/jhammel/bin/firefox'])
32 32
33 # ensure that the options appropriately get set 33 # ensure that the options appropriately get set
34 self.assertEqual(bool(args), False) # no arguments 34 self.assertEqual(bool(args), False) # no arguments
35 self.assertEqual(options.develop, True) 35 self.assertEqual(options.develop, True)
36 self.assertEqual(options.activeTests, ['ts']) 36 self.assertEqual(options.activeTests, ['ts'])
78 78
79 example = ExampleConfiguration() 79 example = ExampleConfiguration()
80 80
81 exception = None 81 exception = None
82 try: 82 try:
83 example.parse(args=[]) 83 example.parse_args(args=[])
84 except Exception, exception: 84 except Exception, exception:
85 pass 85 pass
86 self.assertTrue(isinstance(exception, configuration.MissingValueException)) 86 self.assertTrue(isinstance(exception, configuration.MissingValueException))
87 87
88 def test_required(self): 88 def test_required(self):
109 assert os.path.exists(json_file) 109 assert os.path.exists(json_file)
110 json_config = json.loads(file(json_file).read()) 110 json_config = json.loads(file(json_file).read())
111 111
112 # parse the json file 112 # parse the json file
113 example = ExampleConfiguration() 113 example = ExampleConfiguration()
114 example.parse([json_file]) 114 example.parse_args([json_file])
115 self.assertEqual(example.config, json_config) 115 self.assertEqual(example.config, json_config)
116 116
117 # parse the json file with overrides 117 # parse the json file with overrides
118 example = ExampleConfiguration() 118 example = ExampleConfiguration()
119 example.parse([json_file] + args1) 119 example.parse_args([json_file] + args1)
120 config = json_config.copy() 120 config = json_config.copy()
121 config['browser_path'] = '/opt/bin/firefox' 121 config['browser_path'] = '/opt/bin/firefox'
122 self.assertEqual(example.config, config) 122 self.assertEqual(example.config, config)
123 123
124 # it shouldn't matter in which order the arguments are 124 # it shouldn't matter in which order the arguments are
125 example = ExampleConfiguration() 125 example = ExampleConfiguration()
126 example.parse(args1 + [json_file]) 126 example.parse_args(args1 + [json_file])
127 self.assertEqual(example.config, config) 127 self.assertEqual(example.config, config)
128 128
129 # Now a tricky case: 129 # Now a tricky case:
130 # the default value for test_timeout is 1200: 130 # the default value for test_timeout is 1200:
131 example = ExampleConfiguration() 131 example = ExampleConfiguration()
132 self.assertEqual(example.options['test_timeout']['default'], 1200) 132 self.assertEqual(example.options['test_timeout']['default'], 1200)
133 # The value from base.json is 60: 133 # The value from base.json is 60:
134 self.assertEqual(json_config['test_timeout'], 60) 134 self.assertEqual(json_config['test_timeout'], 60)
135 self.assertEqual(config['test_timeout'], 60) 135 self.assertEqual(config['test_timeout'], 60)
136 # but we can override it back from the "command line" 136 # but we can override it back from the "command line"
137 example.parse(args1 + [json_file, '--test_timeout', '1200']) 137 example.parse_args(args1 + [json_file, '--test_timeout', '1200'])
138 config['test_timeout'] = 1200 138 config['test_timeout'] = 1200
139 self.assertEqual(example.config, config) 139 self.assertEqual(example.config, config)
140 140
141 if __name__ == '__main__': 141 if __name__ == '__main__':
142 unittest.main() 142 unittest.main()