Example #1
0
 def test_questions_negative(self):
     pending = menue(self.options, callback(ret=2)())
     assert pending(arg=213, kljssaf=29) == 2
     assert pending(2) == 2
     with pytest.raises(IndexError):
         pending(30)
     pending = menue(self.options, callback(ret="Not an Int")())
     with pytest.raises(TypeError):
         pending(arg=None)
     with pytest.raises(TypeError):
         pending(None)
Example #2
0
 def test_question_kw_positive(self):
     pending = menue(self.kw_options, callback(ret="THIS IS 2")())
     assert pending() == 2
     assert pending("THIS IS 3") == 3
     with pytest.raises(KeyError):
         pending("This is not a key!")
     with pytest.raises(KeyError):
         pending = menue(self.kw_options, callback(ret="This is no key either")())
         pending()
     with pytest.raises(KeyError):
         pending(4)
Example #3
0
from __future__ import with_statement

import pytest

from storytracker.tests import callback

@callback(*range(5), This="that", There="Then", Blah=None, ret=4)
def bad_example(*args, **kwargs):
    assert(len(args)==5)
    assert(len(kwargs)==4)
    return 4

call1=callback(*range(5), This="that", There="Then", Blah=None, ret=4)()
call2=bad_example
call3=callback(This="that", There="Then", Blah=None)()
call4=callback()()

class TestCallback(object):

    def test_pos(self):
        ret=call1(0,1,2,3,4,This="that", There="Then", Blah="Meh", Extra="null")
        assert(ret==4)
        ret=call2(0,1,2,3,4,This="that", There="Then", Blah="Meh", Extra="null")
        assert(ret==4)
        ret=call3(This="that", There="Then", Blah="Meh", Extra="null")
        assert(ret==None)
        ret=call4()
        assert(ret==None)


    def test_neg(self):
Example #4
0
 def test_question_positive(self):
     pending = menue(self.options, callback(ret=2)())
     assert pending() == 2
     for j in range(5):
         assert pending(j) == j