예제 #1
0
    def test_doc_specific(self):
        """ Test specific stuff on doc() """

        # Classes are represented correctly
        class A(object): pass
        def f(arg=A): pass
        d = exdoc.doc(f)
        self.assertEqual(d['signature'],  "f(arg=A)")
        self.assertEqual(d['qsignature'], "f(arg=A)")

        # Variadic arguments with classes
        class A(object):
            """ Blah blah

            :param a: First
            :param args: Many arguments
            :param kwargs: And keywords
            """

            def __init__(self, a=1, *args, **kwargs):
                pass

        d = exdoc.doc(A)
        self.assertEqual(d['signature'], "A(a=1, *args, **kwargs)")
        self.assertEqual(d['args'], [
            dict(name='a',          type=None, default=1,   doc='First'),
            dict(name='*args',      type=None,              doc='Many arguments'),
            dict(name='**kwargs',   type=None,              doc='And keywords')
        ])
예제 #2
0
def docmodule(module, *predicates):
    return {
        'module': doc(module),
        'attrs':
        {key: doc(value)
         for key, value in getmembers(module, *predicates)},
    }
예제 #3
0
    def test_doc_specific(self):
        """ Test specific stuff on doc() """

        # Classes are represented correctly
        class A:
            pass

        def f(arg=A):
            pass

        d = exdoc.doc(f)
        self.assertEqual(d['signature'], "f(arg=A)")
        self.assertEqual(d['qsignature'],
                         "PyTest.test_doc_specific.<locals>.f(arg=A)")

        # Variadic arguments with classes
        class A:
            """ Blah blah

            :param a: First
            :param args: Many arguments
            :param kwargs: And keywords
            """
            def __init__(self, a=1, *args, **kwargs):
                pass

        d = exdoc.doc(A)
        self.assertEqual(d['signature'], "A(a=1, *args, **kwargs)")
        self.assertEqual(d['args'], [
            dict(name='a', type=None, default=1, doc='First'),
            dict(name='*args', type=None, doc='Many arguments'),
            dict(name='**kwargs', type=None, doc='And keywords')
        ])
예제 #4
0
def doccls(cls, *predicates):
    return {
        'class': doc(cls),
        'attrs':
        {key: doc(value, cls)
         for key, value in getmembers(cls, *predicates)},
    }
예제 #5
0
    def test_google_annotations(self):
        """ Test how annotated function arguments work """

        # Test a generic annotated function
        def f1(a, b: int, c: Union[int, str]) -> bool:
            """
            Args:
                a: one
                b: two
            Returns:
                three
            """
            pass

        d = exdoc.doc(f1)
        self.assertEqual(d['ret'], {'type': 'bool', 'doc': 'three'})
        self.assertEqual(d['args'], [
            {
                'name': 'a',
                'type': None,
                'doc': 'one'
            },
            {
                'name': 'b',
                'type': 'int',
                'doc': 'two'
            },
            {
                'name': 'c',
                'type': 'Union[int, str]',
                'doc': ''
            },
        ])
        self.assertEqual(d['signature'], 'f1(a, b, c)')
        self.assertEqual(d['tsignature'],
                         'f1(a, b: int, c: Union[int, str]) -> bool')

        # Test one specific case: no docstr, just annotation
        def f2(a, b) -> 'PyTest':
            pass

        d = exdoc.doc(f2)
        self.assertEqual(d['ret'], {'type': 'PyTest', 'doc': ''})
예제 #6
0
파일: README.py 프로젝트: kolypto/j2cli
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli
import j2cli.context
import j2cli.extras.filters


README = {
    'formats': {
        name: doc(f)
        for name, f in j2cli.context.FORMATS.items()
    },
    'extras': {
        'filters': {k: doc(v)
                    for k, v in getmembers(j2cli.extras.filters)
                    if inspect.isfunction(v) and inspect.getmodule(v) is j2cli.extras.filters}
    }
}

assert 'yaml' in README['formats'], 'Looks like the YAML library is not installed!'

print(json.dumps(README))
예제 #7
0
import json
from exdoc import doc, getmembers, subclasses

# Methods
doccls = lambda cls, *allowed_keys: {
    'cls': doc(cls),
    'attrs': {name: doc(m, cls)
              for name, m in getmembers(cls, None,
                                        lambda key, value: key in allowed_keys or not key.startswith('_'))}
}

docmodule = lambda mod: {
    'module': doc(mod),
    'members': [ doc(getattr(mod, name)) for name in mod.__all__]
}

# Data
import mongosql
from mongosql.handlers import project, sort, group, filter, join, joinf, aggregate, limit, count
from mongosql import query, MongoQuerySettingsDict, StrictCrudHelperSettingsDict
from mongosql import ModelPropertyBags, CombinedBag, CountingQuery
from mongosql.crud import crudhelper, CrudHelper, StrictCrudHelper, CrudViewMixin, saves_relations

data = dict(
    mongosql=doc(mongosql),
    handlers=doc(mongosql.handlers),
    operations={
        m.__name__.rsplit('.', 1)[1]: doc(m)
        for m in (project, sort, group, filter, join, joinf, aggregate, limit, count)},
    mongosql_query=doc(mongosql.query),
예제 #8
0
파일: README.py 프로젝트: unomena/j2cli
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli
import j2cli.context
import j2cli.extras.filters

README = {
    'formats': {name: doc(f)
                for name, f in j2cli.context.FORMATS.items()},
    'extras': {
        'filters': [
            doc(v) for k, v in getmembers(j2cli.extras.filters)
            if inspect.isfunction(v)
        ]
    }
}

print json.dumps(README)
예제 #9
0
    def test_doc(self):
        """ Test doc() """

        # Module
        d = exdoc.doc(exdoc)
        self.assertEqual(d.pop('module'), None)
        self.assertEqual(d.pop('name'), 'exdoc')
        self.assertEqual(d.pop('qualname'), 'exdoc')
        self.assertTrue(d.pop('doc').startswith('Create a python file'))
        self.assertEqual(d, {})


        # Function
        d = exdoc.doc(h)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'h')
        self.assertEqual(d.pop('qualname'), 'h')
        self.assertEqual(d.pop('doc'), 'Just a function')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'),  'h(a, b, c=True, d=1, *args, **kwargs)')
        self.assertEqual(d.pop('qsignature'), 'h(a, b, c=True, d=1, *args, **kwargs)')
        self.assertEqual(d.pop('ret'), {'doc': 'nothing', 'type': 'None'})

        self.assertEqual(d.pop('args'), [
                {'name': 'a',        'type': 'int',  'doc': 'A-value'},
                {'name': 'b',        'type': None,   'doc': 'B-value, no type'},
                {'name': 'c',        'type': 'None', 'doc': '', 'default': True},
                {'name': 'd',        'type': None,   'doc': '', 'default': 1},
                {'name': '*args',    'type': None,   'doc': 'Varargs'},
                {'name': '**kwargs', 'type': None,   'doc': 'Kwargs'},
            ])
        self.assertEqual(d.pop('exc'), [
            {'name': 'AssertionError', 'doc': 'sometimes'}
        ])
        self.assertEqual(d, {})

        # Class: A
        d = exdoc.doc(A)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'A')
        self.assertEqual(d.pop('qualname'), 'A')
        self.assertIn('x.__init__(...)', d.pop('doc'))  # 'x.__init__(...) initializes x; see help(type(x)) for signature'  # Pythonic stuff here
        self.assertEqual(d.pop('clsdoc'), 'Empty class')
        self.assertEqual(d.pop('signature'),  'A()')
        self.assertEqual(d.pop('qsignature'), 'A()')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Class: B
        d = exdoc.doc(B)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'B')
        self.assertEqual(d.pop('qualname'), 'B')
        self.assertEqual(d.pop('doc'), 'Constructor')
        self.assertEqual(d.pop('clsdoc'), 'Class with a constructor')
        self.assertEqual(d.pop('signature'),  'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('qsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [
            {'name': 'a', 'type': None, 'doc': ''},
            {'name': 'b', 'type': None, 'doc': '', 'default': 1},
            {'name': '*args', 'type': None, 'doc': ''},
            {'name': '**kwargs', 'type': None, 'doc': ''},
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Class: X
        d = exdoc.doc(X)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'X')
        self.assertEqual(d.pop('qualname'), 'X')
        self.assertEqual(d.pop('doc'), 'old-style class')
        self.assertEqual(d.pop('clsdoc'), 'old-style class')
        self.assertEqual(d.pop('signature'),  'X()')
        self.assertEqual(d.pop('qsignature'), 'X()')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Class: Y
        d = exdoc.doc(Y)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'Y')
        self.assertEqual(d.pop('qualname'), 'Y')
        self.assertEqual(d.pop('doc'), 'Constructor documented in class body')
        self.assertEqual(d.pop('clsdoc'), 'Constructor documented in class body')
        self.assertEqual(d.pop('signature'),  'Y(a, b=1)')
        self.assertEqual(d.pop('qsignature'), 'Y(a, b=1)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [
            {'name': 'a', 'type': 'int', 'doc': 'A'},
            {'name': 'b', 'type': None, 'doc': '', 'default': 1},
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Method: C.f
        d = exdoc.doc(C.f)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'f')
        self.assertEqual(d.pop('qualname'), 'C.f')
        self.assertEqual(d.pop('doc'), 'Empty function')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'),  'f(a=1)')
        self.assertEqual(d.pop('qsignature'), 'C.f(a=1)')
        self.assertEqual(d.pop('ret'), {'type': None, 'doc': 'nothing'})
        self.assertEqual(d.pop('args'), [
            {'name': 'a', 'type': None, 'doc': '', 'default': 1}
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Static Method: C.s
        d = exdoc.doc(C.s)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 's')
        self.assertEqual(d.pop('qualname'), 's')  # FIXME: wrong name for staticmethods!
        self.assertEqual(d.pop('doc'), 'Empty static method')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'),  's(a=2)')  # FIXME: wrong name for staticmethods!
        self.assertEqual(d.pop('qsignature'), 's(a=2)')  # FIXME: wrong name for staticmethods!
        self.assertEqual(d.pop('ret'), {'type': 'None', 'doc': ''})
        self.assertEqual(d.pop('args'), [
            {'name': 'a', 'type': None, 'doc': '', 'default': 2}
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Class Method: C.c
        d = exdoc.doc(C.c)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'c')
        self.assertEqual(d.pop('qualname'), 'C.c')
        self.assertEqual(d.pop('doc'), '')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'),  'c(a=3)')
        self.assertEqual(d.pop('qsignature'), 'C.c(a=3)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [
            {'name': 'a', 'type': None, 'doc': '', 'default': 3}
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})

        # Property: C.p
        d = exdoc.doc(C.p)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'p')
        self.assertEqual(d.pop('qualname'), 'p')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('doc'), 'Property doc')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'),  'p')
        self.assertEqual(d.pop('qsignature'), 'p')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d, {})
예제 #10
0
    def test_google_docstring(self):
        # === Test: Function
        # Test the args section
        def f1_args(a, b, c):
            """ Google format

                Args:
                    a: first
                    b (int): second
                        multiline
                    c: third
                        multiline
            """

        d = exdoc.doc(f1_args)
        self.assertEqual(d['doc'], 'Google format')
        self.assertEqual(d['ret'], None)
        self.assertEqual(d['args'], [
            {
                'name': 'a',
                'type': None,
                'doc': 'first'
            },
            {
                'name': 'b',
                'type': 'int',
                'doc': 'second\nmultiline'
            },
            {
                'name': 'c',
                'type': None,
                'doc': 'third\nmultiline'
            },
        ])
        self.assertEqual(d['exc'], [])
        self.assertEqual(d['example'], None)

        # Test the returns section
        def f2_returns(a, b, c):
            """ Google 2

                Args:
                    a:
                    b:
                        something
                Returns:
                    nothing, really
            """

        d = exdoc.doc(f2_returns)
        self.assertEqual(d['doc'], 'Google 2')
        self.assertEqual(d['ret'], {'type': None, 'doc': 'nothing, really'})
        self.assertEqual(d['args'], [
            {
                'name': 'a',
                'type': None,
                'doc': ''
            },
            {
                'name': 'b',
                'type': None,
                'doc': 'something'
            },
            {
                'name': 'c',
                'type': None,
                'doc': ''
            },
        ])
        self.assertEqual(d['exc'], [])
        self.assertEqual(d['example'], None)

        # Test the raises section
        def f3_raises(a):
            """ Google 3

            Arguments:
                a:
            Returns:
                None: nothing
                multiline
            Raises:
                ValueError: bad data
                KeyError: bad idea
            """

        d = exdoc.doc(f3_raises)
        self.assertEqual(d['doc'], 'Google 3')
        self.assertEqual(d['ret'], {
            'type': 'None',
            'doc': 'nothing\nmultiline'
        })
        self.assertEqual(d['args'], [
            {
                'name': 'a',
                'type': None,
                'doc': ''
            },
        ])
        self.assertEqual(d['exc'], [
            {
                'name': 'ValueError',
                'doc': 'bad data'
            },
            {
                'name': 'KeyError',
                'doc': 'bad idea'
            },
        ])
        self.assertEqual(d['example'], None)

        # Test example section
        def f4_example():
            """ Google 4
            Multiline

            Example:
                f4_example() #-> good results
                yeehaw
            """

        d = exdoc.doc(f4_example)
        self.assertEqual(d['doc'], 'Google 4\nMultiline')
        self.assertEqual(d['args'], [])
        self.assertEqual(d['exc'], [])
        self.assertEqual(d['example'], 'f4_example() #-> good results\nyeehaw')

        # Test return value type
        def f6_returns():
            """ Google 6

                Returns:
                    bool: some status
            """

        d = exdoc.doc(f6_returns)
        self.assertEqual(d['ret'], {'type': 'bool', 'doc': 'some status'})
        self.assertEqual(d['tsignature'], 'f6_returns() -> bool')

        # Test that indentation is preserved
        # This is important for proper Markdown generation
        def f7_indentation(a):
            """
            Example:
                a
                    b
                c
            Args:
                a: a
                        b
                    c
            Returns:
                bool: a
                        b
                    c
            """

        d = exdoc.doc(f7_indentation)
        self.assertEqual(d['ret'], {'type': 'bool', 'doc': 'a\n    b\nc'})
        self.assertEqual(d['args'], [{
            'name': 'a',
            'type': None,
            'doc': 'a\n    b\nc'
        }])
        self.assertEqual(d['example'], 'a\n    b\nc')

        # === Test: Class
        class ClsDocstr:
            """
            Example class

            Attrs:
                a: first
                b(int): second
                c: third

            Example:
                hey :)
            """

        d = exdoc.doc(ClsDocstr)
예제 #11
0
#! /usr/bin/env python

from exdoc import doc, getmembers
import json

import exdoc, exdoc.py, exdoc.sa


def docmodule(module):
    return { name: doc(value)
             for name, value in list(getmembers(module)) + [('__module__', module)] }

data = {
    'exdoc': {
        '__module__': doc(exdoc),
        'py': docmodule(exdoc.py),
        'sa': docmodule(exdoc.sa)
    }
}

print(json.dumps(data, indent=2))
예제 #12
0
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import shinto_cli
import shinto_cli.context
import shinto_cli.extras.filters

README = {
    'formats':
    {name: doc(f)
     for name, f in shinto_cli.context.FORMATS.items()},
    'extras': {
        'filters': [
            doc(v) for k, v in getmembers(shinto_cli.extras.filters)
            if inspect.isfunction(v)
        ]
    }
}

print json.dumps(README)
예제 #13
0
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli
import j2cli.context
import j2cli.extras.filters


README = {
    'formats': {
        name: doc(f)
        for name, f in j2cli.context.FORMATS.items()
    },
    'extras': {
        'filters': [doc(v)
                    for k, v in getmembers(j2cli.extras.filters)
                    if inspect.isfunction(v) and inspect.getmodule(v) is j2cli.extras.filters]
    }
}

print(json.dumps(README))
예제 #14
0
파일: README.py 프로젝트: alexamel/Zoyka
def docmodule(module, *predicates):
    return {
        'module': doc(module),
        'attrs': {key: doc(value) for key, value in getmembers(module, *predicates)},
    }
예제 #15
0
import json
from exdoc import doc

# Data
import nplus1loader

data = dict(module=doc(nplus1loader),
            # load_options = [
            #     doc(nplus1loader.)
            # ]
            )

# Document
print(json.dumps(data, indent=2))
예제 #16
0
파일: README.py 프로젝트: alexamel/Zoyka
def doccls(cls, *predicates):
    return {
        'class': doc(cls),
        'attrs': {key: doc(value) for key, value in getmembers(cls, *predicates)},
    }
예제 #17
0
파일: README.py 프로젝트: alexamel/Zoyka
import password_strength
from password_strength import PasswordPolicy, PasswordStats
from exdoc import doc, getmembers

import json


def docmodule(module, *predicates):
    return {
        'module': doc(module),
        'attrs': {key: doc(value) for key, value in getmembers(module, *predicates)},
    }


def doccls(cls, *predicates):
    return {
        'class': doc(cls),
        'attrs': {key: doc(value) for key, value in getmembers(cls, *predicates)},
    }


data = {
    'PasswordPolicy': doccls(PasswordPolicy),
    'PasswordStats': doccls(PasswordStats),
    'tests': docmodule(password_strength.tests, lambda key, value: key not in ('ATest',)),
    'ATest': doc(password_strength.tests.ATest),
}

print json.dumps(data, indent=2)
예제 #18
0
def docmodule(module):
    return { name: doc(value)
             for name, value in list(getmembers(module)) + [('__module__', module)] }
예제 #19
0
파일: README.py 프로젝트: wesobi/j2cli
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli
import j2cli.context
import j2cli.extras.filters

README = {
    'formats': {name: doc(f)
                for name, f in j2cli.context.FORMATS.items()},
    'extras': {
        'filters': {
            k: doc(v)
            for k, v in getmembers(j2cli.extras.filters)
            if inspect.isfunction(v)
            and inspect.getmodule(v) is j2cli.extras.filters
        }
    }
}

assert 'yaml' in README[
    'formats'], 'Looks like the YAML library is not installed!'

print(json.dumps(README))
예제 #20
0
    def test_doc(self):
        """ Test doc() """

        # Module
        d = exdoc.doc(exdoc)
        self.assertEqual(d.pop('module'), None)
        self.assertEqual(d.pop('name'), 'exdoc')
        self.assertEqual(d.pop('qualname'), 'exdoc')
        self.assertTrue(d.pop('doc').startswith('Create a python file'))
        self.assertEqual(d, {})

        # Function
        d = exdoc.doc(h)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'h')
        self.assertEqual(d.pop('qualname'), 'h')
        self.assertEqual(d.pop('doc'), 'Just a function')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('ret'), {'doc': 'nothing', 'type': 'None'})
        self.assertEqual(d.pop('signature'),
                         'h(a, b, c=True, d=1, *args, **kwargs)')
        self.assertEqual(d.pop('rtsignature'),
                         'h(a, b, c=True, d=1, *args, **kwargs) -> None')
        self.assertEqual(
            d.pop('tsignature'),
            'h(a: int, b, c: None=True, d=1, *args, **kwargs) -> None')
        self.assertEqual(d.pop('qsignature'),
                         'h(a, b, c=True, d=1, *args, **kwargs)')
        self.assertEqual(d.pop('qrtsignature'),
                         'h(a, b, c=True, d=1, *args, **kwargs) -> None')
        self.assertEqual(
            d.pop('qtsignature'),
            'h(a: int, b, c: None=True, d=1, *args, **kwargs) -> None')

        self.assertEqual(d.pop('args'), [
            {
                'name': 'a',
                'type': 'int',
                'doc': 'A-value'
            },
            {
                'name': 'b',
                'type': None,
                'doc': 'B-value, no type'
            },
            {
                'name': 'c',
                'type': 'None',
                'doc': '',
                'default': True
            },
            {
                'name': 'd',
                'type': None,
                'doc': '',
                'default': 1
            },
            {
                'name': '*args',
                'type': None,
                'doc': 'Varargs'
            },
            {
                'name': '**kwargs',
                'type': None,
                'doc': 'Kwargs'
            },
        ])
        self.assertEqual(d.pop('exc'), [{
            'name': 'AssertionError',
            'doc': 'sometimes'
        }])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Class: A
        d = exdoc.doc(A)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'A')
        self.assertEqual(d.pop('qualname'), 'A')
        self.assertEqual(d.pop('doc'), 'Empty class')
        self.assertEqual(d.pop('clsdoc'), 'Empty class')

        self.assertEqual(d.pop('signature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('tsignature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('rtsignature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('qsignature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('qtsignature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('qrtsignature'), 'A(*args, **kwargs)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [
            {
                'name': '*args',
                'type': None,
                'doc': ''
            },
            {
                'name': '**kwargs',
                'type': None,
                'doc': ''
            },
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Class: B
        d = exdoc.doc(B)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'B')
        self.assertEqual(d.pop('qualname'), 'B')
        self.assertEqual(d.pop('doc'), 'Constructor')
        self.assertEqual(d.pop('clsdoc'), 'Class with a constructor')
        self.assertEqual(d.pop('signature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('rtsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('tsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('qsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('qrtsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('qtsignature'), 'B(a, b=1, *args, **kwargs)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [
            {
                'name': 'a',
                'type': None,
                'doc': ''
            },
            {
                'name': 'b',
                'type': None,
                'doc': '',
                'default': 1
            },
            {
                'name': '*args',
                'type': None,
                'doc': ''
            },
            {
                'name': '**kwargs',
                'type': None,
                'doc': ''
            },
        ])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Method: C.f
        d = exdoc.doc(C.f, C)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'f')
        self.assertEqual(d.pop('qualname'), 'C.f')
        self.assertEqual(d.pop('doc'), 'Empty function')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'), 'f(a=1)')
        self.assertEqual(d.pop('rtsignature'), 'f(a=1)')
        self.assertEqual(d.pop('tsignature'), 'f(a=1)')
        self.assertEqual(d.pop('qsignature'), 'C.f(a=1)')
        self.assertEqual(d.pop('qrtsignature'), 'C.f(a=1)')
        self.assertEqual(d.pop('qtsignature'), 'C.f(a=1)')
        self.assertEqual(d.pop('ret'), {'type': None, 'doc': 'nothing'})
        self.assertEqual(d.pop('args'), [{
            'name': 'a',
            'type': None,
            'doc': '',
            'default': 1
        }])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Static Method: C.s
        d = exdoc.doc(C.s, C)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 's')
        self.assertEqual(d.pop('qualname'), 'C.s')
        self.assertEqual(d.pop('qsignature'), 'C.s(a=2)')
        self.assertEqual(d.pop('qrtsignature'), 'C.s(a=2) -> None')
        self.assertEqual(d.pop('qtsignature'), 'C.s(a=2) -> None')
        self.assertEqual(d.pop('signature'), 's(a=2)')
        self.assertEqual(d.pop('tsignature'), 's(a=2) -> None')
        self.assertEqual(d.pop('rtsignature'), 's(a=2) -> None')
        self.assertEqual(d.pop('doc'), 'Empty static method')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('ret'), {'type': 'None', 'doc': ''})
        self.assertEqual(d.pop('args'), [{
            'name': 'a',
            'type': None,
            'doc': '',
            'default': 2
        }])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Class Method: C.c
        d = exdoc.doc(C.c, C)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'c')
        self.assertEqual(d.pop('qualname'), 'C.c')
        self.assertEqual(d.pop('doc'), '')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('signature'), 'c(a=3)')
        self.assertEqual(d.pop('rtsignature'), 'c(a=3)')
        self.assertEqual(d.pop('tsignature'), 'c(a=3)')
        self.assertEqual(d.pop('qsignature'), 'C.c(a=3)')
        self.assertEqual(d.pop('qrtsignature'), 'C.c(a=3)')
        self.assertEqual(d.pop('qtsignature'), 'C.c(a=3)')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [{
            'name': 'a',
            'type': None,
            'doc': '',
            'default': 3
        }])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})

        # Property: C.p
        d = exdoc.doc(C.p)
        self.assertEqual(d.pop('module'), 'py-test')
        self.assertEqual(d.pop('name'), 'p')
        self.assertEqual(d.pop('qualname'),
                         'C.p')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('qsignature'),
                         'p')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('qrtsignature'),
                         'C.p(self)')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('qtsignature'),
                         'C.p(self)')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('signature'), 'p')
        self.assertEqual(d.pop('rtsignature'), 'p(self)')
        self.assertEqual(d.pop('tsignature'),
                         'p(self)')  # FIXME: wrong name for properties!
        self.assertEqual(d.pop('doc'), 'Property doc')
        self.assertEqual(d.pop('clsdoc'), '')
        self.assertEqual(d.pop('ret'), None)
        self.assertEqual(d.pop('args'), [])
        self.assertEqual(d.pop('exc'), [])
        self.assertEqual(d.pop('example'), None)
        self.assertEqual(d, {})
예제 #21
0
파일: README.py 프로젝트: kolypto/py-good
import good, good.schema.errors, good.voluptuous
from exdoc import doc, getmembers

import json

doccls = lambda cls, *allowed_keys: {
    'cls': doc(cls),
    'attrs': {name: doc(m, cls) for name, m in getmembers(cls, None, lambda key, value: key in allowed_keys or not key.startswith('_'))}
}

joindict = lambda *dicts: reduce(lambda memo, d: memo.update(d) or memo, dicts, {})

docmodule = lambda mod: {
    'module': doc(mod),
    'members': [ doc(getattr(mod, name)) for name in mod.__all__]
}

data = {
    'good': doc(good),
    'voluptuous': doc(good.voluptuous),

    'Schema': doccls(good.Schema, None, '__call__'),
    'errors': doc(good.schema.errors),
    'Invalid': doccls(good.Invalid),
    'MultipleInvalid': doccls(good.MultipleInvalid),
    'markers': docmodule(good.markers),

    'helpers': docmodule(good.helpers),

    'predicates': docmodule(good.validators.predicates),
    'types': docmodule(good.validators.types),
예제 #22
0
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli_3
import j2cli_3.context
import j2cli_3.extras.filters

README = {
    'formats':
    {name: doc(f)
     for name, f in list(j2cli_3.context.FORMATS.items())},
    'extras': {
        'filters': [
            doc(v) for k, v in getmembers(j2cli_3.extras.filters)
            if inspect.isfunction(v)
        ]
    }
}

print(json.dumps(README))
예제 #23
0
파일: README.py 프로젝트: DavyK/j2cli
#! /usr/bin/env python

import json
import inspect
from exdoc import doc, getmembers

import j2cli
import j2cli.context
import j2cli.extras.filters


README = {
    'formats': {
        name: doc(f)
        for name, f in j2cli.context.FORMATS.items()
    },
    'extras': {
        'filters': [doc(v)
                    for k, v in getmembers(j2cli.extras.filters)
                    if inspect.isfunction(v)]
    }
}

print json.dumps(README)
예제 #24
0
#! /usr/bin/env python

from exdoc import doc, getmembers
import json

import exdoc, exdoc.py, exdoc.sa


def docmodule(module):
    return { name: doc(value)
             for name, value in getmembers(module) + [('__module__', module)] }

data = {
    'exdoc': {
        '__module__': doc(exdoc),
        'py': docmodule(exdoc.py),
        'sa': docmodule(exdoc.sa)
    }
}

print json.dumps(data, indent=2)
예제 #25
0
    return {
        'module': doc(module),
        'attrs':
        {key: doc(value)
         for key, value in getmembers(module, *predicates)},
    }


def doccls(cls, *predicates):
    return {
        'class': doc(cls),
        'attrs':
        {key: doc(value, cls)
         for key, value in getmembers(cls, *predicates)},
    }


data = {
    'PasswordPolicy':
    doccls(PasswordPolicy),
    'PasswordStats':
    doccls(PasswordStats),
    'tests':
    docmodule(password_strength.tests, lambda key, value: key not in
              ('ATest', )),
    'ATest':
    doc(password_strength.tests.ATest),
}

print(json.dumps(data, indent=2))
예제 #26
0
def docmodule(module):
    return { name: doc(value)
             for name, value in getmembers(module) + [('__module__', module)] }
예제 #27
0
import mailem
from exdoc import doc, getmembers

import json

doccls = lambda cls, *predicates: {
    'cls': doc(cls),
    'attrs': {name: doc(m) for name, m in getmembers(cls, *predicates)}
}

data = {
    'mailem': doc(mailem),
    'Message': doc(mailem.Message),
    'Attachment': doc(mailem.Attachment),
    'ImageAttachment': doc(mailem.ImageAttachment),
    'Postman': doccls(mailem.Postman),
    'connection': doc(mailem.connection),
    'SMTPConnection': doc(mailem.connection.SMTPConnection),
    'LoopbackConnection': doc(mailem.connection.LoopbackConnection),
    'Template': doccls(mailem.template.Template, None, lambda k, v: k=='__call__' or not k.startswith('_')),
    'TemplateRegistry': doccls(mailem.template.TemplateRegistry),
}

print json.dumps(data, indent=2)
예제 #28
0
파일: README.py 프로젝트: vartagg/py-good
import good, good.schema.errors, good.voluptuous
from exdoc import doc, getmembers

import json

doccls = lambda cls, *allowed_keys: {
    'cls': doc(cls),
    'attrs': {
        name: doc(m)
        for name, m in getmembers(
            cls, None, lambda key, value: key in allowed_keys or not key.
            startswith('_'))
    }
}

joindict = lambda *dicts: reduce(lambda memo, d: memo.update(d) or memo, dicts,
                                 {})

docmodule = lambda mod: {
    'module': doc(mod),
    'members': [doc(getattr(mod, name)) for name in mod.__all__]
}

data = {
    'good': doc(good),
    'voluptuous': doc(good.voluptuous),
    'Schema': doccls(good.Schema, None, '__call__'),
    'errors': doc(good.schema.errors),
    'Invalid': doccls(good.Invalid),
    'MultipleInvalid': doccls(good.MultipleInvalid),
    'markers': docmodule(good.markers),