Advanced Topics: Biopython

Similar documents
Survey of Unit-Testing Frameworks. by John Szakmeister and Tim Woods

Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Profiling, debugging and testing with Python. Jonathan Bollback, Georg Rieckh and Jose Guzman

New Tools for Testing Web Applications with Python

Python Testing with unittest, nose, pytest

Testing Python. Applying Unit Testing, TDD, BDD and Acceptance Testing

Python as a Testing Tool. Chris Withers

CS 1133, LAB 2: FUNCTIONS AND TESTING

Software Testing with Python

CIS 192: Lecture 13 Scientific Computing and Unit Testing

Scientific Programming in Python

Python programming Testing

Continuous Integration

Software Testing. Theory and Practicalities

Test Driven Development in Python

Wrestling with Python Unit testing. Warren Viant

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

CME 193: Introduction to Scientific Python Lecture 8: Unit testing, more modules, wrap up

Peach Fuzzer Platform

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Computational Mathematics with Python

Unit Testing webmethods Integrations using JUnit Practicing TDD for EAI projects

Computational Mathematics with Python

Computational Mathematics with Python

Open Source HTTP testing tool. Stefane Fermigier

How to write a bash script like the python? Lloyd Huang. KaLUG - Kaohsiung Linux User Group COSCUP Aug

DevKey Documentation. Release 0.1. Colm O Connor

Self-review 9.3 What is PyUnit? PyUnit is the unit testing framework that comes as standard issue with the Python system.

Unit testing with mock code EuroPython 2004 Stefan Schwarzer p.1/25

ns-3 Testing and Validation


Python for Test Automation i. Python for Test Automation

MarathonITE. GUI Testing for Java/Swing Applications

Chapter 9: Building Bigger Programs

MDSplus Automated Build and Distribution System

How To Develop Software

NaviCell Data Visualization Python API

1001ICT Introduction To Programming Lecture Notes

B&K Precision 1785B, 1786B, 1787B, 1788 Power supply Python Library

Driving a Time-based Simulation from MATLAB for Custom Calculations and Control

9/11/15. What is Programming? CSCI 209: Software Development. Discussion: What Is Good Software? Characteristics of Good Software?

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Python and Google App Engine

Browser Testing Framework for LHG

Main Bullet #1 Main Bullet #2 Main Bullet #3

Running and Scheduling QGIS Processing Jobs

Programming in Python. Basic information. Teaching. Administration Organisation Contents of the Course. Jarkko Toivonen. Overview of Python

Scientific Programming with Python. Randy M. Wadkins, Ph.D. Asst. Prof. of Chemistry & Biochem.

Ruby - A Brief History

The Practical Organization of Automated Software Testing

An Open Source Data Integration Project using Python. Mike Pittaro BayPiggies, September 13, 2007

Continuous Integration/Testing and why you should assume every change breaks your code

Gothenburg Mainframe and Continuous Integration. Jan Marek com. CA Technologies. Session S610

Test Driven Deployment with (i)python and nosetest

This presentation explains how to monitor memory consumption of DataStage processes during run time.

Source Code Review Using Static Analysis Tools

Triple-E class Continuous Delivery

CHAD TILBURY.

Writing robust scientific code with testing (and Python) Pietro Berkes, Enthought UK

Grandstream Networks, Inc. XML Configuration File Generator User Guide

Data Intensive Computing Handout 5 Hadoop

A Pythonic Approach to Continuous Delivery

Continuous Integration. Wellcome Trust Centre for Gene Regulation & Expression College of Life Sciences, University of Dundee Dundee, Scotland, UK

sveltest: A testing language

Introduction to Python for Text Analysis

Working with HPC and HTC Apps. Abhinav Thota Research Technologies Indiana University

Running and Enhancing your own Galaxy. Daniel Blankenberg The Galaxy Team

Python Testing Cookbook

Tutorial. Reference for more thorough Mininet walkthrough if desired

[1] Learned how to set up our computer for scripting with python et al. [3] Solved a simple data logistics problem using natural language/pseudocode.

Introduction to Python

Certified The Grinder Testing Professional VS-1165

rpaf KTl Pen source Plone 3.3 Site Administration Manage your site like a Plone professional Alex Clark

Python 2 and 3 compatibility testing via optional run-time type checking

The Network Backup Solution

Let s Learn Market Mechanism by Artificial Market Attached CD-ROM README file U-Mart project

Introduction to Apache Pig Indexing and Search

Introduction to Python

DE4 NetFPGA Packet Generator Design User Guide

Tutorial 7 Unit Test and Web service deployment

soapui Product Comparison

Data Intensive Computing Handout 6 Hadoop

Chapter 2 Writing Simple Programs

Introduction to Linux operating system. module Basic Bioinformatics PBF

BuildBot. S.Cozzini/A.Messina/G.Giuliani. And Continuous Integration. RegCM4 experiences. Warning: Some slides/ideas.

SOFTWARE TESTING TRAINING COURSES CONTENTS

Computational Statistics: A Crash Course using R for Biologists (and Their Friends)

VIRTUAL MACHINE LOGBOOK

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

BioHPC Web Computing Resources at CBSU

webmunit for WebMethods Integration Server

Professional Plone 4 Development

TESTING FRAMEWORKS. Gayatri Ghanakota

FLeSSR Usecase 1 - Multi Platform Software development

Open Source and Free Tools Workshop

Installing C++ compiler for CSc212 Data Structures

Transcription:

Advanced Topics: Biopython Day Three Testing Peter J. A. Cock The James Hutton Institute, Invergowrie, Dundee, DD2 5DA, Scotland, UK 23rd 25th January 2012, Workshop on Genomics, Český Krumlov, Czech Republic

Talk Outline 1 Why test your code? 2 Testing in Python 3 Testing in Biopython 4 Testing in your code

Why test your code? To make sure it does what you want it do do! Later on, to make sure it still does what you want it do do (e.g. after updating a library) To check changes don t have unexpected side effects

But writing tests wastes time! Yes, writing tests takes time. Sometimes as much as writing the code. BUT, overall they should save you time. Especially if you are doing experimental work based on it. PhD students may have to convince their supervisor...

Writing good tests is hard! Simple tests check a typical case of good input data That is important. You must also test with bad input data Error handling is very important.

Test granularity Big tests might verify the output of a lot of code in one go But if it fails, where is the error? Many little tests can verify each function individually Cause of a failure is usually clear Can be used with test driven development (Aside: Big functions are a bad idea - modularise!)

Testing frameworks in Python There are two main test frameworks included in Python itself, unittest - You write test objects with methods that each run a test http://docs.python.org/library/unittest.html doctest - You write examples within docstring documentation comments http://docs.python.org/library/doctest.html Also the assert statement is useful.

Example: mycode.py Suppose you have module mycode, with a function power: def power( value, exponent ) : answer = 1 for i in range(exponent ) : answer *= value return answer It needs some tests, but also some documentation...

Example with assert def power( value, exponent ) : """ Calculate value^exponent and return i t. """ answer = 1 for i in range(exponent ) : answer *= value return answer assert power( 5, 3) == 125

Built in documentation That triple quoted string at the start of the function is the function s docstring, accessed via help(...) command: >>> from mycode import power >>> help ( power) Help on function power in module mycode: power(value, exponent) Calculate value^exponent and return it.

Example with doctest def power( value, exponent ) : """ Calculate value^exponent and return i t. Example: >>> power(5, 3) 125 """ answer = 1 for i in range(exponent ) : answer *= value return answer import doctest doctest. testmod( verbose = True )

Example with doctest Recall that triple quoted string at the start of the function is the function s docstring, accessed via the help(...) command: >>> from mycode import power >>> help ( power) Help on function power in module mycode: power(value, exponent) Calculate value^exponent and return it. Example: >>> power(5, 3) 125

Example with doctest The docstring can contain doctest strings, real examples of commands and their output like: >>> power(5, 3) 125 Using doctest these examples are run and compared to the expected output.

Limitations with doctest The output is compared as a string - cross platform differences can be a problem Examples of failures don t usually make good documentation. Think of doctest strings as documentation examples that gets tested

Example with unittest import unittest from mycode import power class TestPower( unittest. TestCase ) : #Start tests with special method name test_... def test_squared ( s e l f ) : for x in [1, 2, 10, 12345]: s e l f. assertequal (x*x, power(x, 2 ) ) runner = unittest. TextTestRunner ( verbosity = 2) unittest.main( testrunner=runner, exit=false )

Comments on unittest You can have lots of test methods You can easily test exceptions, see assertraises You can even generate test methods dynamically i.e. Very flexible

Unit testing in Biopython Main modules try to include some doctest examples Most new tests use the unittest framework Some old test scripts work with an expected output file We also have doctest examples in the main tutorial

Nightly testing with Buildbot Some bugs are platform or Python version specific running the tests on one machine often not enough We use BuildBot http://trac.buildbot.net/ See http://testing.open-bio.org/biopython/ Runs tests every night on Linux, Mac OS X, Windows, covering Python 2.5, 2.6, 2.7, 3.1, 3.2, and Jython Some projects run their tests for every commit!

Testing in your code My own code has improved since I started writing tests Unit testing is woefully underused in Bioinformatics Don t trust non-trivial programs without unit tests Please do write tests for your own code! Even standalone single file Python scripts can use doctest and unittest so that s not an excuse.

Testing in your code Write some tests for this power function: def power( value, exponent ) : answer = 1 for i in range(exponent ) : answer *= value return answer Perhaps compare it to Python s built in power operator, >>> print 5**3 125