def test_function(self):
        """Watch a function from a module."""
        with wrapping.watch_namespace(
                imports.import_nearest_module) as container:
            imports.import_nearest_module("sys")

        self.assertEqual([(("sys", ), dict(), sys)],
                         [record.get_all() for record in container])
    def test_class_init(self):
        """Watch a class's ``__init__`` method."""
        with wrapping.watch_namespace(
                dependency_analyzer._FakeModule.__init__,  # pylint: disable=protected-access
        ) as container:
            dependency_analyzer._FakeModule("text")  # pylint: disable=protected-access

        self.assertEqual([(("text", ), dict(), None)],
                         [record.get_all() for record in container])
    def test_class_call(self):
        """Watch a instance's ``__call__`` method."""
        caller = _Callable()

        with wrapping.watch_namespace(_Callable.__call__) as container:
            caller("thing")

        self.assertEqual([(("thing", ), dict(), 8)],
                         [record.get_all() for record in container])
    def test_instance_method_003(self):
        """Watch an instance's method."""
        item = dependency_analyzer._FakeModule(  # pylint: disable=protected-access
            "text")

        with wrapping.watch_namespace(item.get_path) as container:
            item.get_path()

        self.assertEqual([(tuple(), dict(), "text")],
                         [record.get_all() for record in container])
    def test_static_function(self):
        """Watch a function from a class."""
        with wrapping.watch_namespace(
                _Callable.do_static,
                namespace="tests.test_wrapping._Callable.do_static"
        ) as container:
            _Callable.do_static("thing")

        self.assertEqual([(("thing", ), dict(), 9)],
                         [record.get_all() for record in container])
    def test_instance_dunder(self):
        """Watch an instance's ``__repr__`` dunder (double-underscore) method."""

        with wrapping.watch_namespace(dependency_analyzer._FakeModule.__repr__  # pylint: disable=protected-access
                                      ) as container:
            item = dependency_analyzer._FakeModule(  # pylint: disable=protected-access
                "text")
            repr(item)

        self.assertEqual(
            [(tuple(), dict(), "_FakeModule('text')")],
            [record.get_all() for record in container],
        )