示例#1
0
文件: tests.py 项目: aleien/deal
 def test_contract_state_switch_default_param(self):
     func = deal.pre(lambda x: x > 0)(lambda x: x * 2)
     deal.switch(main=False)
     func(-2)
     deal.switch(main=True)
     with pytest.raises(deal.PreContractError):
         func(-2)
示例#2
0
文件: tests.py 项目: aleien/deal
 def test_contract_state_switch_custom_param(self):
     func = deal.pre(lambda x: x > 0, debug=True)(lambda x: x * 2)
     deal.switch(debug=False)
     func(-2)
     deal.switch(debug=True)
     with pytest.raises(deal.PreContractError):
         func(-2)
示例#3
0
 def test_main(self):
     func = deal.pre(lambda x: x > 0)(lambda x: x * 2)
     deal.switch(main=False)
     with self.subTest(text='good'):
         func(-2)
     deal.switch(main=True)
     with self.subTest(text='error'):
         with self.assertRaises(deal.PreContractError):
             func(-2)
示例#4
0
文件: tests.py 项目: OsamaNabih/deal
 def test_debug(self):
     func = deal.pre(lambda x: x > 0, debug=True)(lambda x: x * 2)
     deal.switch(debug=False)
     with self.subTest(text='good'):
         func(-2)
     deal.switch(debug=True)
     with self.subTest(text='error'):
         with pytest.raises(deal.PreContractError):
             func(-2)
示例#5
0
def test_state_switch_activate():
    try:
        assert deal.activate()
        assert deactivate()

        deal.switch(main=False)
        assert not deal.activate()
    finally:
        deactivate()
        deal.switch(main=True)
示例#6
0
def test_state_switch_module_load_debug():
    with pytest.raises(RuntimeError):
        deal.module_load(debug=True)
    try:
        deal.switch(debug=False)
        deal.activate()
        deal.module_load(debug=True)
    finally:
        deactivate()
        deal.switch(debug=True)
示例#7
0
def test_contract_state_switch_default_param_generator():
    @deal.pre(lambda x: x > 0)
    def func(x):
        yield x * 2

    deal.switch(main=False)
    assert list(func(-2)) == [-4]
    deal.switch(main=True)
    with pytest.raises(deal.PreContractError):
        list(func(-2))
示例#8
0
def test_contract_state_switch_default_param_async():
    @deal.pre(lambda x: x > 0)
    async def func(x):
        return x * 2

    deal.switch(main=False)
    assert run_sync(func(-2)) == -4
    deal.switch(main=True)
    with pytest.raises(deal.PreContractError):
        run_sync(func(-2))