Exemplo n.º 1
0
    def check(self, ref_cls, chk_cls):
        """
		desc:
			Checks whether chk_cls is a valid back-end implementation of
			ref_cls.

		arguments:
			ref_cls:
				desc:	The reference class.
				type:	type
			chk_cls:
				desc:	The implementation class.
				type:	type
		"""

        print(u'Starting new check ...')
        print(u'\tChecking whether %s inherits %s ...' % (chk_cls, ref_cls))
        self.assertTrue(issubclass(chk_cls, ref_cls))
        # Loop through all functions
        for name, ref_obj in ref_cls.__dict__.items():
            ref_df = yamldoc.DocFactory(ref_obj, types=[u'function'])
            if ref_df is None:
                continue
            chk_obj = getattr(chk_cls, name)
            chk_df = yamldoc.DocFactory(chk_obj, types=[u'function'])
            print(u'\tChecking %s ...' % chk_obj)
            # Remove keyword dictionaries from the argument specification,
            # because these can change because of the @configurable decorator.
            ref_argSpec = ref_df.argSpec()._replace(keywords=None)
            chk_argSpec = chk_df.argSpec()._replace(keywords=None)
            self.assertEqual(ref_argSpec, chk_argSpec)
            chk_src = safe_decode(inspect.getsource(chk_obj).strip())
            # Check whether the function has been implemented
            self.assertNotIn(u'raise NotImplementedError()', chk_src)
        print(u'Done!')
Exemplo n.º 2
0
    def check(self, ref_cls, chk_cls):
        """
		desc:
			Checks whether chk_cls is a valid back-end implementation of
			ref_cls.

		arguments:
			ref_cls:
				desc:	The reference class.
				type:	inherit
			chk_cls:
				desc:	The implementation class.
				type:	inherit
		"""

        print(u'Starting new check ...')
        print(u'\tChecking whether %s inherits %s ...' % (chk_cls, ref_cls))
        self.assertTrue(issubclass(chk_cls, ref_cls))
        # Loop through all functions
        for name, ref_obj in ref_cls.__dict__.items():
            ref_df = yamldoc.DocFactory(ref_obj, types=[u'function'])
            if ref_df == None:
                continue
            chk_obj = getattr(chk_cls, name)
            chk_df = yamldoc.DocFactory(chk_obj, types=[u'function'])
            print(u'\tChecking %s ...' % chk_obj)
            self.assertEqual(ref_df.argSpec(), chk_df.argSpec())
            chk_src = inspect.getsource(chk_obj).strip().decode(u'utf-8')
            # Check whether the function has been implemented
            self.assertNotIn(u'raise NotImplementedError()', chk_src)
            # Check whether docstrings match
            self.assertEqual(unicode(chk_df), unicode(ref_df))
        print(u'Done!')
Exemplo n.º 3
0
def createdoc(src, target, cls, **kwdict):

	if 'dummy' in sys.modules:
		del sys.modules['dummy']
	if cls is None:
		obj = imp.load_source('dummy', ROOT + src)
	else:
		obj = getattr(imp.load_source(cls, ROOT + src), cls)
	df = yamldoc.DocFactory(obj, container=u'div', **kwdict)
	print('Writing %s\n' % target)
	with open(TARGET + target, 'w') as fd:
		fd.write(str(df))
Exemplo n.º 4
0
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
This file is part of YAMLDoc.

YAMLDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

YAMLDoc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with YAMLDoc.  If not, see <http://www.gnu.org/licenses/>.
"""

import yamldoc
from academicmarkdown import build
from yamldoc.py3compat import *
fd = yamldoc.DocFactory(yamldoc)
md = build.MD(str(fd))
build.TOCAnchorHeaders = True
build.HTML(str(fd), u'readme.html')
print(md)
open(u'readme.md', u'w').write(safe_encode(md))
Exemplo n.º 5
0
						arguments. The only difference is that they have a
						default value, which is automatically included in the
						documentation generated by yamldoc.
				type:	int

		argument-list:
			varargs:	An argument list.

		keyword-dict:
			keywords:	A keyword dictionary.

		returns:
			desc:	Some return value. As for arguments and keywords, you can
					specify a type, in which case the function output can be
					checked by the @yamldoc.validate decorator.
			type:	int
		"""

		return 1

# Generate and print nicely formatted documentation for ExampleClass
df = yamldoc.DocFactory(ExampleClass)
print df
# Create an instance of ExampleClass
ec = ExampleClass()
# This works, because argument `a` should be string and keyword `b` should int.
ec.ExampleFunction('test', c=10)
# This will give an error, because the argument types do not match the docstring
# specification.
ec.ExampleFunction(10, c='test')
Exemplo n.º 6
0
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
This file is part of QProgEdit.

QProgEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

QProgEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with QProgEdit.  If not, see <http://www.gnu.org/licenses/>.
"""

import yamldoc
import QProgEdit
from QProgEdit.py3compat import *
from academicmarkdown import build

df = yamldoc.DocFactory(QProgEdit)
s = str(df)
print(s)
build.setStyle('modern')
build.MD(s, u'readme.md')
build.PDF(s, u'readme.pdf')
Exemplo n.º 7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file is part of academicmarkdown.

academicmarkdown is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

academicmarkdown is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with academicmarkdown.  If not, see <http://www.gnu.org/licenses/>.
"""

import yamldoc
import academicmarkdown
from academicmarkdown.py3compat import *

df = yamldoc.DocFactory(academicmarkdown)
academicmarkdown.build.extensions = [
    u'toc', u'exec', u'code', u'constant', u'python'
]
academicmarkdown.build.postMarkdownFilters = []
academicmarkdown.build.MD(str(df), u'readme.md')
academicmarkdown.build.PDF(str(df), u'readme.pdf')
Exemplo n.º 8
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This file is part of academicmarkdown.

academicmarkdown is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

academicmarkdown is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with academicmarkdown.  If not, see <http://www.gnu.org/licenses/>.
"""

import yamldoc
import pseudorandom
import academicmarkdown

df = yamldoc.DocFactory(pseudorandom)
academicmarkdown.build.postMarkdownFilters = []
academicmarkdown.build.MD(unicode(df), u'readme.md')
academicmarkdown.build.PDF(unicode(df), u'readme.pdf')