Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pydoctor/astbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@


def parseFile(path):
"""Duplicate of L{compiler.parseFile} that uses L{MyTransformer}."""
f = open(path, "U")
src = f.read() + "\n"
f.close()
"""Parse the contents of a Python source file."""
with open(path, 'rb') as f:
src = f.read() + b'\n'
return parse(src)


def parse(buf):
"""Duplicate of L{compiler.parse} that uses L{MyTransformer}."""
"""Parse the contents of a Unicode or bytes string."""
return ast.parse(buf)


Expand Down
23 changes: 2 additions & 21 deletions pydoctor/test/test_astbuilder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function

import inspect
import textwrap

from pydoctor import astbuilder, model
Expand Down Expand Up @@ -42,42 +41,24 @@ def f():


def test_function_argspec():
# we don't compare the defaults part of the argspec directly any
# more because inspect.getargspec returns the actual objects that
# are the defaults where as the ast stuff always gives strings
# representing those objects
src = textwrap.dedent('''
def f(a, b=3, *c, **kw):
pass
''')
mod = fromText(src)
docfunc, = mod.contents.values()
ns = {}
exec(src, ns)
realf = ns['f']
inspectargspec = inspect.getargspec(realf)
assert inspectargspec[:-1] == docfunc.argspec[:-1]
assert docfunc.argspec[-1] == ('3',)
assert docfunc.argspec == (['a', 'b'], 'c', 'kw', ('3',))


@py2only
def test_function_argspec_with_tuple():
# we don't compare the defaults part of the argspec directly any
# more because inspect.getargspec returns the actual objects that
# are the defaults where as the ast stuff always gives strings
# representing those objects
src = textwrap.dedent('''
def f((a,z), b=3, *c, **kw):
pass
''')
mod = fromText(src)
docfunc, = mod.contents.values()
ns = {}
exec(src, ns)
realf = ns['f']
inspectargspec = inspect.getargspec(realf)
assert tuple(inspectargspec[:-1]) == tuple(docfunc.argspec[:-1])
assert docfunc.argspec[-1] == ('3',)
assert docfunc.argspec == ([['a', 'z'], 'b'], 'c', 'kw', ('3',))

def test_class():
src = '''
Expand Down
3 changes: 2 additions & 1 deletion pydoctor/test/test_templatewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def test_basic_package():
for ob in system.allobjects.values():
if ob.documentation_location is model.DocLocation.OWN_PAGE:
assert os.path.isfile(os.path.join(targetdir, ob.fullName() + '.html'))
assert 'Package docstring' in open(os.path.join(targetdir, 'basic.html')).read()
with open(os.path.join(targetdir, 'basic.html')) as f:
assert 'Package docstring' in f.read()
finally:
shutil.rmtree(targetdir)

Expand Down
8 changes: 4 additions & 4 deletions pydoctor/zopeinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def addInterfaceInfoToClass(cls, interfaceargs, implementsOnly):
obj.implementedby_directly.append(cls)


schema_prog = re.compile('zope\.schema\.([a-zA-Z_][a-zA-Z0-9_]*)')
schema_prog = re.compile(r'zope\.schema\.([a-zA-Z_][a-zA-Z0-9_]*)')
interface_prog = re.compile(
'zope\.schema\.interfaces\.([a-zA-Z_][a-zA-Z0-9_]*)'
'|zope\.interface\.Interface')
r'zope\.schema\.interfaces\.([a-zA-Z_][a-zA-Z0-9_]*)'
r'|zope\.interface\.Interface')

def namesInterface(system, name):
if interface_prog.match(name):
Expand Down Expand Up @@ -151,7 +151,7 @@ def extractStringLiteral(node):
class ZopeInterfaceModuleVisitor(astbuilder.ModuleVistor):

schema_like_patterns = [
('zope\.interface\.Attribute', extractAttributeDescription),
(r'zope\.interface\.Attribute', extractAttributeDescription),
]

def funcNameFromCall(self, node):
Expand Down