예제 #1
0
파일: this.py 프로젝트: fishroot/nemoa
def get_module() -> Module:
    """Get reference to current module."""
    name = get_module_name(-1)
    if name:
        ref = entity.get_module(name)
        if isinstance(ref, Module):
            return ref
    raise ModuleNotFoundError("could not detect current module")
예제 #2
0
def get_module() -> Module:
    """Get reference to current module."""
    name = get_module_name(-1)
    if name:
        ref = entity.get_module(name)
        if isinstance(ref, Module):
            return ref
    raise ModuleNotFoundError("could not detect current module")
예제 #3
0
def get_caller_module() -> Module:
    """Get reference to callers module."""
    name = get_module_name(-2)
    if name:
        ref = entity.get_module(name)
        if isinstance(ref, Module):
            return ref
    raise ModuleNotFoundError("could not detect module of caller")
예제 #4
0
파일: this.py 프로젝트: fishroot/nemoa
def get_caller_module() -> Module:
    """Get reference to callers module."""
    name = get_module_name(-2)
    if name:
        ref = entity.get_module(name)
        if isinstance(ref, Module):
            return ref
    raise ModuleNotFoundError("could not detect module of caller")
예제 #5
0
파일: stdio.py 프로젝트: fishroot/nemoa
def get_ttylib() -> OptModule:
    """Get module for tty I/O control.

    Depending on the plattform the module within the standard library, which is
    required for tty I/O control differs. The module :py:mod:`termios` provides
    an interface to the POSIX calls for tty I/O control. The module
    :py:mod:`msvcrt` provides access to some useful capabilities on Windows
    platforms.

    Returns:
        Reference to module for tty I/O control or None, if the module could
        not be determined.

    """
    libs = ['msvcrt', 'termios']
    for name in libs:
        ref = entity.get_module(name)
        if ref:
            return ref
    return None
예제 #6
0
def get_submodule(name: str, ref: OptModule = None) -> OptModule:
    """Get instance from the name of a submodule of the current module.

    Args:
        name: Name of submodule of given module.
        ref: Module reference. By default the current callers module is used.

    Returns:
        Module reference of submodule or None, if the current module does not
        contain the given module name.

    """
    # Check type of 'name'
    check.has_type("argument 'name'", name, str)

    # Set default module to callers module
    ref = ref or get_caller_module()

    # Get instance of submodule
    return entity.get_module(ref.__name__ + '.' + name)
예제 #7
0
파일: this.py 프로젝트: fishroot/nemoa
def get_submodule(name: str, ref: OptModule = None) -> OptModule:
    """Get instance from the name of a submodule of the current module.

    Args:
        name: Name of submodule of given module.
        ref: Module reference. By default the current callers module is used.

    Returns:
        Module reference of submodule or None, if the current module does not
        contain the given module name.

    """
    # Check type of 'name'
    check.has_type("argument 'name'", name, str)

    # Set default module to callers module
    ref = ref or get_caller_module()

    # Get instance of submodule
    return entity.get_module(ref.__name__ + '.' + name)
예제 #8
0
파일: stdio.py 프로젝트: fishroot/nemoa
def get_ttylib() -> OptModule:
    """Get module for tty I/O control.

    Depending on the plattform the module within the standard library, which is
    required for tty I/O control differs. The module :py:mod:`termios` provides
    an interface to the POSIX calls for tty I/O control. The module
    :py:mod:`msvcrt` provides access to some useful capabilities on Windows
    platforms.

    Returns:
        Reference to module for tty I/O control or None, if the module could
        not be determined.

    """
    libs = ['msvcrt', 'termios']
    for name in libs:
        ref = entity.get_module(name)
        if ref:
            return ref
    return None
예제 #9
0
def get_root(ref: OptModule = None) -> Module:
    """Get top level module.

    Args:
        ref: Module reference. By default the current callers module is used.

    Returns:
        Module reference to the top level module of the current callers module.

    """
    # Set default module to callers module
    ref = ref or get_caller_module()

    # Get name of the top level module
    name = ref.__name__.split('.', 1)[0]

    # Get reference to the top level module
    tlref = entity.get_module(name)
    if not isinstance(tlref, Module):
        raise ModuleNotFoundError(f"module '{name}' does not exist")
    return tlref
예제 #10
0
파일: this.py 프로젝트: fishroot/nemoa
def get_root(ref: OptModule = None) -> Module:
    """Get top level module.

    Args:
        ref: Module reference. By default the current callers module is used.

    Returns:
        Module reference to the top level module of the current callers module.

    """
    # Set default module to callers module
    ref = ref or get_caller_module()

    # Get name of the top level module
    name = ref.__name__.split('.', 1)[0]

    # Get reference to the top level module
    tlref = entity.get_module(name)
    if not isinstance(tlref, Module):
        raise ModuleNotFoundError(f"module '{name}' does not exist")
    return tlref
예제 #11
0
파일: test.py 프로젝트: fishroot/nemoa
    def assertModuleIsComplete(self) -> None:
        """Assert that all members of module are tested."""
        if not hasattr(self, 'module') or not self.test_completeness:
            return

        # Get reference to module
        ref = entity.get_module(self.module)
        if not ref:
            raise AssertionError(f"module {self.module} does not exist")

        # Get module members
        members = set()
        for name in getattr(
                ref, '__all__',
                entity.get_members(ref, classinfo=(type, Function))):
            if name.startswith('_'):
                continue  # Filter protected members
            if getattr(ref, name).__module__ != ref.__name__:
                continue  # Filter imported members
            if BaseException in getattr(getattr(ref, name), '__mro__', []):
                continue  # Filter exceptions
            members.add(name)

        # Get tested module members
        tested = set(name[5:] for name in entity.get_members(
            self, classinfo=Method, pattern='test_*'))

        # Get untested module members
        untested = members - tested
        if not untested:
            return

        # Raise error on untested module members
        raise AssertionError(
            f"module '{self.module}' comprises "
            f"untested members: {', '.join(sorted(untested))}")
예제 #12
0
파일: __test__.py 프로젝트: fishroot/nemoa
 def test_get_submodules(self) -> None:
     parent = entity.get_module('nemoa.base')
     subs: StrList = []
     if isinstance(parent, Module):
         subs = entity.get_submodules(ref=parent)
     self.assertIn(__name__, subs)
예제 #13
0
파일: __test__.py 프로젝트: fishroot/nemoa
 def test_get_module(self) -> None:
     ref = entity.get_module(__name__)
     self.assertIsInstance(ref, Module)
     self.assertEqual(getattr(ref, '__name__'), __name__)
예제 #14
0
파일: __test__.py 프로젝트: fishroot/nemoa
 def test_get_submodules(self) -> None:
     parent = entity.get_module('nemoa.base')
     subs: StrList = []
     if isinstance(parent, Module):
         subs = entity.get_submodules(ref=parent)
     self.assertIn(__name__, subs)
예제 #15
0
파일: __test__.py 프로젝트: fishroot/nemoa
 def test_get_module(self) -> None:
     ref = entity.get_module(__name__)
     self.assertIsInstance(ref, Module)
     self.assertEqual(getattr(ref, '__name__'), __name__)