Python
PureMVC
Cross-language implementation of the MVC meta-pattern - PureMVC. Supported languages:
- ActionScript 2
- ActionScript 3
- C#
- ColdFusion
- haXe
- Java
- Perl
- PHP
- Python
- Ruby
PowerShell, Tanimoto Coefficient and Programming Collective Intelligence
Programming Collective Intelligence is a great read and very approachable. Toby Segaran’s new book takes you into the world of machine learning and statistics and explains how to draw conclusions about user experience, marketing, personal tastes and human behavior. Toby presents how to use these algorithms to mine sites like Facebook, MovieLens, Delicious, Blogs and […]
The Python (PowerShell?) Challenge
// // found the Python Challenge (direct link HERE). He is using it as a warm up for: The Winter Scripting Games I used his spoiler to get to the second challenge, which was fun. It took me 15 lines of PowerShell to solve it. Good brain candy.
Python / Swig gotcha moving from 2.4 to 2.5
From the python 2.5 release notes:
“On Windows, .DLL is not an accepted file name extension for extension modules anymore; extensions are only found if they end in .PYD.”
Getting Testing Out of The Way: Replacing The Seat
How does one replace a seat when somebody is already sitting in it? In other words, how does one inject mock and testing objects into a mature application that never used any? Help comes in the form of modern dynamic languages that have flashy technologies (IoC, AOP, etc.) downgraded to common citizens. Take a look at Python. A feature allowing a class to be customized during construction is completely decoupled from the class itself and is made very easy to use.
In the following example, a Client will use a connection to access a server. TestTarget is a meta-class that chooses which connection to inject based on current configuration determined by PRODUCTION_MODE variable. It is possible to not only configure an instance before construction, but to instantiate and return a completely different instance, as long as it is usable. For example, it would be possible to replace all instantiations of Client with instantiations of some MockClient class.
#!/usr/bin/env python
PRODUCTION_MODE = False
class ProductionConnection:
def connect(self):
print ‘Production connect’
class TestConnection:
def connect(self):
print ‘Test connect’
class TestTarget(type):
def __init__(clazz, name, bases, dct):
print “Initializing (configuring) class”, name
super(TestTarget, clazz).__init__(name, bases, dct)
if (PRODUCTION_MODE):
clazz.connection = ProductionConnection()
else:
clazz.connection = TestConnection()
class Client:
__metaclass__ = TestTarget
def connect_to_server(self):
self.connection.connect()
if __name__ == ‘__main__’:
c = Client()
c.connect_to_server()
Surprisingly, this code works not only in Python 2.4 for Windows, but also in IronPython, more specifically, in IronPython 1.0 Beta 6. It appears impossible however to define a metaclass for a type created outside of IronPython, or define a global metaclass, which would have opened up many interesting possibilities.
How relevant is this for testing? Admittedly, most mature applications we deal with are not written in modern dynamic languages, and bolting IoC or aspects on top of big C# or Java projects is a complex exercise with less predictable results. It is still feasible I think if large blocks of application, such as external servers, can be replaced by mock objects.
MP3Info.py
Nice to see a little itch I scratched years ago, MP3Info.py, actually still being used. Jon Udell recently posted an article on Audio Linkblogging that used it. It’s also being used by, among others, Xiph.org’s positron project.
Python on .net
Microsoft’s IronPython - python on .net
Updated: The old link seems to have gone away (I think it was an alpha release anyway). The new link is here. It’s been released under shared source.

