def test_group_dict(self): options = OptionParser() options.define('a', default=1) options.define('b', group='b_group', default=2) frame = sys._getframe(0) this_file = frame.f_code.co_filename self.assertEqual(set(['b_group', '', this_file]), options.groups()) b_group_dict = options.group_dict('b_group') self.assertEqual({'b': 2}, b_group_dict) self.assertEqual({}, options.group_dict('nonexistent'))
def test_group_dict(self): options = OptionParser() options.define("a", default=1) options.define("b", group="b_group", default=2) frame = sys._getframe(0) this_file = frame.f_code.co_filename self.assertEqual(set(["b_group", "", this_file]), options.groups()) b_group_dict = options.group_dict("b_group") self.assertEqual({"b": 2}, b_group_dict) self.assertEqual({}, options.group_dict("nonexistent"))
def test_dash_underscore_introspection(self): # Original names are preserved in introspection APIs. options = OptionParser() options.define('with-dash', group='g') options.define('with_underscore', group='g') all_options = ['help', 'with-dash', 'with_underscore'] self.assertEqual(sorted(options), all_options) self.assertEqual(sorted(k for (k, v) in options.items()), all_options) self.assertEqual(sorted(options.as_dict().keys()), all_options) self.assertEqual(sorted(options.group_dict('g')), ['with-dash', 'with_underscore']) # --help shows CLI-style names with dashes. buf = StringIO() options.print_help(buf) self.assertIn('--with-dash', buf.getvalue()) self.assertIn('--with-underscore', buf.getvalue())
def test_dash_underscore_introspection(self): # Original names are preserved in introspection APIs. options = OptionParser() options.define("with-dash", group="g") options.define("with_underscore", group="g") all_options = ["help", "with-dash", "with_underscore"] self.assertEqual(sorted(options), all_options) self.assertEqual(sorted(k for (k, v) in options.items()), all_options) self.assertEqual(sorted(options.as_dict().keys()), all_options) self.assertEqual(sorted(options.group_dict("g")), ["with-dash", "with_underscore"]) # --help shows CLI-style names with dashes. buf = StringIO() options.print_help(buf) self.assertIn("--with-dash", buf.getvalue()) self.assertIn("--with-underscore", buf.getvalue())
def test_dash_underscore_introspection(self): # Original names are preserved in introspection APIs. options = OptionParser() options.define("with-dash", group="g") options.define("with_underscore", group="g") all_options = ["help", "with-dash", "with_underscore"] self.assertEqual(sorted(options), all_options) self.assertEqual(sorted(k for (k, v) in options.items()), all_options) self.assertEqual(sorted(options.as_dict().keys()), all_options) self.assertEqual( sorted(options.group_dict("g")), ["with-dash", "with_underscore"] ) # --help shows CLI-style names with dashes. buf = StringIO() options.print_help(buf) self.assertIn("--with-dash", buf.getvalue()) self.assertIn("--with-underscore", buf.getvalue())