Exemplo n.º 1
0
        def test_disabled_contracts(self):
            contracts.disable_all()

            @contract
            def disabled(phrase):
                """
                :type phrase: str
                """
                return phrase

            # this should not throw w/ contracts disabled
            disabled(int(8))
            contracts.enable_all()
            # this will still not throw because the disabled value is checked at decoration time only
            disabled(int(8))

            @contract
            def enabled(phrase):
                """
                :type phrase: str
                """
                return phrase

            # a newly decorated function will throw
            with pytest.raises(exceptions.ContractNotRespected):
                enabled(int(8))
Exemplo n.º 2
0
def enable_all():
    """
    Wraps PyContracts `enable_all()
    <http://andreacensi.github.io/contracts/api/contracts.html#
    module-contracts.enabling>`_ function. From the PyContracts documentation:
    "Enables all contract checks. Can be overridden by an environment variable"
    """
    contracts.enable_all()
Exemplo n.º 3
0
        def test_disabled_contracts(self):
            contracts.disable_all()

            @contract
            def disabled(phrase):
                """
                :type phrase: str
                """
                return phrase
            # this should not throw w/ contracts disabled
            disabled(int(8))
            contracts.enable_all()
            # this will still not throw because the disabled value is checked at decoration time only
            disabled(int(8))

            @contract
            def enabled(phrase):
                """
                :type phrase: str
                """
                return phrase
            # a newly decorated function will throw
            with pytest.raises(exceptions.ContractNotRespected):
                enabled(int(8))
 def setUp(self):
     contracts.enable_all()
Exemplo n.º 5
0
 def __exit__(self, type, value, traceback):
     enable_all()
 def setUp(self):
     contracts.enable_all()