Example #1
0
    def test_missing_ctypes(self, monkeypatch):
        """
        Keeps working if ctypes is missing.

        A warning is emitted that points to the actual code.
        """
        monkeypatch.setattr(attr._compat, "import_ctypes", lambda: None)
        func = make_set_closure_cell()

        with pytest.warns(RuntimeWarning) as wr:
            func()

        w = wr.pop()
        assert __file__ == w.filename
        assert (
            "Missing ctypes.  Some features like bare super() or accessing "
            "__class__ will not work with slots classes.", ) == w.message.args

        assert just_warn is func
Example #2
0
    def test_missing_ctypes(self, monkeypatch):
        """
        Keeps working if ctypes is missing.

        A warning is emitted that points to the actual code.
        """
        monkeypatch.setattr(attr._compat, "import_ctypes", lambda: None)
        func = make_set_closure_cell()

        with pytest.warns(RuntimeWarning) as wr:
            func()

        w = wr.pop()
        assert __file__ == w.filename
        assert (
            "Missing ctypes.  Some features like bare super() or accessing "
            "__class__ will not work with slots classes.",
        ) == w.message.args

        assert just_warn is func
Example #3
0
    def test_code_hack_failure(self, monkeypatch):
        """
        Keeps working if function/code object introspection doesn't work
        on this (nonstandard) interpeter.

        A warning is emitted that points to the actual code.
        """
        # This is a pretty good approximation of the behavior of
        # the actual types.CodeType on Brython.
        monkeypatch.setattr(types, "CodeType", lambda: None)
        func = make_set_closure_cell()

        with pytest.warns(RuntimeWarning) as wr:
            func()

        w = wr.pop()
        assert __file__ == w.filename
        assert ("Running interpreter doesn't sufficiently support code object "
                "introspection.  Some features like bare super() or accessing "
                "__class__ will not work with slotted classes.",
                ) == w.message.args

        assert just_warn is func