Well House Consultants
You are on the site of
Well House Consultants
Open Source Training Courses
hotel accommodation. You are welcome to browse and use
our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Well House Manor Resources
Object Orientation and General topics
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
C and C++ Resources
Web and Intranet Resources
Python module Y212
Code testing, patterns, profiles and optimisation.
Exercises, examples and other material relating to training module Y212. This topic is presented on public courses Learning to program in Python
, Python Programming
Robust, reusable and maintainable code is critical to any software project, and at the
heart of achieving these goals are validation and testing systems, standardised and shared
code, and the use of design patterns, utility methods, common libraries, and code coverage checkers.
|Articles and tips on this subject||updated|
|4090||Test Driven Development in Python - Customer Comes First|
The Customer comes first!
When you're writing code, you should be thinking of your user. That may be your end user or - if you're writing a module or classes - that might be a fellow developer, set of developers or even yourself. Whichever it is, the important thing is to get it right for them. It ...
|3658||Using Make for a distribution|
Although Make has traditionally been used to build C and C++ programs, its uses are far wider - here's a new example in which I've used it to test a whole series of Python programs, and if they all test correctly to build a distribution (tar) file.
Scenario - three Python programs / classes for distribution. ...
|3478||Testing your Python classes with the unittest package - how to|
Python's unittest module - supplied within the base distribution - allows you to define and run a series of tests for a class or group of classes, and correlate the results, reporting any transgressions in a standard format without having the whole test sequence break.
Testing your code and obtaining ...
|1140||Python GTK - Widget, Packing, Event and Feedback example|
Python has a variety of GUIs available ... one of which, GTK, has been getting much more popular of late. As is common with many of the GUIs in Pyton and other languages, you'll typically write an application as follows:
Initial code, definingWidgetsLayout (Geometry)EventsA main loop, which collects ...
|3464||Passing optional and named parameters to python methods|
When you call a named block of code (a method or function), you'll wish to pass in originating values that are changed from one call / use to the next - these are commonly known as the parameters. If I'm calling a function to calculate the area of a rectangle, for example, I would pass in the width ...
|3442||A demonstration of how many Python facilities work together|
Many of our demonstrations on the Well House Consultants site show individual features of a language - taken in isolaion to show you how they work. However, during a course we usually write further examples to show you how features work in combination to give a total result / solution to an application.
|3441||Pressing ^C in a Python program. Also Progress Bar.|
If you want to stop a user interrupt via ^C aborting your program, you can catch a KeyboardInterrupt in Python. There's an example [here] which I wrote earlier today. It also shows how important it might be to use two try/except blocks rather than one - I've specified two inputs in the same block and, ...
|2616||Defining a static method - Java, Python and Ruby|
Most methods in classes that your write will be run on / applied to individual objects within that class - you'll be asking for the colour of a marker pen, or setting the price of a hotel room. You will NOT - typically - have a model in which all marker pens share the same colour.
But - just occasionally ...
|2123||Using Python with OpenOffice|
The Python-UNO bridge can be used to call up pieces of Python code from within OpenOffice. The source code of a "hello world" example can be found at http://wiki.services.openoffice.org/wiki/PyUNO_bridge, showing you how to start OpenOffice looking for a connection on a TCP/IP port, and then how to ...
|1555||Advanced Python, Perl, PHP and Tcl training courses / classes|
This item is adapted from an answer that I have just written by email - but the question / conundrum as to what to do with fractured advanced training requirements is a common one, so the answer is worth wider sharing. I believe that our solution provides an innovative way of meeting advanced requirements ...
|1146||__new__ v __init__ - python constructor alternatives?|
The constructor you'll normally override (and call when you create an object) in Python is called __init__, but there is also a method called __new__ available to the class author.
If __new__ is defined on a class, it is called in preference to __init__
With __new__ you return the object you have constructed, ...
|1148||Python decorators - wrapping a method call in extra code|
Would you like to add an extra set of wrappers around a series of function of method calls - perhaps to add a profiler or logger to your application? These are examples of the things you can do with Python's decorators, introduced (with the syntax I'll show you below) in Python 2.4.
Here's a class ...
|235||Preparation for a day's work|
Yes, I'm writing "The Horse's Mouth" very late today. It was one of those days where the early morning before the trainees arrived leaked away like water between my fingers, and sending the PHP examples that yesterday's trainees wrote on to them and getting ready for today's tailored advanced Python ...
Examples from our training material
|annie.py|| Test driven exercise|
|dec01|| decorator - to log function calls|
|dt.py|| doctest - a clean example|
|dta.py|| doctest - a longer example|
|dtf.py|| doctest - an example that triggers a failure report|
|first.py|| Test program for use in build demonstration - first principles|
|hound.py|| Object definitions for profiler desmonstration|
|makefile|| Makefile - for a python test and build distribution project|
|mtbf.py|| MTBF class - overwrides + and *, and associated unittest|
|profdemo.py|| How to run the profiler|
|second.py|| Test program for use in build demonstration - with doctest|
|staboth|| Static Method in Python (classmethod - all versions)|
|stameth|| Static Method in Python (all versions)|
|stawithat|| Static Method in Python (Decorator - 2.4 and later)|
|stawrong|| bound method running on a class FAILS|
|tdd_0|| Test Driven Development - step 1|
|tdd_1|| Test Driven Development - multiple objects|
|tdd_2|| Test Driven Developemnt - using unittst|
|tdd_3|| Test Drive Developement - extending unit testing|
|thems.py|| Polymorphism demonstration - used to demonstrate the profiler|
|third.py|| Test program for use in build demonstration - with unittest|
|transport.py|| Sample class - Test Driven Development|
|travel.py|| inheritance, factory, decorator, comparators, static methods, caching, etc|
|trytravel|| unittest for travel.py classes|
|utes.py|| Simple unittest demonstration|
|utes2.py|| unittest nesting demonstration|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
Topics covered in this module
Factories and Comparators.
Unittest and Doctest.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.