Michael Foord, a Python developer and creator of the mock library, writes about Python, testing, and technical writing.
HN links it for his article on why writing a technical book rarely pays off, and for Python posts and cyberpunk folklore.
What do you mean by "usable function literals"? Because Python has them, even if you have to do a bit of work to get them.
def demo (n):
def multiplier (m):
return n * m
return multiplier
x5 = demo(5);
print x5(4)
You can do anything in the inner closure that you might want. The only surprise is scoping - if you want to modify state you need to use a mutable data type because otherwise you'll be instantiating a private variable. But that hoop is easy to handle.
def demo ():
counter = [0]
def increment ():
counter[0] += 1
def peek ():
return counter[0]
return (increment, peek)
(increment1, peek1) = demo()
(increment2, peek2) = demo()
increment1()
increment1()
increment2()
print peek1()
print peek2()
So there. Function literals. They work.
But, you say, you really want anonymous classes? Well look up metaprogramming then. Python really has quite good support for it. There is no trouble creating anonymous classes on the fly with their own attributes, functions, and so on. They can even inherit from each other. http://www.voidspace.org.uk/python/articles/metaclasses.shtml might be a good starting place on this for you.
(Note, I do not recommend metaprogramming unless the solution you make will be reused a lot.)
> They backported the Python 2.7 unittest module to Python 2.4
No, unittest2 is a project by unittest's own maintainer (Michael Foord): http://www.voidspace.org.uk/python/articles/unittest2.shtml
> and included it in Django?
A good thing, short of depending on unittest2 itself (I don't believe Django "accepts" to depend on third-party projects as it's supposed to be self-contained).
unittest2 is a really big improvement over the old unittest, there are new (and better) assertions, improved comparisons (which diff containers on mismatches for instance, and the equality assertions are pluggable), improved fixtures (class and module-level setup and teardown), improved cleanups (separate from teardowns), autodiscovery has finally been included and is pluggable (you can override it for your modules), etc...
Because Django 1.2 has its own layer on top of unittest (to do basic setup and fixtures loading for the developer and integrate with management commands for instance), using unittest2 with it is a pain.
I, for one, am very happy with this development.
> It is getting enterprisey.
Because they bundle a preexisting library instead of developing yet-another-unit-testing-library?
Hi, creator of the package here. If you install the pycrypto package first, jrnl should work fine on Windows, too. It only needs a gcc compiler to build from source [1], but there are even pre-compiled binaries [2] (I don't have any experience with them though - please let me know if it works) :)
I think py2exe could work well, too! Otherwise you could create a virtual environment with virtualenv and install all the dependencies into one folder.
[1] https://www.dlitz.net/software/pycrypto/
[2] http://www.voidspace.org.uk/python/modules.shtml#pycrypto
"Any traditional OOP programmer might tell you that essential elements of OOP are encapsulation and message passing.
The Python equivalents are namespaces and methods.
Python doesn't subscribe to protecting the code from the programmer, like some of the more BSD languages. Python does encapsulate objects as a single namespace but it's a transluscent encapsulation."
From: http://www.voidspace.org.uk/python/articles/OOP.shtml
Unit testing is all about abstracting / mocking out all the modules connected to the unit you are testing & just test your unit.
If you are programming in python, http://www.voidspace.org.uk/python/mock/ would be the most preferred way of mocking out other external units connected to your unit under test.
http://alexmarandon.com/articles/python_mock_gotchas/ should make you an expert on mocking
Make is better than SCons if you are not compiling C. Lots of people would use fabric instead. The stock unittest in the stdlib is quite good, especially in python 2.7+.
For mocks, wait until mock (http://www.voidspace.org.uk/python/mock/) is in the stdlib or download it yourself.