The Test Framework

Throughout this workshop we’ll be using a test framework to check your code. Here’s what you need to know to make it all work.

Download exercise test files. When unzipped, it should create a new folder called exercises. It contains the test framework we will be using, so you will be working from this folder.

Where to write your code

At the beginning of each exercise you’ll see a note describing where to find it. The exercises will be functions you’ll write or modify in the existing .py files in the exercises directory. It’s important that you write your code in the right place, or the tests won’t work.

How to run the tests

Once you’ve written your code and you’re ready to test it, we will use Python to run test.py followed the name of the exercise in your command prompt. Always type these commands from the exercises directory. The test framework knows where to find the files you tell it to test.

How you run this at the terminal will depend on your operating system and which version(s) of Python you have installed.

If you only have one version of Python installed, you can run the tests (for exapmle) for the get_vowel_names exercise in lists.py like this:

Linux/Mac terminal:

$ python test.py get_vowel_names

Windows command window:

> py test.py get_vowel_names

If you have more than one version of Python installed, you’ll need to specify Python 2.7 like this:

Linux/Mac terminal:

$ python2.7 test.py get_vowel_names

Windows command window:

> py -2.7 test.py get_vowel_names

Passing the Tests

If your code has passed the tests, you’ll see some variation of this message:

Testing get_vowel_names

...
----------------------------------------------------------------------
Ran 3 tests in 0.001s

OK

Getting Help

You can also type python test.py (or python2.7 test.py or py -2.7 test.py) by itself, to see helpful documentation.

Please select a thing to test

atbash_cipher:

decode: Return string of each character decoded.
encode: Decode each letter and group into 5-letter words.

lists:

flatten: Return a flattened version of the given 2-D matrix (list-of-lists).
get_vowel_names: Return a list containing all names given that start with a vowel.
...