Skip to content

TDD and refactoring sample application written in python

Notifications You must be signed in to change notification settings

Softhouse/gomoku_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gomoku_python

An example application for TDD and refactoring using the board game Gomoku

Setup

You will need to have Python 2.7 installed A good source to learn about Python is the Python Documentation.

Also the packet manager pip is needed. If you have pip installed you should be able to

$ pip --version
pip 9.0.1

Install virtualenv

virtualenv is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

$ pip install virtualenv
$ mkdir tdd_kurs
$ cd tdd_kurs
$ git clone [email protected]:Softhouse/gomoku_python.git 
$ virtualenv my_virtenv

Running virtualenv

Start virtualenv so all dependencies are installed inside it

$ source my_virtenv/bin/activate

After the lab you can quit the virtual environment by

$ deactivate

Install pygame

With virtualenv running, install Pygame

(virt_env)$ pip install pygame

A Pygame cheat sheet explains the code components of Pygame, read it if you are interested. Pygame is necessary to run the game, but not to run the tests.

Run tests

(virt_env)$ python -m unittest test.test_model

Read more on how to create Python unittests

Run game

Run the game through its GUI

(virt_env)$ cd app; python main.py

Lab

When you write code that accesses a token or cell, the order is first row then column throughout the code, for example:

row, col = pos

Code coverage

If you like you can measure Code coverage to see how much of the production code is exercised by the tests.

(my_virtenv)$ pip install coverage

$ python -m coverage --help
Coverage.py, version 4.3.4 with C extension

Run coverage

First check you are in the root of repo

$ ls
README.md	app		my_virtenv	solutions	test

Then run your tests through the tool

$ python -m coverage run -m unittest discover

Create a report

$ python -m coverage html

Then show it in your browser (choose open or web browser name as suitable to your environment)

$ open htmlcov/index.html
$ firefox htmlcov/index.html

To clear between runs, do:

$ python -m coverage erase

About

TDD and refactoring sample application written in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages