Merge pull request #471 from haberman/python-pool

Implemented most methods on DescriptorPool
pull/13171/head
Joshua Haberman 3 years ago committed by GitHub
commit 10597019ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 41
      python/descriptor.c
  2. 281
      python/descriptor_pool.c
  3. 9
      python/descriptor_pool.h
  4. 4
      python/minimal_test.py
  5. 3
      python/pb_unit_tests/descriptor_database_test_wrapper.py
  6. 64
      python/pb_unit_tests/descriptor_pool_test_wrapper.py
  7. 52
      python/pb_unit_tests/descriptor_test_wrapper.py
  8. 4
      python/pb_unit_tests/generator_test_wrapper.py
  9. 5
      python/pb_unit_tests/json_format_test_wrapper.py
  10. 2
      python/pb_unit_tests/keywords_test_wrapper.py
  11. 14
      python/pb_unit_tests/message_factory_test_wrapper.py
  12. 10
      python/pb_unit_tests/message_test_wrapper.py
  13. 3
      python/pb_unit_tests/proto_builder_test_wrapper.py
  14. 3
      python/pb_unit_tests/reflection_test_wrapper.py
  15. 21
      python/pb_unit_tests/text_format_test_wrapper.py
  16. 6
      python/pb_unit_tests/unknown_fields_test_wrapper.py
  17. 12
      upb/util/def_to_proto.c

@ -30,6 +30,7 @@
#include "python/convert.h"
#include "python/descriptor_containers.h"
#include "python/descriptor_pool.h"
#include "python/message.h"
#include "python/protobuf.h"
#include "upb/def.h"
#include "upb/util/def_to_proto.h"
@ -144,13 +145,9 @@ static PyObject* PyUpb_DescriptorBase_GetOptions(PyUpb_DescriptorBase* self,
typedef void* PyUpb_ToProto_Func(const void* def, upb_arena* arena);
static PyObject* PyUpb_DescriptorBase_CopyToProto(PyObject* _self,
PyUpb_ToProto_Func* func,
const upb_msglayout* layout,
PyObject* py_proto) {
static PyObject* PyUpb_DescriptorBase_GetSerializedProto(
PyObject* _self, PyUpb_ToProto_Func* func, const upb_msglayout* layout) {
PyUpb_DescriptorBase* self = (void*)_self;
PyObject* ret = NULL;
PyObject* str = NULL;
upb_arena* arena = upb_arena_new();
if (!arena) PYUPB_RETURN_OOM;
upb_msg* proto = func(self->def, arena);
@ -158,20 +155,24 @@ static PyObject* PyUpb_DescriptorBase_CopyToProto(PyObject* _self,
size_t size;
char* pb = upb_encode(proto, layout, arena, &size);
if (!pb) goto oom;
str = PyBytes_FromStringAndSize(pb, size);
if (!str) goto oom;
// Disabled until python/message.c is reviewed and checked in.
// PyObject *ret = PyUpb_CMessage_MergeFromString(py_proto, str);
PyErr_Format(PyExc_NotImplementedError, "Not yet implemented");
done:
Py_XDECREF(str);
PyObject* str = PyBytes_FromStringAndSize(pb, size);
upb_arena_free(arena);
return ret;
return str;
oom:
upb_arena_free(arena);
PyErr_SetNone(PyExc_MemoryError);
goto done;
return NULL;
}
static PyObject* PyUpb_DescriptorBase_CopyToProto(PyObject* _self,
PyUpb_ToProto_Func* func,
const upb_msglayout* layout,
PyObject* py_proto) {
PyObject* serialized =
PyUpb_DescriptorBase_GetSerializedProto(_self, func, layout);
if (!serialized) return NULL;
return PyUpb_CMessage_MergeFromString(py_proto, serialized);
}
static void PyUpb_DescriptorBase_Dealloc(PyUpb_DescriptorBase* base) {
@ -1065,6 +1066,13 @@ static PyObject* PyUpb_FileDescriptor_GetPackage(PyObject* _self,
return PyUnicode_FromString(upb_filedef_package(self->def));
}
static PyObject* PyUpb_FileDescriptor_GetSerializedPb(PyObject* self,
void* closure) {
return PyUpb_DescriptorBase_GetSerializedProto(
self, (PyUpb_ToProto_Func*)&upb_FileDef_ToProto,
&google_protobuf_FileDescriptorProto_msginit);
}
static PyObject* PyUpb_FileDescriptor_GetMessageTypesByName(PyObject* _self,
void* closure) {
static PyUpb_ByNameMap_Funcs funcs = {
@ -1180,6 +1188,7 @@ static PyGetSetDef PyUpb_FileDescriptor_Getters[] = {
{"pool", PyUpb_FileDescriptor_GetPool, NULL, "pool"},
{"name", (getter)PyUpb_FileDescriptor_GetName, NULL, "name"},
{"package", PyUpb_FileDescriptor_GetPackage, NULL, "package"},
{"serialized_pb", PyUpb_FileDescriptor_GetSerializedPb},
{"message_types_by_name", PyUpb_FileDescriptor_GetMessageTypesByName, NULL,
"Messages by name"},
{"enum_types_by_name", PyUpb_FileDescriptor_GetEnumTypesByName, NULL,

@ -28,6 +28,7 @@
#include "python/descriptor_pool.h"
#include "python/descriptor.h"
#include "python/message.h"
#include "python/protobuf.h"
#include "upb/def.h"
@ -38,7 +39,7 @@
typedef struct {
PyObject_HEAD
upb_symtab* symtab;
PyObject* db;
PyObject* db; // The DescriptorDatabase underlying this pool. May be NULL.
} PyUpb_DescriptorPool;
PyObject* PyUpb_DescriptorPool_GetDefaultPool() {
@ -46,9 +47,8 @@ PyObject* PyUpb_DescriptorPool_GetDefaultPool() {
return s->default_pool;
}
static PyObject* PyUpb_DescriptorPool_DoCreateWithCache(PyTypeObject* type,
PyObject* db,
PyUpb_WeakMap *obj_cache) {
static PyObject* PyUpb_DescriptorPool_DoCreateWithCache(
PyTypeObject* type, PyObject* db, PyUpb_WeakMap* obj_cache) {
PyUpb_DescriptorPool* pool = (void*)PyType_GenericAlloc(type, 0);
pool->symtab = upb_symtab_new();
pool->db = db;
@ -85,8 +85,8 @@ PyObject* PyUpb_DescriptorPool_Get(const upb_symtab* symtab) {
}
static void PyUpb_DescriptorPool_Dealloc(PyUpb_DescriptorPool* self) {
upb_symtab_free(self->symtab);
PyUpb_DescriptorPool_Clear(self);
upb_symtab_free(self->symtab);
PyUpb_ObjCache_Delete(self->symtab);
PyUpb_Dealloc(self);
}
@ -106,6 +106,7 @@ static PyObject* PyUpb_DescriptorPool_New(PyTypeObject* type, PyObject* args,
return NULL;
}
if (db == Py_None) db = NULL;
return PyUpb_DescriptorPool_DoCreate(type, db);
}
@ -163,6 +164,40 @@ done:
return result;
}
static PyObject* PyUpb_DescriptorPool_Add(PyObject* _self,
PyObject* file_desc) {
PyObject* subargs = PyTuple_New(0);
// TODO: check file_desc type more.
PyObject* serialized =
PyUpb_CMessage_SerializeToString(file_desc, subargs, NULL);
Py_DECREF(subargs);
if (!serialized) return NULL;
PyObject* ret = PyUpb_DescriptorPool_AddSerializedFile(_self, serialized);
Py_DECREF(serialized);
return ret;
}
/*
* PyUpb_DescriptorPool_FindFileByName()
*
* Implements:
* DescriptorPool.FindFileByName(self, name)
*/
static PyObject* PyUpb_DescriptorPool_FindFileByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
const upb_filedef* file = upb_symtab_lookupfile(self->symtab, name);
if (file == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find file %.200s", name);
}
return PyUpb_FileDescriptor_Get(file);
}
/*
* PyUpb_DescriptorPool_FindExtensionByName()
*
@ -184,40 +219,214 @@ static PyObject* PyUpb_DescriptorPool_FindExtensionByName(PyObject* _self,
return PyUpb_FieldDescriptor_Get(field);
}
/*
* PyUpb_DescriptorPool_FindMessageTypeByName()
*
* Implements:
* DescriptorPool.FindMessageTypeByName(self, name)
*/
static PyObject* PyUpb_DescriptorPool_FindMessageTypeByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
const upb_msgdef* m = upb_symtab_lookupmsg(self->symtab, name);
if (m == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name);
}
return PyUpb_Descriptor_Get(m);
}
// Splits a dotted symbol like foo.bar.baz on the last dot. Returns the portion
// after the last dot (baz) and updates `*parent_size` to the length of the
// parent (foo.bar). Returns NULL if no dots were present.
static const char* PyUpb_DescriptorPool_SplitSymbolName(const char* sym,
size_t* parent_size) {
const char* last_dot = strrchr(sym, '.');
if (!last_dot) return NULL;
*parent_size = last_dot - sym;
return last_dot + 1;
}
/*
* PyUpb_DescriptorPool_FindFieldByName()
*
* Implements:
* DescriptorPool.FindFieldByName(self, name)
*/
static PyObject* PyUpb_DescriptorPool_FindFieldByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
// First lookup as extension.
const upb_fielddef* f = upb_symtab_lookupext(self->symtab, name);
if (!f) {
// Otherwise look for a normal field.
size_t parent_size;
const char* child =
PyUpb_DescriptorPool_SplitSymbolName(name, &parent_size);
if (child) {
const upb_msgdef* parent =
upb_symtab_lookupmsg2(self->symtab, name, parent_size);
if (parent) {
f = upb_msgdef_ntofz(parent, child);
}
}
}
if (!f) {
return PyErr_Format(PyExc_KeyError, "Couldn't find message %.200s", name);
}
return PyUpb_FieldDescriptor_Get(f);
}
/*
* PyUpb_DescriptorPool_FindEnumTypeByName()
*
* Implements:
* DescriptorPool.FindEnumTypeByName(self, name)
*/
static PyObject* PyUpb_DescriptorPool_FindEnumTypeByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
const upb_enumdef* e = upb_symtab_lookupenum(self->symtab, name);
if (e == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
}
return PyUpb_EnumDescriptor_Get(e);
}
/*
* PyUpb_DescriptorPool_FindOneofByName()
*
* Implements:
* DescriptorPool.FindOneofByName(self, name)
*/
static PyObject* PyUpb_DescriptorPool_FindOneofByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
size_t parent_size;
const char* child = PyUpb_DescriptorPool_SplitSymbolName(name, &parent_size);
if (child) {
const upb_msgdef* parent =
upb_symtab_lookupmsg2(self->symtab, name, parent_size);
if (parent) {
const upb_oneofdef* o = upb_msgdef_ntooz(parent, child);
return PyUpb_OneofDescriptor_Get(o);
}
}
return PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
}
static PyObject* PyUpb_DescriptorPool_FindServiceByName(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
const upb_servicedef* s = upb_symtab_lookupservice(self->symtab, name);
if (s == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find enum %.200s", name);
}
return PyUpb_ServiceDescriptor_Get(s);
}
static PyObject* PyUpb_DescriptorPool_FindFileContainingSymbol(PyObject* _self,
PyObject* arg) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const char* name = PyUpb_GetStrData(arg);
if (!name) return NULL;
const upb_filedef* f = upb_symtab_lookupfileforsym(self->symtab, name);
if (f == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find symbol %.200s", name);
}
return PyUpb_FileDescriptor_Get(f);
}
static PyObject* PyUpb_DescriptorPool_FindExtensionByNumber(PyObject* _self,
PyObject* args) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
PyObject* message_descriptor;
int number;
if (!PyArg_ParseTuple(args, "Oi", &message_descriptor, &number)) {
return NULL;
}
const upb_fielddef* f = upb_symtab_lookupextbynum(
self->symtab, PyUpb_Descriptor_GetDef(message_descriptor), number);
if (f == NULL) {
return PyErr_Format(PyExc_KeyError, "Couldn't find Extension %d", number);
}
return PyUpb_FieldDescriptor_Get(f);
}
static PyObject* PyUpb_DescriptorPool_FindAllExtensions(PyObject* _self,
PyObject* msg_desc) {
PyUpb_DescriptorPool* self = (PyUpb_DescriptorPool*)_self;
const upb_msgdef* m = PyUpb_Descriptor_GetDef(msg_desc);
size_t n;
const upb_fielddef** ext = upb_symtab_getallexts(self->symtab, m, &n);
PyObject* ret = PyList_New(n);
for (size_t i = 0; i < n; i++) {
PyObject* field = PyUpb_FieldDescriptor_Get(ext[i]);
if (!field) return NULL;
PyList_SetItem(ret, i, field);
}
return ret;
}
static PyMethodDef PyUpb_DescriptorPool_Methods[] = {
/*
TODO: implement remaining methods.
{ "Add", Add, METH_O,
"Adds the FileDescriptorProto and its types to this pool." },
*/
{"Add", PyUpb_DescriptorPool_Add, METH_O,
"Adds the FileDescriptorProto and its types to this pool."},
{"AddSerializedFile", PyUpb_DescriptorPool_AddSerializedFile, METH_O,
"Adds a serialized FileDescriptorProto to this pool."},
/*
{ "FindFileByName", FindFileByName, METH_O,
"Searches for a file descriptor by its .proto name." },
{ "FindMessageTypeByName", FindMessageByName, METH_O,
"Searches for a message descriptor by full name." },
{ "FindFieldByName", FindFieldByNameMethod, METH_O,
"Searches for a field descriptor by full name." },
*/
{"FindFileByName", PyUpb_DescriptorPool_FindFileByName, METH_O,
"Searches for a file descriptor by its .proto name."},
{"FindMessageTypeByName", PyUpb_DescriptorPool_FindMessageTypeByName,
METH_O, "Searches for a message descriptor by full name."},
{"FindFieldByName", PyUpb_DescriptorPool_FindFieldByName, METH_O,
"Searches for a field descriptor by full name."},
{"FindExtensionByName", PyUpb_DescriptorPool_FindExtensionByName, METH_O,
"Searches for extension descriptor by full name."},
/*
{ "FindEnumTypeByName", FindEnumTypeByNameMethod, METH_O,
"Searches for enum type descriptor by full name." },
{ "FindOneofByName", FindOneofByNameMethod, METH_O,
"Searches for oneof descriptor by full name." },
{ "FindServiceByName", FindServiceByName, METH_O,
"Searches for service descriptor by full name." },
{ "FindMethodByName", FindMethodByName, METH_O,
"Searches for method descriptor by full name." },
{ "FindFileContainingSymbol", FindFileContainingSymbol, METH_O,
"Gets the FileDescriptor containing the specified symbol." },
{ "FindExtensionByNumber", FindExtensionByNumber, METH_VARARGS,
"Gets the extension descriptor for the given number." },
{ "FindAllExtensions", FindAllExtensions, METH_O,
"Gets all known extensions of the given message descriptor." },
*/
{"FindEnumTypeByName", PyUpb_DescriptorPool_FindEnumTypeByName, METH_O,
"Searches for enum type descriptor by full name."},
{"FindOneofByName", PyUpb_DescriptorPool_FindOneofByName, METH_O,
"Searches for oneof descriptor by full name."},
{"FindServiceByName", PyUpb_DescriptorPool_FindServiceByName, METH_O,
"Searches for service descriptor by full name."},
//{ "Find, PyUpb_DescriptorPool_Find, METH_O,
// "Searches for method descriptor by full name." },
{"FindFileContainingSymbol", PyUpb_DescriptorPool_FindFileContainingSymbol,
METH_O, "Gets the FileDescriptor containing the specified symbol."},
{"FindExtensionByNumber", PyUpb_DescriptorPool_FindExtensionByNumber,
METH_VARARGS, "Gets the extension descriptor for the given number."},
{"FindAllExtensions", PyUpb_DescriptorPool_FindAllExtensions, METH_O,
"Gets all known extensions of the given message descriptor."},
{NULL}};
static PyType_Slot PyUpb_DescriptorPool_Slots[] = {
@ -241,9 +450,9 @@ static PyType_Spec PyUpb_DescriptorPool_Spec = {
// -----------------------------------------------------------------------------
bool PyUpb_InitDescriptorPool(PyObject* m) {
PyUpb_ModuleState *state = PyUpb_ModuleState_GetFromModule(m);
PyUpb_ModuleState* state = PyUpb_ModuleState_GetFromModule(m);
PyTypeObject* descriptor_pool_type =
AddObject(m, "DescriptorPool", &PyUpb_DescriptorPool_Spec);
PyUpb_AddClass(m, &PyUpb_DescriptorPool_Spec);
if (!descriptor_pool_type) return false;

@ -32,12 +32,17 @@
#include "protobuf.h"
PyObject* PyUpb_DescriptorPool_GetSerializedPb(PyObject* _self,
const char* filename);
// Returns a Python wrapper object for the given symtab. The symtab must have
// been created from a Python DescriptorPool originally.
PyObject* PyUpb_DescriptorPool_Get(const upb_symtab* symtab);
// Given a Python DescriptorPool, returns the underlying symtab.
upb_symtab* PyUpb_DescriptorPool_GetSymtab(PyObject* pool);
// Returns the default DescriptorPool (a global singleton).
PyObject* PyUpb_DescriptorPool_GetDefaultPool(void);
// Module-level init.
bool PyUpb_InitDescriptorPool(PyObject* m);
#endif // PYUPB_DESCRIPTOR_POOL_H__

@ -31,6 +31,10 @@ import unittest
from google.protobuf.pyext import _message
from google.protobuf.internal import api_implementation
from google.protobuf import unittest_pb2
from google.protobuf import descriptor_pool
from google.protobuf.internal import factory_test1_pb2
from google.protobuf.internal import factory_test2_pb2
from google.protobuf import descriptor_pb2
class TestMessageExtension(unittest.TestCase):

@ -26,8 +26,5 @@
from google.protobuf.internal import descriptor_database_test
import unittest
descriptor_database_test.DescriptorDatabaseTest.testAdd.__unittest_expecting_failure__ = True
descriptor_database_test.DescriptorDatabaseTest.testConflictRegister.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=descriptor_database_test, verbosity=2)

@ -25,49 +25,47 @@
from google.protobuf.internal import descriptor_pool_test
import unittest
import copy
print(unittest)
descriptor_pool_test.AddDescriptorTest.testAddTypeError.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testCustomDescriptorPool.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testEmptyDescriptorPool.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testEnum.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testFile.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testFileDescriptorOptionsWithCustomDescriptorPool.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testMessage.__unittest_expecting_failure__ = True
descriptor_pool_test.AddDescriptorTest.testService.__unittest_expecting_failure__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFieldByName.__unittest_expecting_failure__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindMessageTypeByName.__unittest_expecting_failure__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindService.__unittest_expecting_failure__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindTypeErrors.__unittest_expecting_failure__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testUserDefinedDB.__unittest_expecting_failure__ = True
descriptor_pool_test.SecondaryDescriptorFromDescriptorDB.testErrorCollector.__unittest_expecting_failure__ = True
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUp():
#
# AttributeError: 'google.protobuf.pyext._message.FileDescriptor' object has no attribute 'serialized_pb'
#
# TODO: change to __unittest_expecting_failure__ when serialized_pb is available.
descriptor_pool_test.CreateDescriptorPoolTest.testAddSerializedFile.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testComplexNesting.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testConflictRegister.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testDefaultValueForCustomMessages.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testEnumDefaultValue.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testExtensionsAreNotFields.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindAllExtensions.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindEnumTypeByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindEnumTypeByNameFailure.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindExtensionByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindExtensionByNumber.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFieldByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFileByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFileByNameFailure.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFileContainingSymbol.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindFileContainingSymbolFailure.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindMessageTypeByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindMessageTypeByNameFailure.__unittest_skip__ = True
descriptor_pool_test.DefaultDescriptorPoolTest.testFindMethods.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindOneofByName.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindService.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testFindTypeErrors.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testUserDefinedDB.__unittest_skip__ = True
descriptor_pool_test.CreateDescriptorPoolTest.testAddFileDescriptor.__unittest_skip__ = True
descriptor_pool_test.SecondaryDescriptorFromDescriptorDB.testErrorCollector.__unittest_skip__ = True
# Some tests are defined in a base class and inherited by multiple sub-classes.
# If only some of the subclasses fail, we need to duplicate the test method
# before marking it, otherwise the mark will affect all subclasses.
def wrap(cls, method):
existing = getattr(cls, method)
setattr(cls, method, lambda self: existing(self))
getattr(cls, method).__unittest_expecting_failure__ = True
wrap(descriptor_pool_test.CreateDescriptorPoolTest, "testAddFileDescriptor")
wrap(descriptor_pool_test.CreateDescriptorPoolTest, "testAddSerializedFile")
wrap(descriptor_pool_test.CreateDescriptorPoolTest, "testComplexNesting")
wrap(descriptor_pool_test.CreateDescriptorPoolTest, "testExtensionsAreNotFields")
wrap(descriptor_pool_test.DefaultDescriptorPoolTest, "testAddFileDescriptor")
wrap(descriptor_pool_test.DefaultDescriptorPoolTest, "testAddSerializedFile")
wrap(descriptor_pool_test.DefaultDescriptorPoolTest, "testComplexNesting")
wrap(descriptor_pool_test.DefaultDescriptorPoolTest, "testEnumDefaultValue")
wrap(descriptor_pool_test.DefaultDescriptorPoolTest, "testExtensionsAreNotFields")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindAllExtensions")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindEnumTypeByName")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindExtensionByName")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindExtensionByNumber")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindFileByName")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindFileContainingSymbol")
wrap(descriptor_pool_test.SecondaryDescriptorFromDescriptorDB, "testFindOneofByName")
if __name__ == '__main__':
unittest.main(module=descriptor_pool_test, verbosity=2)

@ -40,46 +40,30 @@ descriptor_test.DescriptorCopyToProtoTest.testCopyToProto_TypeError.__unittest_e
descriptor_test.GeneratedDescriptorTest.testDescriptor.__unittest_expecting_failure__ = True
descriptor_test.MakeDescriptorTest.testCamelcaseName.__unittest_expecting_failure__ = True
descriptor_test.MakeDescriptorTest.testJsonName.__unittest_expecting_failure__ = True
descriptor_test.MakeDescriptorTest.testMakeDescriptorWithNestedFields.__unittest_expecting_failure__ = True
descriptor_test.MakeDescriptorTest.testMakeDescriptorWithOptions.__unittest_expecting_failure__ = True
descriptor_test.MakeDescriptorTest.testMakeDescriptorWithUnsignedIntField.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testAggregateOptions.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testComplexExtensionOptions.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testContainingServiceFixups.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testContainingTypeFixups.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testCustomOptionsCopyTo.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testDefault.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testDifferentCustomOptionTypes.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testEnumFixups.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testEnumValueName.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testFileDescriptor.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testFileDescriptorReferences.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testGetOptions.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testImmutableCppDescriptor.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testNestedOptions.__unittest_expecting_failure__ = True
descriptor_test.NewDescriptorTest.testSimpleCustomOptions.__unittest_expecting_failure__ = True
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUp():
#
# AttributeError: 'google.protobuf.pyext._message.DescriptorPool' object has no attribute 'Add'
# TypeError: Couldn't build proto file into descriptor pool: duplicate file name (some/filename/some.proto)
#
# TODO: change to __unittest_expecting_failure__ when DescriptorPool.Add() is implemented
descriptor_test.DescriptorTest.testAggregateOptions.__unittest_skip__ = True
descriptor_test.DescriptorTest.testComplexExtensionOptions.__unittest_skip__ = True
descriptor_test.DescriptorTest.testContainingServiceFixups.__unittest_skip__ = True
descriptor_test.DescriptorTest.testContainingTypeFixups.__unittest_skip__ = True
descriptor_test.DescriptorTest.testCustomOptionsCopyTo.__unittest_skip__ = True
descriptor_test.DescriptorTest.testDefault.__unittest_skip__ = True
descriptor_test.DescriptorTest.testDifferentCustomOptionTypes.__unittest_skip__ = True
descriptor_test.DescriptorTest.testEnumFixups.__unittest_skip__ = True
descriptor_test.DescriptorTest.testEnumValueName.__unittest_skip__ = True
descriptor_test.DescriptorTest.testFileDescriptor.__unittest_skip__ = True
descriptor_test.DescriptorTest.testFileDescriptorReferences.__unittest_skip__ = True
descriptor_test.DescriptorTest.testGetOptions.__unittest_skip__ = True
descriptor_test.DescriptorTest.testImmutableCppDescriptor.__unittest_skip__ = True
descriptor_test.DescriptorTest.testNestedOptions.__unittest_skip__ = True
descriptor_test.DescriptorTest.testSimpleCustomOptions.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testAggregateOptions.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testComplexExtensionOptions.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testContainingServiceFixups.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testContainingTypeFixups.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testCustomOptionsCopyTo.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testDefault.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testDifferentCustomOptionTypes.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testEnumFixups.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testEnumValueName.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testFileDescriptor.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testFileDescriptorReferences.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testGetOptions.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testImmutableCppDescriptor.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testNestedOptions.__unittest_skip__ = True
descriptor_test.NewDescriptorTest.testSimpleCustomOptions.__unittest_skip__ = True
# TODO: change to __unittest_expecting_failure__ when we have some solution for duplicated filenames
descriptor_test.DescriptorTest.__unittest_skip__ = True
if __name__ == '__main__':
unittest.main(module=descriptor_test, verbosity=2)

@ -28,13 +28,9 @@ import unittest
generator_test.GeneratorTest.testBadIdentifiers.__unittest_expecting_failure__ = True
generator_test.GeneratorTest.testExtensionScope.__unittest_expecting_failure__ = True
generator_test.GeneratorTest.testFileDescriptor.__unittest_expecting_failure__ = True
generator_test.GeneratorTest.testMessageWithCustomOptions.__unittest_expecting_failure__ = True
generator_test.GeneratorTest.testOneof.__unittest_expecting_failure__ = True
generator_test.GeneratorTest.testOptions.__unittest_expecting_failure__ = True
generator_test.SymbolDatabaseRegistrationTest.testEnums.__unittest_expecting_failure__ = True
generator_test.SymbolDatabaseRegistrationTest.testFindFileByName.__unittest_expecting_failure__ = True
generator_test.SymbolDatabaseRegistrationTest.testGetSymbol.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=generator_test, verbosity=2)

@ -29,7 +29,6 @@ import unittest
json_format_test.JsonFormatTest.testAllFieldsToJson.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testAlwaysSeriliaze.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testAnyMessage.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testAnyMessageDescriptorPoolMissingType.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testDurationMessage.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testEmptyMessageToJson.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testExtensionSerializationDictMatchesProto3Spec.__unittest_expecting_failure__ = True
@ -40,17 +39,13 @@ json_format_test.JsonFormatTest.testExtensionToDictAndBackWithScalar.__unittest_
json_format_test.JsonFormatTest.testExtensionToJsonAndBack.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testFieldMaskMessage.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testFloatPrecision.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testIgnoreUnknownField.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testInvalidAny.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testInvalidMap.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testJsonEscapeString.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testJsonName.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testJsonParseDictToAnyDoesNotAlterInput.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testListValueMessage.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testMapFields.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testNullValue.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testOneofFields.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testParseDictAnyDescriptorPoolMissingType.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testParseNull.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testPartialMessageToJson.__unittest_expecting_failure__ = True
json_format_test.JsonFormatTest.testStructMessage.__unittest_expecting_failure__ = True

@ -28,8 +28,6 @@ import unittest
keywords_test.KeywordsConflictTest.testExtension.__unittest_expecting_failure__ = True
keywords_test.KeywordsConflictTest.testExtensionForNestedMessage.__unittest_expecting_failure__ = True
keywords_test.KeywordsConflictTest.testMessage.__unittest_expecting_failure__ = True
keywords_test.KeywordsConflictTest.testNestedMessage.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=keywords_test, verbosity=2)

@ -26,16 +26,10 @@
from google.protobuf.internal import message_factory_test
import unittest
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUp():
#
# AttributeError: 'google.protobuf.pyext._message.FileDescriptor' object has no attribute 'serialized_pb'
#
# TODO: change to __unittest_expecting_failure__ when serialized_pb is available.
message_factory_test.MessageFactoryTest.testCreatePrototypeOverride.__unittest_skip__ = True
message_factory_test.MessageFactoryTest.testDuplicateExtensionNumber.__unittest_skip__ = True
message_factory_test.MessageFactoryTest.testGetMessages.__unittest_skip__ = True
message_factory_test.MessageFactoryTest.testGetPrototype.__unittest_skip__ = True
message_factory_test.MessageFactoryTest.testCreatePrototypeOverride.__unittest_expecting_failure__ = True
message_factory_test.MessageFactoryTest.testDuplicateExtensionNumber.__unittest_expecting_failure__ = True
message_factory_test.MessageFactoryTest.testGetMessages.__unittest_expecting_failure__ = True
message_factory_test.MessageFactoryTest.testGetPrototype.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=message_factory_test, verbosity=2)

@ -94,14 +94,8 @@ message_test.Proto3Test.testScalarMap.__unittest_expecting_failure__ = True
message_test.Proto3Test.testScalarMapDefaults.__unittest_expecting_failure__ = True
message_test.Proto3Test.testStringUnicodeConversionInMap.__unittest_expecting_failure__ = True
message_test.Proto3Test.testSubmessageMap.__unittest_expecting_failure__ = True
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUpClass():
#
# AttributeError: 'google.protobuf.pyext._message.DescriptorPool' object has no attribute 'Add'
#
# TODO: change to __unittest_expecting_failure__ when DescriptorPoo.Add is implemented
message_test.OversizeProtosTest.__unittest_skip__ = True
message_test.OversizeProtosTest.testAssertOversizeProto.__unittest_expecting_failure__ = True
message_test.OversizeProtosTest.testSucceedOversizeProto.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=message_test, verbosity=2)

@ -27,9 +27,6 @@ from google.protobuf.internal import proto_builder_test
import unittest
proto_builder_test.ProtoBuilderTest.testMakeLargeProtoClass.__unittest_expecting_failure__ = True
proto_builder_test.ProtoBuilderTest.testMakeSameProtoClassTwice.__unittest_expecting_failure__ = True
proto_builder_test.ProtoBuilderTest.testMakeSimpleProtoClass.__unittest_expecting_failure__ = True
proto_builder_test.ProtoBuilderTest.testOrderedFields.__unittest_expecting_failure__ = True
if __name__ == '__main__':
unittest.main(module=proto_builder_test, verbosity=2)

@ -35,8 +35,6 @@ reflection_test.ByteSizeTest.testPackedExtensions.__unittest_expecting_failure__
reflection_test.ByteSizeTest.testRepeatedCompositesDelete.__unittest_expecting_failure__ = True
reflection_test.ByteSizeTest.testRepeatedScalarsRemove.__unittest_expecting_failure__ = True
reflection_test.ClassAPITest.testMakeClassWithNestedDescriptor.__unittest_expecting_failure__ = True
reflection_test.ClassAPITest.testParsingFlatClass.__unittest_expecting_failure__ = True
reflection_test.ClassAPITest.testParsingNestedClass.__unittest_expecting_failure__ = True
reflection_test.ExtensionEqualityTest.testExtensionEquality.__unittest_expecting_failure__ = True
reflection_test.MutualRecursionEqualityTest.testEqualityWithMutualRecursion.__unittest_expecting_failure__ = True
reflection_test.OptionsTest.testMessageOptions.__unittest_expecting_failure__ = True
@ -54,7 +52,6 @@ reflection_test.Proto2ReflectionTest.testMergeFromExtensionsNestedMessage.__unit
reflection_test.Proto2ReflectionTest.testMergeFromExtensionsRepeated.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testMergeFromExtensionsSingular.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testNestedExtensions.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testRegisteredExtensions.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testRepeatedCompositeConstructor.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testRepeatedCompositeRemove.__unittest_expecting_failure__ = True
reflection_test.Proto2ReflectionTest.testRepeatedCompositeReverse_Empty.__unittest_expecting_failure__ = True

@ -40,7 +40,6 @@ text_format_test.OnlyWorksWithProto2RightNowTests.testPrintInIndexOrder.__unitte
text_format_test.OnlyWorksWithProto2RightNowTests.testPrintMap.__unittest_expecting_failure__ = True
text_format_test.OnlyWorksWithProto2RightNowTests.testPrintMapUsingCppImplementation.__unittest_expecting_failure__ = True
text_format_test.OnlyWorksWithProto2RightNowTests.testPrintUnknownFields.__unittest_expecting_failure__ = True
text_format_test.OptionalColonMessageToStringTest.testForcePrintOptionalColon.__unittest_expecting_failure__ = True
text_format_test.Proto2Tests.testExtensionInsideAnyMessage.__unittest_expecting_failure__ = True
text_format_test.Proto2Tests.testMergeDuplicateExtensionScalars.__unittest_expecting_failure__ = True
text_format_test.Proto2Tests.testParseAllExtensions.__unittest_expecting_failure__ = True
@ -57,19 +56,7 @@ text_format_test.Proto2Tests.testPrintAllExtensionsPointy.__unittest_expecting_f
text_format_test.Proto2Tests.testPrintMessageSet.__unittest_expecting_failure__ = True
text_format_test.Proto2Tests.testPrintMessageSetAsOneLine.__unittest_expecting_failure__ = True
text_format_test.Proto2Tests.testPrintMessageSetByFieldNumber.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeAlternativeUrl.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeExpandedAny.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeExpandedAnyDescriptorPoolMissingType.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeExpandedAnyPointyBrackets.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeExpandedAnyRepeated.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testMergeMissingAnyEndToken.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintAndParseMessageInvalidAny.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAny.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAnyAsOneLine.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAnyAsOneLinePointyBrackets.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAnyDescriptorPoolMissingType.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAnyPointyBrackets.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testPrintMessageExpandAnyRepeated.__unittest_expecting_failure__ = True
text_format_test.Proto3Tests.testTopAnyMessage.__unittest_expecting_failure__ = True
getattr(text_format_test.TextFormatMessageToStringTests, "testCustomOptions" + sep + "0").__unittest_expecting_failure__ = True
getattr(text_format_test.TextFormatMessageToStringTests, "testCustomOptions" + sep + "1").__unittest_expecting_failure__ = True
@ -112,13 +99,5 @@ getattr(text_format_test.TextFormatParserTests, "testParseEmptyText" + sep + "1"
getattr(text_format_test.TextFormatParserTests, "testParseEmptyText" + sep + "0").__unittest_expecting_failure__ = True
getattr(text_format_test.TextFormatParserTests, "testParseEmptyText" + sep + "1").__unittest_expecting_failure__ = True
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUp():
#
# NotImplementedError: Conversion of message types not yet implemented
#
# TODO: change to __unittest_expecting_failure__ when message types can be converted
#text_format_test.WhitespaceTest.__unittest_skip__ = True
if __name__ == '__main__':
unittest.main(module=text_format_test, verbosity=2)

@ -26,12 +26,6 @@
from google.protobuf.internal import unknown_fields_test
import unittest
# We must skip these tests entirely (rather than running them with
# __unittest_expecting_failure__) because they error out in setUp():
#
# NotImplementedError: access repeated
#
# TODO: change to __unittest_expecting_failure__ when repeated fields are available
unknown_fields_test.UnknownEnumValuesTest.testCheckUnknownFieldValueForEnum.__unittest_expecting_failure__ = True
unknown_fields_test.UnknownEnumValuesTest.testRoundTrip.__unittest_expecting_failure__ = True
unknown_fields_test.UnknownFieldsAccessorsTest.testCheckUnknownFieldValue.__unittest_expecting_failure__ = True

@ -392,10 +392,13 @@ static google_protobuf_FileDescriptorProto *filedef_toproto(
google_protobuf_FileDescriptorProto_set_name(
proto, strviewdup(ctx, upb_filedef_name(f)));
size_t n = strlen(upb_filedef_package(f));
if (n) {
google_protobuf_FileDescriptorProto_set_package(
proto, strviewdup(ctx, upb_filedef_package(f)));
const char* package = upb_filedef_package(f);
if (package) {
size_t n = strlen(package);
if (n) {
google_protobuf_FileDescriptorProto_set_package(
proto, strviewdup(ctx, upb_filedef_package(f)));
}
}
if (upb_filedef_syntax(f) == UPB_SYNTAX_PROTO3) {
@ -403,6 +406,7 @@ static google_protobuf_FileDescriptorProto *filedef_toproto(
strviewdup(ctx, "proto3"));
}
size_t n;
n = upb_filedef_depcount(f);
upb_strview *deps = google_protobuf_FileDescriptorProto_resize_dependency(
proto, n, ctx->arena);

Loading…
Cancel
Save