def test_serialize_roundtrip(self): # Use the global 'FLAGS' as the source, to ensure all the framework defined # flags will go through the round trip process. flags.DEFINE_string('testflag', 'testval', 'help', flag_values=FLAGS) flags.DEFINE_multi_enum('test_multi_enum_flag', ['x', 'y'], ['x', 'y', 'z'], 'Multi enum help.', flag_values=FLAGS) class Fruit(enum.Enum): APPLE = 1 ORANGE = 2 TOMATO = 3 flags.DEFINE_multi_enum_class('test_multi_enum_class_flag', ['APPLE', 'TOMATO'], Fruit, 'Fruit help.', flag_values=FLAGS) new_flag_values = flags.FlagValues() new_flag_values.append_flag_values(FLAGS) FLAGS.testflag = 'roundtrip_me' FLAGS.test_multi_enum_flag = ['y', 'z'] FLAGS.test_multi_enum_class_flag = [Fruit.ORANGE, Fruit.APPLE] argv = ['binary_name'] + FLAGS.flags_into_string().splitlines() self.assertNotEqual(new_flag_values['testflag'], FLAGS.testflag) self.assertNotEqual(new_flag_values['test_multi_enum_flag'], FLAGS.test_multi_enum_flag) self.assertNotEqual(new_flag_values['test_multi_enum_class_flag'], FLAGS.test_multi_enum_class_flag) new_flag_values(argv) self.assertEqual(new_flag_values.testflag, FLAGS.testflag) self.assertEqual(new_flag_values.test_multi_enum_flag, FLAGS.test_multi_enum_flag) self.assertEqual(new_flag_values.test_multi_enum_class_flag, FLAGS.test_multi_enum_class_flag) del FLAGS.testflag del FLAGS.test_multi_enum_flag del FLAGS.test_multi_enum_class_flag
def test_flag_help_in_xml_multi_enum_class_list_default(self): class Fruit(enum.Enum): ORANGE = 0 BANANA = 1 flags.DEFINE_multi_enum_class('fruit', ['ORANGE', 'BANANA'], Fruit, 'The fruit flag.', flag_values=self.fv) expected_output = ( '<flag>\n' ' <file>tool</file>\n' ' <name>fruit</name>\n' ' <meaning><orange|banana>: The fruit flag.;\n' ' repeat this option to specify a list of values</meaning>\n' ' <default>orange,banana</default>\n' ' <current>orange,banana</current>\n' ' <type>multi enum class</type>\n' ' <enum_value>ORANGE</enum_value>\n' ' <enum_value>BANANA</enum_value>\n' '</flag>\n') self._check_flag_help_in_xml('fruit', 'tool', expected_output)