Skip to main content

for "Behavior Driven Development" (BDD) -- a client-facing scripting language to put the squeeze on all your features

Project description

Wheel Status Latest Version License Build status Coverage Documetation

Morelia viridis is a Python Behavior Driven Development platform, conceptually derived from Ruby’s Cucumber Framework.

Mascot:

http://www.naturfoto.cz/fotografie/ostatni/krajta-zelena-47784.jpg

Installation

sudo pip install Morelia

Quick usage guide

Write a feature description:

# calculator.feature

Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers

Scenario: Add two numbers
    Given I have powered calculator on
    When I enter "50" into the calculator
    And I enter "70" into the calculator
    And I press add
    Then the result should be "120" on the screen

Create standard python’s unittest and hook Morelia into it:

# test_acceptance.py

import unittest

from morelia import run


class CalculatorTestCase(unittest.TestCase):

    def test_addition(self):
        """ Addition feature """
        filename = os.path.join(os.path.dirname(__file__), 'calculator.feature')
        run(filename, self, verbose=True, show_all_missing=True)

Run test with your favourite runner: unittest, nose, py.test, trial. You name it!

$ python -m unittest -v test_acceptance  # or
$ nosetests -v test_acceptance.py  # or
$ py.test -v test_acceptance.py  # or
$ trial test_acceptance.py  # or
$ # django/pyramid/flask/(place for your favourite test runner)

And you’ll see which steps are missing:

F
======================================================================
FAIL: test_addition (test_acceptance.CalculatorTestCase)
Addition feature
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_acceptance.py", line 45, in test_addition
    run(filename, self, verbose=True, show_all_missing=True)
  File "(..)/morelia/__init__.py", line 22, in run
    return ast.evaluate(suite, **kwargs)
  File "(..)/morelia/grammar.py", line 31, in evaluate
    feature.evaluate_steps(matcher_visitor)
  File "(..)/morelia/grammar.py", line 76, in evaluate_steps
    self._method_hook(visitor, class_name, 'after_')
  File "(..)/morelia/grammar.py", line 85, in _method_hook
    method(self)
  File "(..)/morelia/visitors.py", line 125, in after_feature
    self._suite.fail(to_docstring(diagnostic))
AssertionError: Cannot match steps:

    def step_I_have_powered_calculator_on(self):
        r'I have powered calculator on'

        raise NotImplementedError('I have powered calculator on')

    def step_I_enter_number_into_the_calculator(self, number):
        r'I enter "([^"]+)" into the calculator'

        raise NotImplementedError('I enter "20" into the calculator')

    def step_I_press_add(self):
        r'I press add'

        raise NotImplementedError('I press add')

    def step_the_result_should_be_number_on_the_screen(self, number):
        r'the result should be "([^"]+)" on the screen'

        raise NotImplementedError('the result should be "140" on the screen')

----------------------------------------------------------------------
Ran 1 test in 0.029s

Now implement steps with standard TestCases that you are familiar:

# test_acceptance.py

import unittest

from morelia import run


class CalculatorTestCase(unittest.TestCase):

    def test_addition(self):
        """ Addition feature """
        filename = os.path.join(os.path.dirname(__file__), 'calculator.feature')
        run(filename, self, verbose=True, show_all_missing=True)

    def step_I_have_powered_calculator_on(self):
        r'I have powered calculator on'
        self.stack = []

    def step_I_enter_a_number_into_the_calculator(self, number):
        r'I enter "(\d+)" into the calculator'  # match by regexp
        self.stack.append(int(number))

    def step_I_press_add(self):  # matched by method name
        self.result = sum(self.stack)

    def step_the_result_should_be_on_the_screen(self, number):
        r'the result should be "{number}" on the screen'  # match by format-like string
        self.assertEqual(int(number), self.result)

And run it again:

$ python -m unittest test_acceptance

Feature: Addition
    In order to avoid silly mistakes
    As a math idiot
    I want to be told the sum of two numbers
Scenario: Add two numbers
    Given I have powered calculator on                       # pass  0.000s
    When I enter "50" into the calculator                    # pass  0.000s
    And I enter "70" into the calculator                     # pass  0.000s
    And I press add                                          # pass  0.001s
    Then the result should be "120" on the screen            # pass  0.001s
.
----------------------------------------------------------------------
Ran 1 test in 0.028s

OK

Note that Morelia does not waste anyone’s time inventing a new testing back-end just to add a layer of literacy over our testage. Steps are miniature TestCases. Your onsite customer need never know, and your unit tests and customer tests can share their support methods. The same one test button can run all TDD and BDD tests.

Look at example directory for a little more enhanced example and read full documentation for more advanced topics.

Documentation

Full documentation is available at http://morelia.readthedocs.org/en/latest/index.html

http://zeroplayer.com/images/stuff/sneakySnake.jpg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Morelia-0.4.2.tar.gz (36.1 kB view details)

Uploaded Source

Built Distribution

Morelia-0.4.2-py2.py3-none-any.whl (39.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file Morelia-0.4.2.tar.gz.

File metadata

  • Download URL: Morelia-0.4.2.tar.gz
  • Upload date:
  • Size: 36.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Morelia-0.4.2.tar.gz
Algorithm Hash digest
SHA256 87ee922c39482b90465f307fa03e22430fb223cb4bc0e8d448be97f6152e1fb3
MD5 94e6292317e45113ef3c138c063ce604
BLAKE2b-256 1b6d6a21d223ad0db06a0d0832e70addef73a8e3f7ac920c7e7b1c191bb8a30b

See more details on using hashes here.

File details

Details for the file Morelia-0.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for Morelia-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fdcef49d1b3ce75f516f4e33b6852f7c3b4af498576351b76e198a7c19f9a0d4
MD5 db5c1a4ea30041f4b969c3d4fb78ccfc
BLAKE2b-256 9a2401a11d8a49e2c40a56d2e29e0364159be21927f2acb14f278df6b2f4c8f3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page