Skip to content

Instantly share code, notes, and snippets.

@iluxame
Last active August 29, 2015 14:14
Show Gist options
  • Save iluxame/a84aef18d30d573258bb to your computer and use it in GitHub Desktop.
Save iluxame/a84aef18d30d573258bb to your computer and use it in GitHub Desktop.
python game code coverage example
Game setup - woרks with Fedora:
1. Download game:
wget -O ardentryst1.71.tar.gz http://goo.gl/fJnyAs
2. Install Pygame:
Fedora: sudo yum install pygame
3. Untar game:
tar -xzvf ardentryst1.17.tar.gz
4. cd ardentryst1.17
4. install game: sudo ./install.sh
5. Now the hard part:
try to play to check that game is working ok :)
just run sudo ardentryst
Code coverage:
1. Install coverage: sudo yum install -y python-coverage
2. run "coverage debug sys" and check that your env is clean
3. Go to game's directory and create .coveragerc like this one:
[imeerovi@localhost ~]$ cat /usr/share/games/ardentryst/.coveragerc
# .coveragerc to control coverage.py
[run]
branch = True
source = /usr/share/games/ardentryst
data_file = /tmp/ardentryst-coverage-data
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover
# Don't complain about missing debug-only code:
def __repr__
if self\.debug
# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError
# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
ignore_errors = True
[html]
directory = /tmp/coverage_html_report
4. modify sitecustomize file or create it if it is not exists. Please take a look at this example:
[imeerovi@localhost ~]$ cat /usr/lib/python2.7/site-packages/sitecustomize.py
import os
import coverage
os.environ['COVERAGE_PROCESS_START']= "/usr/share/games/ardentryst/.coveragerc"
coverage.process_startup()
5. Run "coverage debug sys" and check that your environment is modified according to .coveragerc parmeters
6. Play game :)
7. Run:
"coverage html --rcfile=/usr/share/games/ardentryst/.coveragerc"
8. See you code coverage:
firefox /tmp/coverage_html_report/index.html
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment