Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business 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
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk 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

Background
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 subjectupdated
4090Test 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 ...
2013-05-18
 
3658Using 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. ...
2012-03-17
 
3478Testing 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 ...
2011-10-14
(longer)
1140Python 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 ...
2011-10-13
 
3464Passing 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 ...
2011-10-04
 
3442A 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. On ...
2011-09-16
(longest)
3441Pressing ^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, ...
2011-09-16
 
2616Defining 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 ...
2010-02-01
 
2123Using 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 ...
2009-04-10
 
1555Advanced 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 ...
2008-02-27
 
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, ...
2007-04-18
 
1148Python 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 ...
2007-04-15
 
235Preparation 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 ...
2006-06-05
(short)
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
Background information
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
Decorators.
Static Methods.
Factories and Comparators.
Unittest and Doctest.
The Profiler.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses 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.


You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/resources/Y212.html • PAGE BUILT: Wed Mar 6 10:39:20 2013 • BUILD SYSTEM: wizard