1/11/2003

Learning about the twisted trial unittesting framework

I used to run the woven tests by themselves a lot using the -file switch of admin/runtests. Since the trial unittest framework has been checked in, this no longer works. It appears the way to run a single test is to use the -m switch to specify the module that contains the tests:

bin/trial -m twisted.test.test_woven

1/06/2003

Do not read this.

Do not read this.


from __future__ import generators


class Text(str):
def __init__(self, it):
self.it = it
def __str__(self):
return self.it


def coerceBasic(item):
if isinstance(item, str):
item = Text(item)
elif isinstance(item, tuple):
item = lmx2(item)
assert isinstance(item, Text) or
isinstance(item, lmx2), "wtf did you add %s to me for?" % item
return item


class lmx2(object):
def __init__(self, argument, **kw):
if isinstance(argument, str):
self._name = argument
self._children = []
self._attributes = kw
else:
assert not kw, "Either use a fourple or a tag name and set of keyword arguments"
self._name, self._attributes, self._children, spare = argument
def __lshift__(self, other):
self._children.append(other)
return self
def __rshift__(self, other):
other.__dict__ = self.__dict__
other.__class__ = self.__class__
return other
def _gen(self):
for item in self._children:
yield coerceBasic(item)
def __iter__(self):
return self._gen()
def __getitem__(self, item):
if isinstance(item, int):
return coerceBasic(self._children[item])
return self._attributes[item]
def __setitem__(self, item, value):
if isinstance(item, int):
self._children[item] = value
else:
self._attributes[item] = value
def __delitem__(self, item):
if isinstance(item, int):
del self._children[item]
else:
del self._attributes[item]
def __getattr__(self, name):
if name[0] == '_':
raise AttributeError("no private attrs")
return lambda **kw: self._children.append(lmx2(name, **kw))
def __str__(self):
return ('<%s ' % self._name) + ' '.join(['%s="%s"' % (key, value)
for key, value in self._attributes.items()]) + ('>...' % self._name)

Man, I _told_ you not to read this. Why you always trippin like that?



1/04/2003

Twisted logging

In the CVS version of twisted, there have been some modifications to make the default logging less intrusive (it won't write to stdout by default). If you just use twistd to run your apps, you shouldn't notice any difference, but if you like to write scripts that you run directly that start the reactor directly, you might be wondering what happened to logging. Here's a little recipe to turn on logging again.

import sys
from twisted.python import log
log.startLogging(sys.stdout, 0)

If you wish, you can also use any file in place of sys.stdout.