Changes

0.9.0 (2018-10-25)

Highlights

  • Fix Python 3.7 collections ABC classes deprecation warning. See GH-55 <https://github.com/jaimegildesagredo/expects/pull/55>.
  • Hide expects internals from pytest tracebacks. See GH-51 <https://github.com/jaimegildesagredo/expects/pull/51>.

Backwards-incompatible

  • Dropped Python 2.6 support.

0.8.0 (2016-05-15)

Changes since last stable release:

Highlights

  • New failure messages for matchers. Now its easier to see the reason that caused the assertion failure. For example:

    >>> expect([1, {'foo': 1}]).to(contain(have_key('foo', 2)))
    
    AssertionError:
    expected: [1, {'foo': 1}] to contain have key 'foo' equal 2
         but: item have key 'foo' equal 2 not found
    

Bug fixes

  • Now the failure message for have_key/have_keys is fixed when composed with another matcher. See GH-29.
  • Allow contain, contain_exactly and contain_only matchers to work with dict views (e.g. dict.keys()). See GH-42.
  • Allow contain, contain_exactly and contain_only matchers to work with sets. See GH-38.
  • Show traceback in raise_error when another exception is raised. See GH-41.
  • The equal matcher now uses __ne__ for negated assertions. See GH-40.
  • The not_ matcher now uses the inner matcher _match_negated method to perform a negated assertion.
  • Python 2.6 support.

Backwards-incompatible

Although your assertions should still be working (if are broken, just report an issue), the custom matchers api has been changed. To see an example of how to migrate your custom matchers to the new api you can see the doublex-expects migration.

  • The Matcher._match method now should return a tuple of bool representing the result of the matcher and a list of reasons that explain this result:

    def _match(self, subject):
        if subject:
            return True, ['a reason']
        return False, ['another reason']
    
  • The Matcher._description method was removed. Now, with the change announced above, a matcher description won’t need the subject to describe itself, so the __repr__ magic method will be used instead to describe matchers.

  • The Matcher._match_value method was removed. With the new api it made much less sense so it was removed and the expects.matchers.default_matcher wrapper function was added:

    >>> default_matcher(1)._match(2)
    False, ['was 1']
    

0.8.0rc5 (2016-05-07)

Bug fixes

  • Allow contain, contain_exactly and contain_only matchers to work with dict views (e.g. dict.keys()). See GH-42.
  • Allow contain, contain_exactly and contain_only matchers to work with sets. See GH-38.
  • Show traceback in raise_error when another exception is raised. See GH-41.

0.8.0rc4 (2015-10-14)

Bug fixes

  • Show the correct failure message on negated contain_exactly and contain_only matchers. See GH-33.

0.8.0rc3 (2015-10-07)

Bug fixes

  • The equal matcher now uses __ne__ for negated assertions. See GH-40.
  • The not_ matcher now uses the inner matcher _match_negated method to perform a negated assertion.

0.8.0rc2 (2015-08-14)

Bug fixes

  • Python 2.6 support.

0.8.0rc1 (2015-07-17)

Highlights

  • New failure messages for matchers. Now its easier to see the reason that caused the assertion failure. For example:

    >>> expect([1, {'foo': 1}]).to(contain(have_key('foo', 2)))
    
    AssertionError:
    expected: [1, {'foo': 1}] to contain have key 'foo' equal 2
         but: item have key 'foo' equal 2 not found
    

Bug fixes

  • Now the failure message for have_key/have_keys is fixed when composed with another matcher. See GH-29.

Backwards-incompatible

Although your assertions should still be working (if are broken, just report an issue), the custom matchers api has been changed. To see an example of how to migrate your custom matchers to the new api you can see the doublex-expects migration.

  • The Matcher._match method now should return a tuple of bool representing the result of the matcher and a list of reasons that explain this result:

    def _match(self, subject):
        if subject:
            return True, ['a reason']
        return False, ['another reason']
    
  • The Matcher._description method was removed. Now, with the change announced above, a matcher description won’t need the subject to describe itself, so the __repr__ magic method will be used instead to describe matchers.

  • The Matcher._match_value method was removed. With the new api it made much less sense so it was removed and the expects.matchers.default_matcher wrapper function was added:

    >>> default_matcher(1)._match(2)
    False, ['was 1']
    

0.7.0 (2015-06-26)

Bug fixes

Bug fixes

  • The contain_exactly matcher does not raise an IndexError if the subject list has fewer elements than the expected one. GH-23.

0.7.1 (2015-06-09)

Bug fixes

  • The contain_exactly matcher does not raise an IndexError if the subject list has fewer elements than the expected one. GH-23.

0.7.0 (2015-03-01)

Highlights

  • Added have_len as an alias to have_length.

  • The have_len and have_length matchers can receive another matcher as expected value:

    expect('foo').to(have_len(be_above(2)))
    
  • The contain and contain_exactly matchers now can receive another matchers as arguments:

    expect(['foo', 'bar']).to(contain(be_a(str)))
    expect(['foo', 'bar']).to(contain_exactly(be_a(str), match('\w+')))
    
  • Improved be_a and be_an failure messages.

  • Added the contain_only matcher:

    expect([1, 2]).to(contain_only(2, 1))
    
  • Added the to_not alias for not_to to negate assertions:

    expect(True).to_not(be_false)
    
  • Added the aliases module with matcher aliases useful to compose matchers:

    from expects import *
    from expects.aliases import *
    
    expect([1, 2]).to(contain_exactly(an(int), 2))
    

Backwards-incompatible

  • The failure context manager now uses the end_with matcher as default matcher for failure message instead of the previously used contain matcher. Example:

    >>> from expects.testing import failure
    >>> with failure('foo'):
    ...     raise AssertionError('A foo message')
    AssertionError: Expected message 'A foo message' to end with 'foo'
    
    >>> with failure('message'):
    ...     raise AssertionError('A foo message')
    

0.6.2 (2014-12-10)

Bug fixes

  • Fixed contain_exactly to work with iterable objects. Regression introduced in v0.6.1.

0.6.1 (2014-11-30)

Bug fixes

  • Now the contain and contain_exactly matchers fail with a proper message when used with a non-sequence type. See GH-21.

0.6.0 (2014-11-24)

Highlights

  • Now the raise_error matcher can be used without specifying an exception class for writing less strict assertions:

    expect(lambda: foo).to(raise_error)
    
  • Implemented the Matcher._match_value method to help develop custom matchers that receive another matchers. See the docs for more info.

  • The specs and docs directories are now distributed with the source tarball. See GH-20.

0.5.0 (2014-09-20)

Highlights

  • Now the & and | operators can be used to write simpler assertions:

    expect('Foo').to(have_length(3) & start_with('F'))
    expect('Foo').to(equal('Foo') | equal('Bar'))
    
  • The testing.failure context manager can be used even without calling it with the failure message as argument:

    with failure:
        expect('foo').to(be_empty)
    
  • Also can receive matchers as argument:

    with failure(end_with('empty')):
        expect('foo').to(be_empty)
    

Note

See also backwards-incompatible changes for testing.failure.

Bug fixes

  • The be_within matcher now supports float values.
  • In some places bytes were not being treated as a string type in python 3.

Backwards-incompatible

  • The match matcher now passes if matches a part of the subject string instead of all of it. Previously used the re.match() and now uses re.search(). If your tests depended on this you can migrate them by adding a '^' and '$' at the beginning and end of your regular expression.
  • The testing.failure context manager not longer tries to match regular expressions. Instead you can pass the match matcher with your regexp.

0.4.2 (2014-08-16)

Highlights

  • Added the not_ matcher to negate another matcher when composing matchers.

0.4.1 (2014-08-16)

Bug fixes

  • Now from expects import * only imports the expect callable and built in matchers.

0.4.0 (2014-08-15)

Warnings

This release does not maintain backwards compatibility with the previous version because a new syntax was implemented based on matchers. Matchers have been implemented maintaining compatibility with its equivalent assertions (and those that break compatibility are listed below). For most users upgrade to this version will only involve a migration to the new syntax.

Highlights

  • Improved failure message for have_keys and have_properties matchers.
  • The raise_error matcher now can receive any other matcher as the second argument.

Bug fixes

  • The have_key and have_keys always fail if the subject is not a dict.
  • Fixed contain matcher behavior when negated. See this commit.

Backwards-incompatible

  • The end_with matcher should receive args in the right order and not reversed. See this commit.
  • The to.have and to.have.only assertions have been remamed to contain and contain_exactly matchers.
  • Assertion chaining has been replaced by matcher composition in all places where was possible in the previous version.
  • The testing.failure context manager now only receives a string matching the failure message.

0.3.0 (2014-06-29)

Highlights

Bug fixes

  • Fixes a regression in the raise_error assertion introduced in v0.2.2 which caused some tests to fail. See GH-17 for more info.

0.2.3 (2014-06-04)

Highlights

0.2.2 (2014-05-20)

Bug fixes

  • to.raise_error now works with a non-string object as second arg. See docs for examples.

0.2.1 (2014-03-22)

Highlights

  • Added a testing module with the failure contextmanager.
  • Added a matchers module and the key matcher.

Bug fixes

  • to.have and to.only.have now work properly when actual is a string.

0.2.0 (2014-02-05)

Highlights

  • Added initial plugins support. See plugins docs for more info.
  • The key and property expectations now return a new Expects object that can be used to chain expectations.
  • Now every expectation part can be prefixed with not_ in order to negate an expectation. Ex: expect('foo').not_to.be.empty is the same than expect('foo').to.not_be.empty.
  • Added the only.have expectation to test that the subject only has the given items.

Backwards-incompatible

  • The greater_than, greater_or_equal_to, less_than and less_or_equal_to expectations are renamed to above, above_or_equal, below and below_or_equal.

0.1.1 (2013-08-20)

Bug fixes

  • to.have when iterable items are not hashable (Issue #8).
  • to.have.key weird behavior when actual is not a dict (Issue #10).

0.1.0 (2013-08-11)

Highlights

  • First expects release.