Giter VIP home page Giter VIP logo

pyspecs's Introduction

pyspecs - Minimalistic BDD in Python

Build Status

pyspecs is a testing framework that strives to achieve more readable specifications (tests) by leveraging some fancy syntactic sugar and auto-discovery of tests/specs. WARNING: version 2.0 introduces breaking changes if you've been using 1.0 or 1.1.

Installation is straightforward:

$ pip install pyspecs

or...

$ easy_install pyspecs

or...

$ git clone https://[email protected]/mdwhatcott/pyspecs.git
$ cd pyspecs
$ python setup.py

Assertions

The main tool for verifying behavior is an assertion of some kind. The simplest assertion can be made by using the built-in assert statement:

assert 42 == 'The answer the life, the universe and everything'

For readability this project provides a more fluent method for making assertions:

# These imported names are all synonyms for the class that
# provides fluent assertions (Should). Use whichever provides
# the best readability.  The general patter is:
# >>> the([value]).should.[condition_method]([comparison_args])
#  or...
# >>> the([value]).should_NOT.[condition_method]([comparison_args]) # negated!

from pyspecs import the, this, that, it


this(42).should.equal(42) # this passes

this([1, 2, 3]).should.contain(2) # this also passes

the(list()).should.be_empty() # passes

it(1).should_NOT.be_greater_than(100) # passes

# raises AssertionError, caught by framework, logged as failure
that(200).should.be_less_than(0)

Writing complete specs

from pyspecs import given, when, then, and_, the


with given.two_operands:
    a = 2
    b = 3

    with when.supplied_to_the_add_function:
        total = a + b

        with then.the_total_should_be_mathmatically_correct:
            the(total).should.equal(5)

        with and_.the_total_should_be_greater_than_either_operand:
            the(total).should.be_greater_than(a)
            the(total).should.be_greater_than(b)

    with when.supplied_to_the_subtract_function:
        difference = b - a

        with then.the_difference_should_be_mathmatically_correct:
            the(difference).should.equal(1)

    # cleanup is just based on scope
    del a, b, total, difference

Notice that the names of each step are supplied as dynamic attributes of the given, when, then, and and_ step keywords. These user-created attributes are used in the output (below). Here is a listing of words that can be used as steps:

  • given
  • provided
  • when
  • then
  • and_
  • so
  • therefore
  • however
  • as_well_as

These steps can be arranged in any order and hierarchy for compose a specification (spec). You can even create your own steps that suit your needs (see the source code for how that's done).

Execution of specs

Beyond providing the python library which will be explained below, installation provides a command-line script into the environment, meant to be invoked from the root of your project. The script will execute all specs in .py files ending in 'test.py' or 'tests.py' or beginning with 'test'.

To run all tests once:

$ run_pyspecs.py

To begin an auto-test loop (runs all specs anytime a .py file is saved):

$ run_pyspecs.py -w

Complete Example

There are some complete examples of specs, code, and output in the examples folder.

pyspecs's People

Contributors

magmax avatar mdwhatcott avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyspecs's Issues

pip install pyspecs fails

Hi.
I know that it was corrected in master but version used by pip still has print problem:
pip install pyspecs
Collecting pyspecs
Downloading pyspecs-2.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\WINDOWS\TEMP\pip-build-ua7ehn77\pyspecs\setup.py", line 2, in
import pyspecs
File "C:\WINDOWS\TEMP\pip-build-ua7ehn77\pyspecs\pyspecs_init_.py", line 3, in
from pyspecs._reporting import ConsoleReporter
File "C:\WINDOWS\TEMP\pip-build-ua7ehn77\pyspecs\pyspecs_reporting.py", line 61
print problem
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\WINDOWS\TEMP\pip-build-ua7ehn77\pyspecs\

I use Python 3.6.0

Live step name reporting

Right now a scenario is reported only after successful completion of the entire scenario. If there is an error or a failure it is held back until the end of the run to be displayed with any other problematic scenarios. I'm thinking I need to display the step as it is being run. This becomes apparent only when running integration tests that run slowly and it's a pain to have to wait until the end to see what went wrong.

pip3 install pyspecs fails

apparently it uses 2.x version of a lib because the error message is:
Collecting pyspecs
Downloading pyspecs-2.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-v9a13ynw/pyspecs/setup.py", line 2, in
import pyspecs
File "/tmp/pip-build-v9a13ynw/pyspecs/pyspecs/init.py", line 3, in
from pyspecs._reporting import ConsoleReporter
File "/tmp/pip-build-v9a13ynw/pyspecs/pyspecs/_reporting.py", line 61
print problem
^
SyntaxError: Missing parentheses in call to 'print'

No UTF-8 characters in the output

I want to use characters from Polish alphabet in the step descriptions but they aren't displayed on the output, -- are displayed instead of Polish letters, eg.
| โ€ข given email E2 zosta-- u--yty do rejestracji
When I print the same string using python print function I get Polish letters.
I use Windows 10, Python 3.6

License?

Hi, I wasn't able to find a license in here anywhere. People need one in order to be able to use this!

The MIT license is often a good choice.

Thanks!

Incorrect example (maybe)

Hi! Very new to this project.

In fizzbuzz.pyspecs I see statements like this:

with given('the number 2, which is not divisible by 3 nor 5'):

But that style gives an error in my local tests. Is it something new/old?

Integration with existing python test runners (unittest, nose etc)

Howdy, love what you're going for here, would love to use it with my existing unittest.TestCase based test suite.

It occurs to me that it would be possible to implement your dsl / semantics on top of unittest.TestCase such that specs could happily co-exist with test cases.

Love to hear your thoughts,
Luke

A small enhancement to the pyspecs syntax

I love pyspecs!

I also love the syntax highlighting in my code editor.

So I have written 3 functions (pyspecs_extensions) that alllow me to use pyspecs with clearer and more colorful syntax. This makes for better readability (in my opinion at least).

pyspecs

I am putting this here because I want to share this with the pyspecs community and thought maybe you'd be interested in this as an enhancement to this otherwise excellent project.

Nose 2 compatibility

Nose is the most used test runner. It allows lots of things, so I think it doesn't worth it to write another new, with coverage, etc.

They are moving to nose2 (still under development), but it is quite easy to write a plugin for it. This will allow us to use pyspecs with coverage, other reporting systems (like xml, useful for automatic processes) without any work.

This issue may require some changes in the code, in order to split the repoting and execution in two different plugins or maybe add configuration options to allow it.

Need to flush stdout for darwin

The reporter needs to call .flush() each time output is received. For some reason, python on mac doesn't like to flush to the console very often.

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.