Unittesting SocketServer.StreamRequestHandler subclasses

2011-09-09 Thread Neilen Marais
Hi,

Is there a recommended way for writing unittests of
SocketServer.StreamRequestHandler subclasses? I've tried making a
server stub class and a connection stub class with a recv() method
that immediately raises socket.error(errno.ECONNRESET, ).

This works OK, but it means that whatever unittests I run always
happens after the handler's handle() method has already been called.
Is there a way to avoid this?

Thanks
Neilen
-- 
http://mail.python.org/mailman/listinfo/python-list


fast kd-tree or octree implementations for python

2006-11-16 Thread Neilen Marais
Hi.

I'm doing a FEM (Finite Elements) code in python. It uses a tetrahedral
mesh to represent the geometry. For post-processing one specifies a list
of 3D coordinates to calculate field values at, which requires the tet
that contains a given point. Right now I'm brute-forcing it checking each
tet for each point, which is very slow on large meshes since the number of
points you are looking for also tend to increase with mesh size.

It seems a kd-tree or octree data-structure will allow me to do lookups in
O(logN) time at the cost of building the data structure in O(N*logN) time.
I am looking for preferably a fast kd-tree implementation with a
GPL-compatible license that is already wrapped for Python, but I'd be
willing to make my own wrappers if needed.

So far I've found CGAL -  and 
GTS -- The GNU Triangulated Surface Library -  .

CGAL has python wrappers but the tree code is under the QPL license (not
GPL compat) while GTS doesn't come with ready-made python wrappers. What
are other good choices?

Thanks
Neilen

-- 
you know its kind of tragic 
we live in the new world
but we've lost the magic
-- Battery 9 (www.battery9.co.za)

-- 
http://mail.python.org/mailman/listinfo/python-list


Using difflib to compare text ignoring whitespace differences

2006-12-19 Thread Neilen Marais
Hi

I'm trying to compare some text to find differences other than whitespace.
I seem to be misunderstanding something, since I can't even get a basic
example to work:

In [104]: d = difflib.Differ(charjunk=difflib.IS_CHARACTER_JUNK)

In [105]: list(d.compare(['  a'], ['a']))
Out[105]: ['-   a', '+ a']

Surely if whitespace characters are being ignored those two strings should
be marked as identical? What am I doing wrong?

Thanks
Neilen

-- 
you know its kind of tragic 
we live in the new world
but we've lost the magic
-- Battery 9 (www.battery9.co.za)

-- 
http://mail.python.org/mailman/listinfo/python-list