def testTypeInfoStringObjects(self): """Test the type info objects behave as expected.""" a = type_info.String() self.assertRaises(type_info.TypeValueError, a.Validate, 1) self.assertRaises(type_info.TypeValueError, a.Validate, None) a.Validate("test") a.Validate(u"test") a.Validate(u"/test-Îñ铁网åţî[öñåļ(îžåţîờñ")
def testTypeDescriptorSet(self): type_infos = [ type_info.String(name="output", default="analysis/{p}/{u}-{t}"), type_info.String(description="Profile to use.", name="profile", default=""), type_info.String(description="A comma separated list of plugins.", name="plugins", default=""), ] info = type_info.TypeDescriptorSet( type_infos[0], type_infos[1], type_infos[2], ) new_info = type_info.TypeDescriptorSet(type_infos[0], ) updated_info = new_info + type_info.TypeDescriptorSet(type_infos[1], ) updated_info += type_info.TypeDescriptorSet(type_infos[2], ) self.assertEqual(info.descriptor_map, updated_info.descriptor_map) self.assertEqual(sorted(info.descriptors), sorted(updated_info.descriptors)) self.assertIn(type_infos[1], updated_info.descriptors) self.assertIn("plugins", updated_info) removed_info = updated_info.Remove("plugins") self.assertIn(type_infos[1], updated_info.descriptors) self.assertIn("plugins", updated_info) self.assertNotIn(type_infos[2], removed_info.descriptors) self.assertNotIn("plugins", removed_info)
def testStructDefinition(self): """Ensure that errors in struct definitions are raised.""" # A descriptor without a field number should raise. self.assertRaises( type_info.TypeValueError, rdf_structs.ProtoEmbedded, name="name") # Adding a duplicate field number should raise. self.assertRaises( type_info.TypeValueError, TestStruct.AddDescriptor, rdf_structs.ProtoUnsignedInteger(name="int", field_number=2)) # Adding a descriptor which is not a Proto* descriptor is not allowed for # Struct fields: self.assertRaises(type_info.TypeValueError, TestStruct.AddDescriptor, type_info.String(name="int"))