def test_initpkg_nodoc(monkeypatch): mod = ModuleType("hello") mod.__file__ = "hello.py" monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {}) newmod = sys.modules["hello"] assert not newmod.__doc__
def test_initpkg_defaults(monkeypatch): mod = ModuleType("hello") monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {}) newmod = sys.modules["hello"] assert newmod.__file__ is None assert not hasattr(newmod, "__version__")
def test_initpkg_nodoc(monkeypatch): mod = ModuleType('hello') mod.__file__ = "hello.py" monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {}) newmod = sys.modules['hello'] assert not newmod.__doc__
def test_initpkg_defaults(monkeypatch): mod = ModuleType('hello') monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {}) newmod = sys.modules['hello'] assert newmod.__file__ is None assert not hasattr(newmod, '__version__')
def test_initpkg_replaces_sysmodules(monkeypatch): mod = ModuleType('hello') monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {'x': 'os.path:abspath'}) newmod = sys.modules['hello'] assert newmod != mod assert newmod.x == os.path.abspath
def test_initpkg_updates_sysmodules(monkeypatch): mod = ModuleType("hello") monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {"x": "os.path:abspath"}) newmod = sys.modules["hello"] assert (PY2 and newmod != mod) or (PY3 and newmod is mod) assert newmod.x == os.path.abspath
def test_initpkg_overwrite_doc(monkeypatch): hello = ModuleType("hello") hello.__doc__ = "this is the documentation" monkeypatch.setitem(sys.modules, "hello", hello) apipkg.initpkg("hello", {"__doc__": "sys:__doc__"}) newhello = sys.modules["hello"] assert (PY2 and newhello != hello) or (PY3 and newhello is hello) assert newhello.__doc__ == sys.__doc__
def test_eagerload_on_bython(monkeypatch): monkeypatch.delitem(sys.modules, "bpython", raising=False) apipkg.initpkg("apipkg.testmodule.example.lazy", {"test": "apipkg.does_not_exist"}) monkeypatch.setitem(sys.modules, "bpython", True) with pytest.raises(ImportError): apipkg.initpkg("apipkg.testmodule.example.lazy", {"test": "apipkg.does_not_exist"})
def test_eagerload_on_bython(monkeypatch): monkeypatch.delitem(sys.modules, 'bpython', raising=False) apipkg.initpkg('apipkg.testmodule.example.lazy', {'test': 'apipkg.does_not_exist'}) monkeypatch.setitem(sys.modules, 'bpython', True) with pytest.raises(ImportError): apipkg.initpkg('apipkg.testmodule.example.lazy', {'test': 'apipkg.does_not_exist'})
def test_initpkg_overwrite_doc(monkeypatch): hello = ModuleType('hello') hello.__doc__ = "this is the documentation" monkeypatch.setitem(sys.modules, 'hello', hello) apipkg.initpkg('hello', {"__doc__": "sys:__doc__"}) newhello = sys.modules['hello'] assert newhello != hello assert newhello.__doc__ == sys.__doc__
def test_initpkg_not_transfers_not_existing_attrs(monkeypatch): mod = ModuleType('hello') mod.__file__ = "hello.py" assert not hasattr(mod, '__path__') monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {}) newmod = sys.modules['hello'] assert newmod != mod assert newmod.__file__ == py.path.local(mod.__file__) assert not hasattr(newmod, '__path__')
def test_initpkg_not_transfers_not_existing_attrs(monkeypatch): mod = ModuleType("hello") mod.__file__ = "hello.py" assert not hasattr(mod, "__path__") assert not hasattr(mod, "__package__") or mod.__package__ is None monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {}) newmod = sys.modules["hello"] assert (PY2 and newmod != mod) or (PY3 and newmod is mod) assert newmod.__file__ == os.path.abspath(mod.__file__) assert not hasattr(newmod, "__path__") assert not hasattr(newmod, "__package__") or mod.__package__ is None
def test_initpkg_not_changing_jython_paths(monkeypatch): mod = ModuleType("hello") mod.__file__ = "__pyclasspath__/test.py" mod.__path__ = ["__pyclasspath__/fun", "ichange"] monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {}) newmod = sys.modules["hello"] assert (PY2 and newmod != mod) or (PY3 and newmod is mod) assert newmod.__file__.startswith("__pyclasspath__") unchanged, changed = newmod.__path__ assert changed != "ichange" assert unchanged.startswith("__pyclasspath__")
def test_initpkg_not_changing_jython_paths(monkeypatch): mod = ModuleType('hello') mod.__file__ = '__pyclasspath__/test.py' mod.__path__ = ['__pyclasspath__/fun', 'ichange'] monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {}) newmod = sys.modules['hello'] assert newmod != mod assert newmod.__file__.startswith('__pyclasspath__') unchanged, changed = newmod.__path__ assert changed != 'ichange' assert unchanged.startswith('__pyclasspath__')
def test_initpkg_transfers_attrs(monkeypatch): mod = ModuleType('hello') mod.__version__ = 10 mod.__file__ = "hello.py" mod.__loader__ = "loader" mod.__doc__ = "this is the documentation" monkeypatch.setitem(sys.modules, 'hello', mod) apipkg.initpkg('hello', {}) newmod = sys.modules['hello'] assert newmod != mod assert newmod.__file__ == py.path.local(mod.__file__) assert newmod.__version__ == mod.__version__ assert newmod.__loader__ == mod.__loader__ assert newmod.__doc__ == mod.__doc__
def test_initpkg_transfers_attrs(monkeypatch): mod = ModuleType("hello") mod.__version__ = 10 mod.__file__ = "hello.py" mod.__loader__ = "loader" mod.__package__ = "package" mod.__doc__ = "this is the documentation" mod.goodbye = "goodbye" monkeypatch.setitem(sys.modules, "hello", mod) apipkg.initpkg("hello", {}) newmod = sys.modules["hello"] assert (PY2 and newmod != mod) or (PY3 and newmod is mod) assert newmod.__file__ == os.path.abspath(mod.__file__) assert newmod.__version__ == mod.__version__ assert newmod.__loader__ == mod.__loader__ assert newmod.__package__ == mod.__package__ assert newmod.__doc__ == mod.__doc__ assert not hasattr(newmod, "goodbye")
from apipkg import initpkg initpkg( __name__, dict( jobs = "qs.jobs", proc = "qs.proc", qserve = "qs.qserve", rpcclient = "qs.rpcclient", rpcserver = "qs.rpcserver", slave = "qs.slave"))
# import apipkg apipkg.initpkg(__name__, { 'EventReceiver' : "xunitgen2._EventReceiver:EventReceiver", 'Report' : "xunitgen2._Report:Report", 'XunitDestination' : "xunitgen2._XunitDestination:XunitDestination", 'Recorder' : "xunitgen2._Recorder:Recorder", 'XmlWriter' : "xunitgen2._XmlWriter:XmlWriter", 'toxml' : "xunitgen2._XmlWriter:toxml", })
# import apipkg apipkg.initpkg(__name__, { 'commands': { "HelpCommand": "clish._commands._HelpCommand:HelpCommand", "ExitCommand": "clish._commands._ExitCommand:ExitCommand", }, 'Namespace': "clish._Namespace:Namespace", 'Command' : "clish._Command:Command", 'Shell' : "clish._Shell:Shell", # DEPRECATE NAMES 'InteractiveCommand' : "clish._Command:Command", 'InteractiveShell' : "clish._Shell:Shell", })
------- pure python lib for connecting to local and remote Python Interpreters. (c) 2012, Holger Krekel and others """ import apipkg apipkg.initpkg( __name__, { '__version__': '._version:version', 'PopenGateway': '.deprecated:PopenGateway', 'SocketGateway': '.deprecated:SocketGateway', 'SshGateway': '.deprecated:SshGateway', 'makegateway': '.multi:makegateway', 'set_execmodel': '.multi:set_execmodel', 'HostNotFound': '.gateway_bootstrap:HostNotFound', 'RemoteError': '.gateway_base:RemoteError', 'TimeoutError': '.gateway_base:TimeoutError', 'XSpec': '.xspec:XSpec', 'Group': '.multi:Group', 'MultiChannel': '.multi:MultiChannel', 'RSync': '.rsync:RSync', 'default_group': '.multi:default_group', 'dumps': '.gateway_base:dumps', 'loads': '.gateway_base:loads', 'load': '.gateway_base:load', 'dump': '.gateway_base:dump', 'DataFormatError': '.gateway_base:DataFormatError', })
def test_importlib_find_spec_fake_module(find_spec): mod = apipkg.initpkg("apipkg.testmodule.example.missing", {}) with pytest.raises(ValueError, match=mod.__name__ + r"\.__spec__ is None"): find_spec(mod.__name__)
# mypkg/__init__.py import apipkg apipkg.initpkg( __name__, { "SomeClass": "_mypkg.somemodule:SomeClass", "sub": { "OtherClass": "_mypkg.somemodule:OtherClass", }, }, )
""" anyvc ~~~~~~ pythonic vcs abstractions :license: LPL2 :copyright: Ronny Pfannschmidt and others """ import apipkg apipkg.initpkg( __name__, { 'workdir': { 'clone': 'anyvc._workdir:clone', 'checkout': 'anyvc._workdir:checkout', 'open': 'anyvc._workdir:open', }, })
import codecs from collections import namedtuple import logging import os import re from six.moves import configparser import apipkg import pytest from pycsw.core import admin from pycsw.core.config import StaticContext apipkg.initpkg("optionaldependencies", { "psycopg2": "psycopg2", }) from optionaldependencies import psycopg2 # NOQA: E402 TESTS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SuiteDirs = namedtuple("SuiteDirs", [ "get_tests_dir", "post_tests_dir", "data_tests_dir", "expected_results_dir", "export_tests_dir", ])
exports = dict( capturing = 'ExceptionCapture OutputCapture', config = 'Config', diffing = 'TreeDiffer JSONDiffer PrettyDiffer YAMLDiffer DataDiffer', environment = 'Environment', expecting = 'MustRaise', importing = 'BlockingImporter AssertionLoggingImporter', representing = 'AttributeRepr TreeRepr', running = 'Runner TerminalRunner', suite = 'ConfigSuite Suite fixture generator test', ) defs = {} for module, members in exports.iteritems(): for member in members.split(): defs[member] = ''.join(['_detest.', module, ':', member]) defs.update( paver = dict( auto = '_detest.paver:auto', test = '_detest.paver:test', ) ) import apipkg apipkg.initpkg(__name__, defs)
execnet ------- pure python lib for connecting to local and remote Python Interpreters. (c) 2012, Holger Krekel and others """ import apipkg apipkg.initpkg(__name__, { '__version__': '._version:version', 'PopenGateway': '.deprecated:PopenGateway', 'SocketGateway': '.deprecated:SocketGateway', 'SshGateway': '.deprecated:SshGateway', 'makegateway': '.multi:makegateway', 'set_execmodel': '.multi:set_execmodel', 'HostNotFound': '.gateway_bootstrap:HostNotFound', 'RemoteError': '.gateway_base:RemoteError', 'TimeoutError': '.gateway_base:TimeoutError', 'XSpec': '.xspec:XSpec', 'Group': '.multi:Group', 'MultiChannel': '.multi:MultiChannel', 'RSync': '.rsync:RSync', 'default_group': '.multi:default_group', 'dumps': '.gateway_base:dumps', 'loads': '.gateway_base:loads', 'load': '.gateway_base:load', 'dump': '.gateway_base:dump', 'DataFormatError': '.gateway_base:DataFormatError', })
# import apipkg apipkg.initpkg( __name__, { 'commands': { "HelpCommand": "clish._commands._HelpCommand:HelpCommand", "ExitCommand": "clish._commands._ExitCommand:ExitCommand", }, 'Namespace': "clish._Namespace:Namespace", 'Command': "clish._Command:Command", 'Shell': "clish._Shell:Shell", # DEPRECATE NAMES 'InteractiveCommand': "clish._Command:Command", 'InteractiveShell': "clish._Shell:Shell", })
# mypkg/__init__.py import apipkg apipkg.initpkg( __name__, { 'SomeClass': '_mypkg.somemodule:SomeClass', 'sub': { 'OtherClass': '_mypkg.somemodule:OtherClass', } })
from apipkg import initpkg initpkg( __name__, dict( rst='rag.documents.rst', fs='rag.histories.fs', git='rag.histories.git', scss='rag.stylesheets.scss', genshi='rag.templates.genshi', bare='rag.sites.bare', Site='rag.sites.default:Site', ))
from apipkg import initpkg initpkg(__name__, dict( rst='rag.documents.rst', fs='rag.histories.fs', git='rag.histories.git', scss='rag.stylesheets.scss', genshi='rag.templates.genshi', bare='rag.sites.bare', Site='rag.sites.default:Site', ) )
def test_initpkg_without_old_module(): apipkg.initpkg("initpkg_without_old_module", dict(modules="sys:modules")) from initpkg_without_old_module import modules assert modules is sys.modules
pure python lib for connecting to local and remote Python Interpreters. (c) 2012, Holger Krekel and others """ import apipkg apipkg.initpkg( __name__, { "__version__": "._version:version", "PopenGateway": ".deprecated:PopenGateway", "SocketGateway": ".deprecated:SocketGateway", "SshGateway": ".deprecated:SshGateway", "makegateway": ".multi:makegateway", "set_execmodel": ".multi:set_execmodel", "HostNotFound": ".gateway_bootstrap:HostNotFound", "RemoteError": ".gateway_base:RemoteError", "TimeoutError": ".gateway_base:TimeoutError", "XSpec": ".xspec:XSpec", "Group": ".multi:Group", "MultiChannel": ".multi:MultiChannel", "RSync": ".rsync:RSync", "default_group": ".multi:default_group", "dumps": ".gateway_base:dumps", "loads": ".gateway_base:loads", "load": ".gateway_base:load", "dump": ".gateway_base:dump", "DataFormatError": ".gateway_base:DataFormatError", }, )
from apipkg import initpkg initpkg( __name__, dict(jobs="qs.jobs", proc="qs.proc", qserve="qs.qserve", rpcclient="qs.rpcclient", rpcserver="qs.rpcserver", slave="qs.slave"))
import codecs from collections import namedtuple import logging import os import re import configparser import apipkg import pytest from pycsw.core import admin from pycsw.core.config import StaticContext apipkg.initpkg("optionaldependencies", { "psycopg2": "psycopg2", }) from optionaldependencies import psycopg2 # NOQA: E402 TESTS_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SuiteDirs = namedtuple("SuiteDirs", [ "get_tests_dir", "post_tests_dir", "data_tests_dir", "expected_results_dir", "export_tests_dir", ])
from apipkg import initpkg from ramverk.inventory import members api = {} for module, names in members.iteritems(): for name in names: assert name not in api api[name] = ':'.join([module, name]) initpkg(__name__, api)