comparison tests/unit.py @ 89:0804a706d6bf

handle CLI errors with optparse
author Jeff Hammel <jhammel@mozilla.com>
date Sat, 28 Apr 2012 15:29:57 -0700
parents 2a2e9aee5bc6
children c530f6265deb
comparison
equal deleted inserted replaced
88:36cf1d9bf40b 89:0804a706d6bf
76 def test_missing_values(self): 76 def test_missing_values(self):
77 """ensure that Configuration raises a missing value exception""" 77 """ensure that Configuration raises a missing value exception"""
78 78
79 example = ExampleConfiguration() 79 example = ExampleConfiguration()
80 80
81 exception = None 81 # monkey-patch the error method from optparse.OptionParser
82 try: 82 error_msg = []
83 example.parse_args(args=[]) 83 def error(msg):
84 except Exception, exception: 84 error_msg.append(msg)
85 pass 85 example.error = error
86 self.assertTrue(isinstance(exception, configuration.MissingValueException)) 86
87 # trigger it
88 example.parse_args(args=[])
89 self.assertEqual(error_msg, ['Parameter browser_path is required but not present'])
87 90
88 def test_required(self): 91 def test_required(self):
89 """ensure you have to have required values""" 92 """ensure you have to have required values"""
90 93
91 example = ExampleConfiguration() 94 example = ExampleConfiguration()