easy

This section is currently unfinished and will be updated further!

The easy module is a collection of simple tools to help you with common programming tasks:

  • test() - Check if your functions are working correctly

  • SQL - Work with databases easily

Installation

Save the easy.py file in the same folder as your Python programs. Click here to download it.

If the file opens in your browser instead of downloading, right-click the link and choose “Save Link As”.

Importing

At the top of your Python file, import what you need:

1from easy import test          # Just for testing
2from easy import SQL           # Just for databases
3from easy import test, SQL     # For both

test()

Basic Usage

1from easy import test
2
3def add(a, b):
4    return a + b
5
6test(add(2, 3), 5, "Adding 2 and 3")
7test(add(10, 15), 26, "Adding 10 and 15")
Show Output
✓ PASS: Adding 2 and 3
✗ FAIL: Adding 10 and 15
Expected: 26
Got:      25

What You Need

  1. Your function call - call your function with the inputs you want to test

  2. Expected output - what you think the function should return

  3. Test name (optional) - a description to help you know which test failed

  4. Tolerance (optional) - for decimal numbers, how close is close enough (default is 0.0001)

Testing Decimal Numbers

When testing functions that return decimal numbers (floats), the test() function automatically handles small differences caused by how computers store decimals:

1def add(a, b):
2    return a + b
3
4# This works even though 0.1 + 0.2 doesn't exactly equal 0.3 in Python!
5test(add(0.1, 0.2), 0.3, "Adding decimals")
Show Output
✓ PASS: Adding decimals