Git Product home page Git Product logo

doublex-expects's Introduction

Jaime Gil de Sagredo Luna

Passionate about building high-quality software products that deliver value to users. With a focus on fast, iterative and user-driven development, I specialize in developing both MVPs and long-term products using cost and time sustainable processes.

My core practices and experience encompass a wide range of methodologies, including eXtreme Programming, Simple Design, Lean and DevOps. I am well-versed in Test-Driven Development (TDD), Domain-Driven Development (DDD), and Hexagonal architecture, which enable me to build robust and scalable software solutions.

I can help your company, startup, or software development team build high-quality software products that satisfy your users needs. Whether it's through crafting new products, iterating your existing products, or guiding and mentoring your development team to improve their skills and capabilities.

Contact me to schedule a meeting or find more about me at: LinkedIn, Twitter or my personal page.

doublex-expects's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

doublex-expects's Issues

Allow to compose matchers in have_been_called_with

Doublex builtin called.with_args can receive another hamcrest matcher to allow more complex assertions.

This is especially useful if you want to test that a method has been called with an argument you don't own.

For example:

stub = Stub()
stub.method(object(foo=1))

expect(stub.method).to(have_been_called_with(have_property('foo', 1)))

`have_been_called_with` matches partially but depending on argument order

Hey! I've a quick question.

This fails:

with it('blows my mind'):
    spy = Spy()
    spy.function(1, 2)

    expect(spy.function).to(have_been_called_with(2))

This doesn't fail:

with it('blows my mind'):
    spy = Spy()
    spy.function(1, 2)

    expect(spy.function).to(have_been_called_with(1))

So, have_been_called_with matches partially if the non-specified arguments come after the specified ones. But if you specify a certain argument and the spy function gets called with some arguments before the one you specified, that matcher fails.

Is this intentional? I always thought have_been_called_with performed a partial match (that is, ignoring extra arguments), no matter the relationship between the order of the arguments to the actual call, and the order of the arguments specified in the matcher. In other words, I'd expect both the examples above to pass.

Thank you!

How to use have_been_called_with(a(str))?

The README mentions:

expect(my_spy.method).to(have_been_called_with(a(str), key=match('\w+')))

But I'm not sure what to import a from. Neither doublex, doublex-expects or expects has a a name to export.

have been satisfied in any order fails

The matcher have_been_satisfied_in_any_order does not work correctly for all cases.

Failing example

    with it('passes if mock methods have been called in another order FAILS'):
        with doublex.Mock() as mock:
            mock.the_first_function_foo(1)
            mock.the_second_function_bar()

        mock.the_second_function_bar()
        mock.the_first_function_foo(1)

        expect(mock).to(have_been_satisfied_in_any_order)

"Partial mock satisfy"?

Hey there,

Currently, have_been_satisfied fails when the prepared invocations do happen, but some others happen as well. That is, the following raises AssertionError:

with Mock() as mock:
  mock.attribute

mock.attribute
mock.another_attribute

expect(mock).to(have_been_satisfied)

Can we have a matcher which would make this pass? That would make it behave similarly to the way have_been_called_with works on spies (verifying that methods are called with at least the specified arguments [at least, if the extra arguments come before the specified ones, see #13]).

Changing the current have_been_satisfied to this behaviour may break somebody: although all cases where that matcher now passes would still pass with the new behaviour, somebody may be expecting failures when the invocations do not match exactly, and since that would not be a failure with this behaviour, those tests would break.

Error trying to test that a spy method has been called with an empty stub/spy as argument

some_object = Stub()
my_spy = Spy()

my_spy.method(some_object)

expect(my_spy.method).to(have_been_called_with(some_object))

raises:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/expects/expectations.py", line 19, in to
    self._assert(matcher)
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/expects/expectations.py", line 23, in _assert
    raise AssertionError(self._failure_message(matcher))
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/expects/expectations.py", line 35, in _failure_message
    )(self._subject)
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/expects/matchers/__init__.py", line 103, in _failure_message
    subject=subject, description=self._description(subject))
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/doublex_expects/matchers.py", line 120, in _description
    message += ' with {}'.format(plain_enumerate(self._args, self._kwargs))
  File "/home/jgil/.virtualenvs/felix/local/lib/python2.7/site-packages/expects/texts.py", line 29, in plain_enumerate
    result += token
TypeError: cannot concatenate 'str' and 'NoneType' objects

This is caused because an empty stub passes this conditional: https://github.com/jaimegildesagredo/expects/blob/master/expects/texts.py#L14

Incompatibility between expect and doublex-expects

Doublex-expects version 0.6.0 is not compatible with expects versions >= 0.6.0

Steps to reproduce:

git checkout 01e1013368df25eaea1559ad87534a10bd307e70
pip install -r requirements.txt
pip install -r test-requirements.txt
mamba

Hint

Maybe placing in the requirements.txt that expects>=0.6.0,<="last_compatible_version"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.