Skip to main content

checkexpect is a simple unit testing framework for python development

Project description

versiondownloads

checkexpect is a simple unit testing framework for python development https://pypi.python.org/pypi/checkexpect in a python library. checkexpect is a mature, viable way to make your test-driven development drive the design of your data, and your data drive the design of your functions. It’s also a simple tool that allows you to execute unit tests inline with your code, in a systematic way.

This is a fork of the original checkexpect, hosted on GitHub and last updated in 2016.

Features

  • [x] Support for inline unit tests. checkExpect will support tests created in another directory as well.

  • [x] Support for TDD and DDD development.

  • [x] Support for Systematic Program Design methods using HtDD and HtDF recipes.

  • [x] Support for color coded terminal (console) output.

TODO

  • [ ] Python 3.5 support.

Installation

  1. Install checkexpect.

    pip install checkexpect
  2. Now you can now add a reference to the checkexpect package like so.

    #!/usr/bin/env python
    
    # import package
    from checkexpect.core import checkExpect
  3. Write some code and test it using checkexpect inline with your code.

    #!/usr/bin/env python
    
    # import packages
    from checkexpect.core import checkExpect
    import math
    
    # Usage: checkExpect(function|object|type, param, expected value, "a description of the test")
    
    # define a function
    def square(a):
      return a * a                    # could replace return statement with (lambda a: math.pow(a, 2))
                                      # from code_statement_B below.
    # examples
    num_to_square = 12
    code_statement_A = 12 * 12        # used in the function body
    
    # check the algor1thm design of our square function, and unit test it at the same time
    checkExpect(square, 12, 144, "Square of a number")
    
    # Or just pass our examples
    checkExpect(square, num_to_square, code_statement_A, "Square of a number")
    
    # Or use lambda expressions
    code_statement_B = lambda a: math.pow(a, 2)
    checkExpect(square, num_to_square, code_statement_B(12), "Square of a number")
    
    # add up a list of numbers
    
    # examples
    param1 = [1,2,9]
    
    def add(args):
        total = 0
        for i in args:
            total = i + total
        return total
    
    checkExpect(add, param1, 12, "Add two numbers")
    
    # Create a string from an arbitrary list of strings
    
    # examples
    param3 = [ "Darel", "Johnson"]
    def string_together(los):
        newStr = [ str.strip() for str in los]
        return " ".join(newStr)
    
    checkExpect(string_together, param3,"Darel Johnson")
  4. Execute your python script from the command line (terminal) to see the unit test results. Most tests usually fail (RED) in the beginning.

  5. Refactor your code and execute your script until all functions under test, turn GREEN.

  6. That’s it! You’re done.

Upgrades

  1. Upgrade checkexpect.

    pip install checkexpect -U

That command will upgrade an existing installation of checkexpect.

Configuration

None - No configuration needed.

Support

For checkexpect support contact me at mailto:dareljohnson@yahoo.com

License

This project originally started life as javascript unit test project. This project was abandoned in 2013 and was brought back to life as checkexpect by our team in 2016. In the process, most of the project was refactored and brought up to speed with modern python best practices. The work done prior to the 2013 rewrite is licensed under MIT. Improvements since then are licensed under MIT. See LICENSE for more details.

SemVer

This project implements Semantic Versioning .

Credits

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

checkexpect-1.0.19-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file checkexpect-1.0.19-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for checkexpect-1.0.19-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 657d7be4edaa3c71962853d5e0575aa231f57fbc721a5469f2551f4ae4b87026
MD5 1839e22ad589aa3346111706f27ec9d8
BLAKE2b-256 f753894710a4f41896d30aa749c71f33406846fa20e58632f9eabdb9c2b0ae51

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