Server IP : 85.214.239.14 / Your IP : 3.137.219.213 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/cwd/srv/modoboa/env/lib64/python3.5/site-packages/gevent/tests/ |
Upload File : |
from __future__ import print_function import doctest import functools import os import re import sys import unittest # Ignore tracebacks: ZeroDivisionError def myfunction(*_args, **_kwargs): pass class RENormalizingOutputChecker(doctest.OutputChecker): """ Pattern-normalizing output checker. Inspired by one used in zope.testing. """ def __init__(self, patterns): self.transformers = [functools.partial(re.sub, replacement) for re, replacement in patterns] def check_output(self, want, got, optionflags): if got == want: return True for transformer in self.transformers: want = transformer(want) got = transformer(got) return doctest.OutputChecker.check_output(self, want, got, optionflags) FORBIDDEN_MODULES = set() class Modules(object): def __init__(self, allowed_modules): from gevent.testing import walk_modules self.allowed_modules = allowed_modules self.modules = set() for path, module in walk_modules(recursive=True): self.add_module(module, path) def add_module(self, name, path): if self.allowed_modules and name not in self.allowed_modules: return if name in FORBIDDEN_MODULES: return self.modules.add((name, path)) def __bool__(self): return bool(self.modules) __nonzero__ = __bool__ def __iter__(self): return iter(self.modules) def main(): # pylint:disable=too-many-locals cwd = os.getcwd() # Use pure_python to get the correct module source and docstrings os.environ['PURE_PYTHON'] = '1' import gevent from gevent import socket from gevent.testing import util from gevent.testing import sysinfo if sysinfo.WIN: FORBIDDEN_MODULES.update({ # Uses commands only found on posix 'gevent.subprocess', }) try: allowed_modules = sys.argv[1:] sys.path.append('.') globs = { 'myfunction': myfunction, 'gevent': gevent, 'socket': socket, } modules = Modules(allowed_modules) if not modules: sys.exit('No modules found matching %s' % ' '.join(allowed_modules)) suite = unittest.TestSuite() checker = RENormalizingOutputChecker(( # Normalize subprocess.py: BSD ls is in the example, gnu ls outputs # 'cannot access' (re.compile( "ls: cannot access 'non_existent_file': No such file or directory"), "ls: non_existent_file: No such file or directory"), # Python 3 bytes add a "b". (re.compile(r'b(".*?")'), r"\1"), (re.compile(r"b('.*?')"), r"\1"), )) tests_count = 0 modules_count = 0 for m, path in sorted(modules): with open(path, 'rb') as f: contents = f.read() if re.search(br'^\s*>>> ', contents, re.M): s = doctest.DocTestSuite(m, extraglobs=globs, checker=checker) test_count = len(s._tests) util.log('%s (from %s): %s tests', m, path, test_count) suite.addTest(s) modules_count += 1 tests_count += test_count util.log('Total: %s tests in %s modules', tests_count, modules_count) # TODO: Pass this off to unittest.main() runner = unittest.TextTestRunner(verbosity=2) runner.run(suite) finally: os.chdir(cwd) if __name__ == '__main__': main()