Example #1
0
    def test_provides_with_no_interface_check(self):
        class Test(HasTraits):
            # Deliberately _not_ implementing get_foo. This class
            # should not pass an IFoo interface check.
            pass

        provides_ifoo = provides(IFoo)
        with self.set_check_interfaces(0):
            # Simulate application of the decorator
            Test = provides_ifoo(Test)

        test = Test()
        self.assertIsInstance(test, IFoo)
Example #2
0
    def test_provides_with_interface_check_error(self):
        class Test(HasTraits):
            # Deliberately _not_ implementing get_foo. This class
            # should not pass an IFoo interface check.
            pass

        provides_ifoo = provides(IFoo)
        with self.set_check_interfaces(2):
            with self.assertWarns(DeprecationWarning) as warnings_cm:
                with self.assertRaises(InterfaceError):
                    # Simulate application of the decorator
                    Test = provides_ifoo(Test)

        test = Test()
        self.assertIsInstance(test, IFoo)

        self.assertIn(
            "the @provides decorator will not perform interface checks",
            str(warnings_cm.warning),
        )

        # Check we used the appropriate stacklevel.
        _, _, this_module = __name__.rpartition(".")
        self.assertIn(this_module, warnings_cm.filename)