Skip to content
This repository was archived by the owner on Apr 14, 2025. It is now read-only.
/ pyne Public archive

A Simple BDD Testing Framework for python.

License

Notifications You must be signed in to change notification settings

Avvir/pyne

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pyne Testing Framework

Pyne is a BDD style testing framework for Python. It's styled after frameworks for other languages like Mocha, Jasmine, Spectrum, and Rspec.

An example pyne test:

@pyne
def some_file():
    @describe("when two numbers are added together")
    def _():
      @before_each
      def _(self):
        self.calculator = Calculator()

      @it("returns the sum")
      def _(self):
        expect(self.calculator.calculate("22 + 11")).to_be(33)

You can see more examples in the examples folder

Running tests

Run a file

python some_test.py

Run all tests

To run all the tests in a directory, you can use the cli:

./pyne/cli.py

Run only some tests

You can focus on a single test by using @fit instead of @it Or a single describe block by using @fdescribe instead of @describe

Using Test Doubles

Spying

In order to spy on an instances methods:

from pyne.expectations import expect
from pyne.pyne_test_collector import before_each, describe, it
from pyne.test_doubles.spy import stub

from some_module import SomeClass

@describe("SomeClass")
def _():
    @before_each
    def _(self):
        self.class_instance = SomeClass()
        stub(self.class_instance, self.class_instance.some_method)
    
    @it("gets called with something")
    def _(self):
        self.class_instance.some_method("something")
        expect(self.class_instance.some_method).was_called_with("something")

If you need the method to still return something, you scan specify what it returns:

    @before_each
    def _(self):
        self.class_instance = SomeClass()
        stub(self.class_instance, self.class_instance.some_method)
        self.class_instance.some_method.returns("some value")

Contribution / Development

For instructions on how to contribute to Pyne, read CONTRIBUTING.md

About

A Simple BDD Testing Framework for python.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages