# Path: mockito/utils.py
# def get_obj(path):
#     """Return obj for given dotted path.
# 
#     Typical inputs for `path` are 'os' or 'os.path' in which case you get a
#     module; or 'os.path.exists' in which case you get a function from that
#     module.
# 
#     Just returns the given input in case it is not a str.
# 
#     Note: Relative imports not supported.
#     Raises ImportError or AttributeError as appropriate.
# 
#     """
#     # Since we usually pass in mocks here; duck typing is not appropriate
#     # (mocks respond to every attribute).
#     if not isinstance(path, str):
#         return path
# 
#     if path.startswith('.'):
#         raise TypeError('relative imports are not supported')
# 
#     parts = path.split('.')
#     head, tail = parts[0], parts[1:]
# 
#     obj = importlib.import_module(head)
# 
#     # Normally a simple reduce, but we go the extra mile
#     # for good exception messages.
#     for i, name in enumerate(tail):
#         try:
#             obj = getattr(obj, name)
#         except AttributeError:
#             # Note the [:i] instead of [:i+1], so we get the path just
#             # *before* the AttributeError, t.i. the part of it that went ok.
#             module = '.'.join([head] + tail[:i])
#             try:
#                 importlib.import_module(module)
#             except ImportError:
#                 raise AttributeError(
#                     "object '%s' has no attribute '%s'" % (module, name))
#             else:
#                 raise AttributeError(
#                     "module '%s' has no attribute '%s'" % (module, name))
#     return obj
# 
# def get_obj_attr_tuple(path):
#     """Split path into (obj, attribute) tuple.
# 
#     Given `path` is 'os.path.exists' will thus return `(os.path, 'exists')`
# 
#     If path is not a str, delegates to `get_function_host(path)`
# 
#     """
#     if not isinstance(path, str):
#         return get_function_host(path)
# 
#     if path.startswith('.'):
#         raise TypeError('relative imports are not supported')
# 
#     try:
#         leading, end = path.rsplit('.', 1)
#     except ValueError:
#         raise TypeError('path must have dots')
# 
#     return get_obj(leading), end


import pytest
import sys
        import os
        import os.path
        import os.path
        import os
        import os
        import os
        import os
from mockito.utils import get_obj, get_obj_attr_tuple
        with pytest.raises(ImportError) as exc:
            assert get_obj('mum') is foo
        if PY3:
            assert str(exc.value) == "No module named 'mum'"
        else:
            assert str(exc.value) == "No module named mum"

    def testUnknownMumFoo(self):
        with pytest.raises(ImportError) as exc:
            assert get_obj('mum.foo') is foo
        if PY3:
            assert str(exc.value) == "No module named 'mum'"
        else:
            assert str(exc.value) == "No module named mum"

    def testReturnGivenObject(self):
        assert get_obj(os) == os
        assert get_obj(os.path) == os.path
        assert get_obj(2) == 2

    def testDisallowRelativeImports(self):
        with pytest.raises(TypeError):
            get_obj('.mum')

class TestReturnTuple:
    def testOs(self):
        with pytest.raises(TypeError):
            get_obj_attr_tuple('os')

    def testOsPath(self):

# Path: mockito/utils.py
# def get_obj(path):
#     """Return obj for given dotted path.
# 
#     Typical inputs for `path` are 'os' or 'os.path' in which case you get a
#     module; or 'os.path.exists' in which case you get a function from that
#     module.
# 
#     Just returns the given input in case it is not a str.
# 
#     Note: Relative imports not supported.
#     Raises ImportError or AttributeError as appropriate.
# 
#     """
#     # Since we usually pass in mocks here; duck typing is not appropriate
#     # (mocks respond to every attribute).
#     if not isinstance(path, str):
#         return path
# 
#     if path.startswith('.'):
#         raise TypeError('relative imports are not supported')
# 
#     parts = path.split('.')
#     head, tail = parts[0], parts[1:]
# 
#     obj = importlib.import_module(head)
# 
#     # Normally a simple reduce, but we go the extra mile
#     # for good exception messages.
#     for i, name in enumerate(tail):
#         try:
#             obj = getattr(obj, name)
#         except AttributeError:
#             # Note the [:i] instead of [:i+1], so we get the path just
#             # *before* the AttributeError, t.i. the part of it that went ok.
#             module = '.'.join([head] + tail[:i])
#             try:
#                 importlib.import_module(module)
#             except ImportError:
#                 raise AttributeError(
#                     "object '%s' has no attribute '%s'" % (module, name))
#             else:
#                 raise AttributeError(
#                     "module '%s' has no attribute '%s'" % (module, name))
#     return obj
# 
# def get_obj_attr_tuple(path):
#     """Split path into (obj, attribute) tuple.
# 
#     Given `path` is 'os.path.exists' will thus return `(os.path, 'exists')`
# 
#     If path is not a str, delegates to `get_function_host(path)`
# 
#     """
#     if not isinstance(path, str):
#         return get_function_host(path)
# 
#     if path.startswith('.'):
#         raise TypeError('relative imports are not supported')
# 
#     try:
#         leading, end = path.rsplit('.', 1)
#     except ValueError:
#         raise TypeError('path must have dots')
# 
#     return get_obj(leading), end


# Path: tests/late_imports_test.py
import pytest
import sys
        import os
        import os.path
        import os.path
        import os
        import os
        import os
        import os
from mockito.utils import get_obj, get_obj_attr_tuple

        with pytest.raises(ImportError) as exc:
            assert get_obj('mum') is foo
        if PY3:
            assert str(exc.value) == "No module named 'mum'"
        else:
            assert str(exc.value) == "No module named mum"

    def testUnknownMumFoo(self):
        with pytest.raises(ImportError) as exc:
            assert get_obj('mum.foo') is foo
        if PY3:
            assert str(exc.value) == "No module named 'mum'"
        else:
            assert str(exc.value) == "No module named mum"

    def testReturnGivenObject(self):
        assert get_obj(os) == os
        assert get_obj(os.path) == os.path
        assert get_obj(2) == 2

    def testDisallowRelativeImports(self):
        with pytest.raises(TypeError):
            get_obj('.mum')

class TestReturnTuple:
    def testOs(self):
        with pytest.raises(TypeError):
            get_obj_attr_tuple('os')

    def testOsPath(self):

        assert get_obj_attr_tuple('os.path') == (os, 'path')