Ejemplo n.º 1
0
    def test_get_locations_supported(self):
        # Test _get_locations return the supported location types.
        registry = TargetRegistry()

        class SpecificEditor:
            pass

        class Locator1:
            pass

        class Locator2:
            pass

        def solver(wrapper, location):
            return 1

        # when
        registry.register_location(
            target_class=SpecificEditor,
            locator_class=Locator1,
            solver=solver,
        )
        registry.register_location(
            target_class=SpecificEditor,
            locator_class=Locator2,
            solver=solver,
        )

        # then
        self.assertEqual(registry._get_locations(SpecificEditor()),
                         {Locator1, Locator2})
Ejemplo n.º 2
0
    def test_register_location(self):
        def solver(wrapper, location):
            return 1

        registry = TargetRegistry()
        registry.register_location(target_class=float,
                                   locator_class=str,
                                   solver=solver)

        self.assertIs(registry.get_solver(float, str), solver)
Ejemplo n.º 3
0
    def test_help_message(self):

        class Action:
            """ Say hello.
            Say bye.
            """
            pass

        class Locator:
            """ Return anything you like.
            Good day!
            """
            pass

        registry1 = TargetRegistry()
        registry1.register_interaction(
            target_class=str,
            interaction_class=Action,
            handler=mock.Mock(),
        )
        registry2 = TargetRegistry()
        registry2.register_location(
            target_class=str,
            locator_class=Locator,
            solver=mock.Mock(),
        )

        wrapper = example_ui_wrapper(
            target="dummy", registries=[registry1, registry2]
        )

        # when
        stream = io.StringIO()
        with mock.patch("sys.stdout", stream):
            wrapper.help()

        # then
        self.assertEqual(
            stream.getvalue(),
            textwrap.dedent(f"""\
                Interactions
                ------------
                {Action!r}
                    Say hello.
                    Say bye.

                Locations
                ---------
                {Locator!r}
                    Return anything you like.
                    Good day!

            """)
        )
Ejemplo n.º 4
0
    def test_register_location_report_existing(self):
        def solver(wrapper, location):
            return 1

        registry = TargetRegistry()
        registry.register_location(target_class=float,
                                   locator_class=str,
                                   solver=solver)

        with self.assertRaises(LocationNotSupported) as exception_context:
            registry.get_solver(float, None)

        self.assertEqual(exception_context.exception.supported, [str])
Ejemplo n.º 5
0
    def test_get_location_help_default(self):
        class Locator:
            """ Some default documentation."""
            pass

        registry = TargetRegistry()
        registry.register_location(
            target_class=float,
            locator_class=Locator,
            solver=lambda w, l: 1,
        )

        help_text = registry.get_location_doc(
            target_class=float,
            locator_class=Locator,
        )
        self.assertEqual(help_text, "Some default documentation.")