Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install expecter

How to install expecter

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install expecter
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.2.1
0.2.2Never BuiltWhy not?
0.2.1 Available View build log
0.2 Available View build log
0.1.3 Available View build log
Windows (64-bit)
0.2.1
0.2.2Never BuiltWhy not?
0.2.1 Available View build log
0.2 Available View build log
0.1.3 Available View build log
Mac OS X (10.5+)
0.2.1
0.2.2Never BuiltWhy not?
0.2.1 Available View build log
0.2 Available View build log
0.1.3 Available View build log
Linux (32-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.2 Available View build log
0.1.3 Available View build log
Linux (64-bit)
0.2.2 Available View build log
0.2.1 Available View build log
0.2 Available View build log
0.1.3 Available View build log
 
License
BSD
Imports
Lastest release
version 0.2.2 on Nov 28th, 2012

BASICS

Expecter Gadget helps you to write assertions. Never again will you forget which is expected and which is actual!

Basic expectations are easy:

>>> from expecter import expect
>>> expect('some' + 'thing') == 'something'
expect('something')
>>> expect(1) > 100
Traceback (most recent call last):
...
AssertionError: Expected something greater than 100 but got 1

Just read the expectations like a sentence. "expect(2) == 1 + 1" reads as "Expect 2 to equal 1 + 1". Obviously, the expectation is about 2, and it's being compared to 1 + 1. No ambiguity!

EXCEPTIONS

Expectations about exceptions use the "with" statement. Everything is good if the expected exception is raised:

>>> from __future__ import with_statement
>>> with expect.raises(KeyError):
...     {}[123]

If it's not raised, Expecter Gadget will raise an AssertionError:

>>> with expect.raises(KeyError):
...     pass
Traceback (most recent call last):
...
AssertionError: Expected an exception of type KeyError but got none

Exceptions that don't match the expected one will not be swallowed, so your test will error as you expect:

>>> from __future__ import with_statement
>>> with expect.raises(NameError):
...     {}[123]
Traceback (most recent call last):
...
KeyError: 123

CUSTOM EXPECTATIONS

You can add a custom expectation with the add_expectation method. You give it a predicate that should return true if the expectation succeeds and false if it fails. All expectation objects will grow a method with the name of your predicate method (so don't use a lambda). Appropriate exception messages will be generated when your predicate fails:

>>> import expecter
>>> def can_meow(thing):
...     return thing == 'kitty'
>>> expecter.add_expectation(can_meow)
>>> expect('kitty').can_meow()
>>> expect('puppy').can_meow()
Traceback (most recent call last):
...
AssertionError: Expected that 'puppy' can_meow, but it can't

Subscribe to package updates

Last updated Nov 28th, 2012

Download Stats

Last month:9

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.