Python is a multi-paradigm language meaning it supports different programming styles, Object Orientation and Functional Programming being the major ones. However choice is not always a good thing, if you are interested in writing modular programs that are easy to maintain and promote code reuse what should you do? This talk discusses modularity in this context looking at Python's support for both paradigms, comparing and contrasting them. We then look at Python techniques and tools that bridge the perceived impedance mismatch between Object Orientation and Functional Programming.
Specific extensions to unittest, and Django's built-in test runner, illustrate the hacksHHHH^H techniques Python offers us to augment existing classes, especially when extending in directions which were not anticipated by the original classes' authors.
The specific augmentations demonstrated are:
Getting the Django test runner to look for tests in all project directories, rather than just in each app's models.py and tests.py. (Simple inheritance and method overriding)
Filtering out the screens full of verbose output produced by Django when setting up test databases, without losing any unexpected output that might be important. (patching stdout with a filtering stream.)
An alternate method of printing test names when verbosity=2, that is simultaneously more compact and easier to read. (Changing output for human-factors while leaving underlying functionality unaffected)
Colored output - scroll back through a verbose test run and instantly see skips, expectedFails, as well as fails and errors. (When you have to resort to wholesale cut-and-paste - what causes this, and what changes could authors of libraries like unittest do to help prevent users from having to do this.)
Turning off the display of test docstrings instead of test names, since this has a negative effect on the naming of tests.
Enabling code coverage during the test run, no matter what method of running tests you use.
Extending the report printed at the end of a test run to list skipped tests and their reasons for skipping, after the errors and fails. No longer be in the dark about why your test run contained skipped tests.
A way of combining these diverse extensions so that users can choose to enable or disable specific features (generate classes at runtime with dynamic composition.)
See slides and source code at https://github.com/tartley/exten...
I built a game where people can play against each other in real-time using sockets (WebSockets and Flash sockets). Talk will describe how the game works, the tools used and various tips and best practice advice for people interested in doing something with sockets and using Python as the back end.
24th–25th September 2011