Пример #1
0
def behavior(its):
    from specfor import mock
    
    empty_mock = mock.define("empty")
    empty = empty_mock("id-0")
    mock.check(empty)
    pass
Пример #2
0
def behavior(its):
    from specfor import mock
    
    empty_mock = mock.define("empty")
    empty = empty_mock("id-0")
    
    with the.raising[AttributeError]:
        empty.foobar
        pass
    pass
Пример #3
0
def behavior(its):
    from specfor import mock
    
    counter_mock = mock.define("counter")
    method_def = counter_mock.method("count")
    @method_def.define(at=1)
    def count(self):
        return 1
    
    counter = counter_mock("id-0")
    with the.raising[AssertionError]: mock.check(counter)
    
    counter.count()
    mock.check(counter)
    
    counter.count()
    with the.raising[AssertionError]: mock.check(counter)
    pass
Пример #4
0
def behavior(its):
    from specfor import mock
    
    callbacks_mock = mock.define("callbacks")
    method_def = callbacks_mock.method("init")
    @method_def.define(ordered=1) 
    def init(self):
        pass
    
    # next of ordered count should increment just 1
    method_def = callbacks_mock.method("prepare")
    @method_def.define(ordered=2) 
    def prepare(self):
        pass
    
    method_def = callbacks_mock.method("call")
    @method_def.define(ordered=3)
    def call(self):
        pass
    
    method_def = callbacks_mock.method("cleanup")
    @method_def.define(ordered=4)
    def cleanup(self):
        pass
    
    method_def = callbacks_mock.method("destroy")
    @method_def.define(ordered=5)
    def destroy(self):
        pass
    
    
    callbacks = callbacks_mock("id-0")
    # raise AssertionError if all ordered methods are not called
    with the.raising[AssertionError]: mock.check(callbacks)
    callbacks.init()
    callbacks.prepare()
    callbacks.call()
    # raise AssertionError if method called invalid order
    with the.raising[AssertionError]: callbacks.destroy()    
    callbacks.cleanup()
    callbacks.destroy()
    mock.check(callbacks)
    pass
Пример #5
0
def behavior(its):
    from specfor import mock
    
    converter_mock = mock.define("converter")
    method = converter_mock.method("convert")
    @method.define(just=dict(item=0))
    def convert(self, item):
        return "zero"
    @method.define(just=dict(item=1))
    def convert(self, item):
        return "one"
    @method.define(like=dict(item=int))
    def convert(self, item):
        return "many"
    
    converter = converter_mock("id-0")
    
    the[converter.convert(0)].should.be["zero"]
    the[converter.convert(1)].should.be["one"]
    the[converter.convert(10)].should.be["many"]
    
    pass
Пример #6
0
def behavior(its):
    from specfor import mock
    log = []
    
    consts_mock = mock.define("consts")
    prop = consts_mock.property("content_type")
    @prop.get.always
    def content_type(self):
        log.append("get")
        return "text/html"
    @prop.set.always
    def content_type(self, val):
        log.append("ignored")
        return
    
    consts = consts_mock("id-0")
    
    the[consts.content_type].should.be["text/html"]
    consts.content_type = "application/xml"
    the[consts.content_type].should.be["text/html"]
    
    the[log].should.be_same_order_as[["get", "ignored", "get"]]
    pass