Basic Usage

The goal of Should-DSL is to write should expectations in Python as clear and readable as possible, using an “almost” natural language (limited by some Python language’s constraints).

In order to use this DSL, you need to import should and should_not objects from should_dsl module.

import unittest
from should_dsl import should, should_not
from cards_game import Player, Card

class CardsGameExamples(unittest.TestCase):

  def setUp(self):
    self.player = Player('John Doe')

  def test_player_has_initial_number_of_cards(self):
    self.player |should| have(11).cards

  def test_player_has_a_name(self): |should| equal_to('John Doe')

  def test_discard_card(self):
    card = Card('Q', 'spades')
    self.player.hand |should_not| contain(card)

if __name__ == '__main__':
$ python  -v
test_discard_card (__main__.CardsGameExamples) ... ok
test_player_has_initial_number_of_cards (__main__.CardsGameExamples) ... ok
test_player_has_a_name (__main__.CardsGameExamples) ... ok

Ran 3 tests in 0.002s



Should-DSL Matchers: check all available matchers

Predicate Matchers: predicate matchers are the matchers that work with boolean methods and attributes, giving users more freedom to write more readable specifications.

Custom Matchers: extending Should-DSL with custom matchers is very easy. It is possible to add matchers through functions and classes, for simple and complex behaviors.

Contributing: see how you can contribute to Should-DSL development

License: MIT License


Should-DSL can be installed through PyPI, using pip or easy_install.

$ pip install should-dsl
# maybe you need to run it as sudo

Powered by

Table Of Contents

Next topic

Should-DSL Matchers

This Page