test_config.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:gdata-python3 作者: dvska 项目源码 文件源码
def check_data_classes(test, classes):
    import inspect
    for data_class in classes:
        test.assertTrue(data_class.__doc__ is not None,
                        'The class %s should have a docstring' % data_class)
        if hasattr(data_class, '_qname'):
            qname_versions = None
            if isinstance(data_class._qname, tuple):
                qname_versions = data_class._qname
            else:
                qname_versions = (data_class._qname,)
            for versioned_qname in qname_versions:
                test.assertTrue(isinstance(versioned_qname, str),
                                'The class %s has a non-string _qname' % data_class)
                test.assertTrue(not versioned_qname.endswith('}'),
                                'The _qname for class %s is only a namespace' % (
                                    data_class))

        for attribute_name, value in data_class.__dict__.items():
            # Ignore all elements that start with _ (private members)
            if not attribute_name.startswith('_'):
                try:
                    if not (isinstance(value, str) or inspect.isfunction(value)
                            or (isinstance(value, list)
                                and issubclass(value[0], atom.core.XmlElement))
                            or type(value) == property  # Allow properties.
                            or inspect.ismethod(value)  # Allow methods.
                            or inspect.ismethoddescriptor(value)  # Allow method descriptors.
                            # staticmethod et al.
                            or issubclass(value, atom.core.XmlElement)):
                        test.fail(
                            'XmlElement member should have an attribute, XML class,'
                            ' or list of XML classes as attributes.')

                except TypeError:
                    test.fail('Element %s in %s was of type %s' % (
                        attribute_name, data_class._qname, type(value)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号