Exemple #1
0
 def test_success(self):
     _defines.DEFINE_string('string_flag_1',
                            None,
                            'string flag 1',
                            flag_values=self.flag_values)
     _defines.DEFINE_string('string_flag_2',
                            None,
                            'string flag 2',
                            flag_values=self.flag_values)
     flag_names = ['string_flag_1', 'string_flag_2']
     _validators.mark_flags_as_required(flag_names,
                                        flag_values=self.flag_values)
     argv = ('./program', '--string_flag_1=value_1',
             '--string_flag_2=value_2')
     self.flag_values(argv)
     self.assertEqual('value_1', self.flag_values.string_flag_1)
     self.assertEqual('value_2', self.flag_values.string_flag_2)
Exemple #2
0
 def test_catch_none_as_default(self):
     _defines.DEFINE_string('string_flag_1',
                            None,
                            'string flag 1',
                            flag_values=self.flag_values)
     _defines.DEFINE_string('string_flag_2',
                            None,
                            'string flag 2',
                            flag_values=self.flag_values)
     _validators.mark_flags_as_required(['string_flag_1', 'string_flag_2'],
                                        flag_values=self.flag_values)
     argv = ('./program', '--string_flag_1=value_1')
     expected = (
         r'flag --string_flag_2=None: Flag --string_flag_2 must be specified\.'
     )
     self.assertRaisesRegexp(_exceptions.IllegalFlagValueError, expected,
                             self.flag_values, argv)
Exemple #3
0
 def test_catch_multiple_flags_as_none_at_program_start(self):
     _defines.DEFINE_float('float_flag_1',
                           None,
                           'string flag 1',
                           flag_values=self.flag_values)
     _defines.DEFINE_float('float_flag_2',
                           None,
                           'string flag 2',
                           flag_values=self.flag_values)
     _validators.mark_flags_as_required(['float_flag_1', 'float_flag_2'],
                                        flag_values=self.flag_values)
     argv = ('./program', '')
     expected = (
         'flag --float_flag_1=None: Flag --float_flag_1 must have a value '
         'other than None.\n'
         'flag --float_flag_2=None: Flag --float_flag_2 must have a value '
         'other than None.')
     with self.assertRaises(_exceptions.IllegalFlagValueError) as cm:
         self.flag_values(argv)
     self.assertEqual(expected, str(cm.exception))
Exemple #4
0
 def test_catch_setting_none_after_program_start(self):
     _defines.DEFINE_string('string_flag_1',
                            'value_1',
                            'string flag 1',
                            flag_values=self.flag_values)
     _defines.DEFINE_string('string_flag_2',
                            'value_2',
                            'string flag 2',
                            flag_values=self.flag_values)
     _validators.mark_flags_as_required(['string_flag_1', 'string_flag_2'],
                                        flag_values=self.flag_values)
     argv = ('./program', '--string_flag_1=value_1')
     self.flag_values(argv)
     self.assertEqual('value_1', self.flag_values.string_flag_1)
     expected = (
         'flag --string_flag_1=None: Flag --string_flag_1 must have a value '
         'other than None.')
     with self.assertRaises(_exceptions.IllegalFlagValueError) as cm:
         self.flag_values.string_flag_1 = None
     self.assertEqual(expected, str(cm.exception))
Exemple #5
0
 def test_catch_setting_none_after_program_start(self):
     _defines.DEFINE_string('string_flag_1',
                            'value_1',
                            'string flag 1',
                            flag_values=self.flag_values)
     _defines.DEFINE_string('string_flag_2',
                            'value_2',
                            'string flag 2',
                            flag_values=self.flag_values)
     _validators.mark_flags_as_required(['string_flag_1', 'string_flag_2'],
                                        flag_values=self.flag_values)
     argv = ('./program', '--string_flag_1=value_1')
     self.flag_values(argv)
     self.assertEqual('value_1', self.flag_values.string_flag_1)
     expected = (
         'flag --string_flag_1=None: Flag --string_flag_1 must be specified.'
     )
     try:
         self.flag_values.string_flag_1 = None
         raise AssertionError('Failed to detect non-set required flag.')
     except _exceptions.IllegalFlagValueError as e:
         self.assertEqual(expected, str(e))