Exemple #1
0
 def __init__(self, graph=None):
     super(Analysis, self).__init__()
     self.graph = graph or rgraph.Graph()
     self.object_manager = objects.ObjectManager()
     self.tracer = self._register_setup(
         tracer.Tracer(self.graph, self.object_manager))
     self.import_hook = self._register_setup(
         import_hook.ImportHook(self.graph, self.object_manager))
def test_nested_import():
    om = objects.ObjectManager()
    with ImportImportHook(graph.Graph(), om):
        import email.mime.message

    assert om.lookup_module("email") == objects.Module.from_imported(email)
    assert om.lookup_module("email.mime") == objects.Module.from_imported(
        email.mime)
    assert om.lookup_module(
        "email.mime.message") == objects.Module.from_imported(
            email.mime.message)
def test_from_import_with_nonmodule():
    om = objects.ObjectManager()
    with ImportImportHook(graph.Graph(), om):
        from email.mime.message import MIMEMessage

    import email.mime

    assert om.lookup_module("email") == objects.Module.from_imported(email)
    assert om.lookup_module("email.mime") == objects.Module.from_imported(
        email.mime)
    assert om.lookup_module(
        "email.mime.message") == objects.Module.from_imported(
            email.mime.message)
def test_relative_importlib():
    om = objects.ObjectManager()
    with ImportLibImportHook(graph.Graph(), om):
        _image = importlib.import_module("..message", "email.mime.image")

    import email.mime.message

    assert om.lookup_module("email") == objects.Module.from_imported(email)
    assert om.lookup_module("email.mime") == objects.Module.from_imported(
        email.mime)
    assert om.lookup_module(
        "email.mime.message") == objects.Module.from_imported(
            email.mime.message)
def test_complex_from_import():
    om = objects.ObjectManager()
    with ImportImportHook(graph.Graph(), om):
        from email.mime import message, image

    import email.mime

    assert om.lookup_module("email") == objects.Module.from_imported(email)
    assert om.lookup_module("email.mime") == objects.Module.from_imported(
        email.mime)
    assert om.lookup_module(
        "email.mime.message") == objects.Module.from_imported(
            email.mime.message)
    assert om.lookup_module(
        "email.mime.image") == objects.Module.from_imported(email.mime.image)
def test_basic_import():
    om = objects.ObjectManager()
    with ImportImportHook(graph.Graph(), om):
        import this

    assert om.lookup_module("this") == objects.Module.from_imported(this)
def test_basic_import_module():
    om = objects.ObjectManager()
    with ImportLibImportHook(graph.Graph(), om):
        this = importlib.import_module("this")

    assert om.lookup_module("this") == objects.Module.from_imported(this)