Example #1
0
 def test_optional_flag(self):
     for flag in ['flag', 'fla_g', 'fla-g']:
         rv = re_parse_args.match('[--%s]' % flag)
         self.assertIsNotNone(rv)
         self.assertEquals(rv.groupdict()['key_name'], flag)
         self.assertEquals(rv.groupdict()['key'], '--%s' % flag)
         self.assertEquals(rv.groupdict()['lopt'], '[')
         self.assertEquals(rv.groupdict()['ropt'], ']')
         self.assertIsNone(rv.groupdict()['argument'])
         self.assertIsNone(rv.groupdict()['value'])
Example #2
0
 def test_optional_argument(self):
     for arg in ['argument', 'arg-ument', 'arg_ument']:
         rv = re_parse_args.match('[%s]' % arg)
         self.assertIsNotNone(rv)
         self.assertEquals(rv.groupdict()['argument'], arg)
         self.assertEquals(rv.groupdict()['lopt'], '[')
         self.assertEquals(rv.groupdict()['ropt'], ']')
         self.assertIsNone(rv.groupdict()['key'])
         self.assertIsNone(rv.groupdict()['key_name'])
         self.assertIsNone(rv.groupdict()['value'])
Example #3
0
 def test_optional_key_value(self):
     for k, v in [('key', 'value'), ('k-ey', 'value'),
                  ('k_ey', 'value'), ('key', 'val-ue'),
                  ('key', 'val_ue'), ('k-ey', 'val-ue'),
                  ('k_ey', 'val_ue')]:
         rv = re_parse_args.match('[--%s=%s]' % (k, v))
         self.assertIsNotNone(rv)
         self.assertEquals(rv.groupdict()['key_name'], k)
         self.assertEquals(rv.groupdict()['key'], '--%s' % k)
         self.assertEquals(rv.groupdict()['value'], v)
         self.assertEquals(rv.groupdict()['lopt'], '[')
         self.assertEquals(rv.groupdict()['ropt'], ']')
         self.assertIsNone(rv.groupdict()['argument'])