ludibrio

Platform for test doubles in Python (mocks, stubs, fakes, and dummies)
Download

ludibrio Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • Gustavo Rezende
  • Publisher web site:
  • http://nsigustavo.blogspot.com

ludibrio Tags


ludibrio Description

Platform for test doubles in Python (mocks, stubs, fakes, and dummies) ludibrio is a platform to test doubles in Python (mocks, stubs, fakes, and dummies).MocksMocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive. >>> from ludibrio import Mock >>> with Mock() as greetings: ... greetings.excuse_me() >> 'Com licença' ... greetings.hello('Gustavo') >> 'Ola, Gustavo' ... greetings.see_you_soon >> 'Até logo' ... greetings.see_you_soon >> 'Até logo, denovo' >>> print greetings.excuse_me() Com licença >>> print greetings.hello('Gustavo') Ola, Gustavo >>> print greetings.see_you_soon Até logo >>> print greetings.see_you_soon Até logo, denovo >>> print greetings.see_you_soon Traceback (most recent call last): ... AssertionError: Object's mocks are not pre-programmed with expectations >>> with Mock() as greetings: ... greetings.excuse_me() >> 'Com licença' ... greetings.see_you_soon >> 'Até logo' >>> print greetings.excuse_me() Com licença >>> print greetings.hello('Gustavo Rezende') Traceback (most recent call last): ... AssertionError: Object's mocks are not pre-programmed with expectations: __getattribute__(see_you_soon, ) Expected: __getattribute__(hello, ) >>> with Mock() as greetings: ... greetings.excuse_me(name='gustavo') >> 'Com licença' >>> greetings.excuse_me(name='Diego Manhães') Traceback (most recent call last): ... AssertionError: Object's mocks are not pre-programmed with expectations: __call__(, name=gustavo) Expected: __call__(, name=Diego Manhães) >>> with Mock() as listing: ... listing >> 'um' ... listing >> ... listing >> 4 >>> print listing um >>> print listing >>> print listing 4 >>> with Mock() as callable: ... callable(two=2) >> 2 >>> callable(two=2) 2 >>> with Mock() as operator: ... operator * 4 >> 4 ... operator + 4 >> 5 ... operator ** 4 >> 1 >>> operator * 4 4 >>> operator + 4 5 >>> operator ** 4 1 >>> with Mock() as Greetings: ... greetings = Greetings(tree=3) >>> greetings Mock Object >>> with Mock() as MySQLdb: ... con = MySQLdb.connect('servidor', ' usuario', 'senha') ... con.select_db('banco de dados') >> None ... cursor = con.cursor() ... cursor.execute('ALGUM SQL') >> None ... cursor.fetchall() >> >>> con = MySQLdb.connect('servidor', ' usuario', 'senha') >>> con.select_db('banco de dados') >>> cursor = con.cursor() >>> cursor.execute('ALGUM SQL') >>> cursor.fetchall() >>> with Mock() as testeError: ... testeError.foo('bar') >> ArithmeticError('teste error') >>> testeError.foo('bar') Traceback (most recent call last): ... ArithmeticError: teste error >>> with Mock() as teste: ... teste.called() > teste.called() 1 >>> teste.validate() Traceback (most recent call last): ... AssertionError: Object's mocks are not pre-programmed with expectations>>> with Mock() as count:... count() >> 1... count() >> 2... count() >> 3>>> count()1>>> count()2>>> count()3DummyDummy Objects are passed around but never validated. >>> from ludibrio import Dummy >>> Dummy() Dummy Object >>> Dummy(repr="Objeto Idiota") Objeto Idiota >>> Dummy(1,2.3,"4",a=5.6, b=7, c="8 ...") Dummy Object >>> def execute_but_not_validated(x): ... x.write("teste") ... x.close() >>> execute_but_not_validated(Dummy()) >>> dummy = Dummy() >>> dummy.executAnythingAndReturnDummyObject() Dummy Object >>> dummy.foo() Dummy Object >>> dummy.bar Dummy Object >>> dummy.one.two.three() Dummy Object >>> 1 + Dummy() Dummy Object >>> Dummy() -1 Dummy Object >>> dummy = Dummy() >>> dummy ** 22 and dummy / dummy Dummy Object >>> dummy * 69 or dummy // dummy == "Anything" Dummy Object >>> list(Dummy()) >>> for i in Dummy():print i Dummy Object >>> Dummy() Dummy Object >>> Dummy() Dummy Object >>> 8 in Dummy() True >>> dict(Dummy()) {Dummy Object: Dummy Object} >>> str(Dummy()) 'Dummy Object' >>> Dummy() %(1, "Gustavo Rezende", 2.8) Dummy Object >>> int(Dummy()) 1 >>> float(Dummy()) 1.0 >>> bool(Dummy()) True >>> del dummy.anything >>> isinstance(Dummy(), str) FalseStubsStubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. >>> from ludibrio import Stub >>> with Stub(repr='Greetings') as greetings: ... greetings.excuse_me() >> 'Com licença' ... greetings.hello('Gustavo') >> 'Ola, Gustavo' ... greetings.outrohello('Gustavo') >> 'Oi, Gustavo' ... greetings.hello('Gustavo', 'Diego') >> 'Ola, Gustavo e Diego' ... greetings.see_you_soon >> 'Até logo' >>> print greetings.hello('Gustavo') Ola, Gustavo >>> print greetings.excuse_me() Com licença >>> print greetings.hello('Gustavo') Ola, Gustavo >>> print greetings.outrohello('Gustavo') Oi, Gustavo >>> print greetings.outrohello('Gustavo') Oi, Gustavo >>> print greetings.hello('Gustavo') Ola, Gustavo >>> print greetings.see_you_soon Até logo >>> greetings Greetings >>> print greetings.hello('Gustavo', 'Diego') Ola, Gustavo e Diego >>> print greetings.hello('Gustavo') Ola, Gustavo >>> print greetings.executAnythingAndReturnDummyObject() Dummy Object >>> greetings + 171 - greetings * 22 Dummy Object >>> with Stub() as count: ... count() >> 1 ... count() >> 2 ... count() >> 3 >>> count() 1 >>> count() 2 >>> count() 3 Requirements: · Python


ludibrio Related Software