Exemple #1
0
def string_importing():
    assert import_dotted_name("attest") is attest
    assert import_dotted_name("attest.tests") is attest.tests
    assert import_dotted_name("attest.utils") is utils
    assert import_dotted_name("attest.utils:import_dotted_name") is import_dotted_name
    assert import_dotted_name("attest.utils.import_dotted_name") is import_dotted_name

    with raises(AttributeError):
        import_dotted_name("attest._nil")

    with raises(ImportError):
        with disable_imports("attest"):
            import_dotted_name("attest")
Exemple #2
0
def string_importing():
    assert import_dotted_name('attest') is attest
    assert import_dotted_name('attest.tests') is attest.tests
    assert import_dotted_name('attest.utils') is utils
    assert import_dotted_name('attest.utils:import_dotted_name') \
           is import_dotted_name
    assert import_dotted_name('attest.utils.import_dotted_name') \
           is import_dotted_name

    with raises(AttributeError):
        import_dotted_name('attest._nil')

    with raises(ImportError):
        with disable_imports('attest'):
            import_dotted_name('attest')
Exemple #3
0
def string_importing():
    assert import_dotted_name('attest') is attest
    assert import_dotted_name('attest.tests') is attest.tests
    assert import_dotted_name('attest.utils') is utils
    assert import_dotted_name('attest.utils:import_dotted_name') \
           is import_dotted_name
    assert import_dotted_name('attest.utils.import_dotted_name') \
           is import_dotted_name


    with raises(AttributeError):
        import_dotted_name('attest._nil')

    with raises(ImportError):
        with disable_imports('attest'):
            import_dotted_name('attest')
Exemple #4
0
 def register(self, tests):
     if inspect.isclass(tests):
             self._tests.extend(tests())
             return tests
     elif isinstance(tests, basestring):
         def istests(obj):
             return isinstance(obj, (Tests, RootGroup))
         obj = import_dotted_name(tests)
         if inspect.ismodule(obj):
             for tests in deep_get_members(tests, istests, private=True):
                 self.register(tests)
             return
         tests = obj
     for test in tests:
         if not test in self._tests:
             self._tests.append(test)
Exemple #5
0
    def register(self, tests):
        """Merge in other tests.

        :param tests:
            * A class, which is then instantiated and return allowing it to be
              used as a decorator for :class:`TestBase` classes.
            * A string, representing the dotted name to one of:

              * a module or package, which is recursively scanned for
                :class:`Tests` instances that are not private
              * an iterable yielding tests
            * Otherwise any iterable object is assumed to yield tests.

        Any of these can be passed in a list to the :class:`Tests`
        constructor.

        .. versionadded:: 0.2
            Refer to collections by import path as a string

        .. versionadded:: 0.6
            Recursive scanning of modules and packages

        .. versionchanged:: 0.6
            Tests are only added if not already added

        """
        if inspect.isclass(tests):
            self._tests.extend(tests())
            return tests
        elif isinstance(tests, basestring):
            def istests(obj):
                return isinstance(obj, Tests)
            obj = import_dotted_name(tests)
            if inspect.ismodule(obj):
                for tests in deep_get_members(tests, istests):
                    self.register(tests)
                return
            tests = obj
        for test in tests:
            if not test in self._tests:
                self._tests.append(test)