how to add a custom type to unittest.TestCase.assertEqual

If you would like your TestCase class to understand one of your custom types as if it were standard, use addTypeEqualityFunc to supply a custom comparison function.

source: unittest/case.py:415

1
2
3
4
5
6
7
8
9
10
11
12
def addTypeEqualityFunc(self, typeobj, function):
"""Add a type specific assertEqual style function to compare a type.
This method is for use by TestCase subclasses that need to register
their own type equality functions to provide nicer error messages.
Args:
typeobj: The data type to call this function on when both values
are of the same type in assertEqual().
function: The callable taking two arguments and an optional
msg= argument that raises self.failureException with a
useful error message when the two arguments are not equal.
"""
self._type_equality_funcs[typeobj] = function

pickle.PicklingError: Function to be pickled has free variables that are referenced before assignment in enclosing scope

The code I had that caused this problem looked like this:

1
2
3
4
5
6
7
if x :
y = x

def foo() :
print y

cloud.pickle(foo)

If this were a normal call to foo, the error instead would be:

1
UnboundLocalError: local variable 'y' referenced before assignment

The fix is to make sure that all variables used in foo have values at the time that it is pickled:

1
2
3
4
5
6
7
8
9
if x :
y = x
else :
y = None

def foo() :
print y

cloud.pickle(foo)

Even this would be ok:

1
2
3
4
5
6
7
8
9
def foo() :
print y

if x :
y = x
else :
y = None

cloud.pickle(foo)

Window Sill Insulation Plug

Awesome idea for later:

Cast a 3” or larger tap to cut large threads into window sill. Make same size threaded wooden plug that can screw in tightly. Remove plug to check on insulation in the sill. Alternatively, could hold a wooden block in place that makes a perfect fit in a square hole and use embedded magnets to pull it out.

This can all be done later though. We could start by leaving it sealed up and drilling/cutting a hole in it later to check on things.

Window Building Musing

On the one hand I don’t want to deal with the time and complexity of building windows, on the other and, especially on the south wall, I like the idea of being able to build them all our selves and make them fit well …

What species of wood should be used for bond beams, lintels, gringo blocks, etc. when building a CEB wall, if I don't want to treat the wood with chemicals?

It appears no to matter much, but around here (Bloomington, Indiana) the most common rot resistant woods are Black Locust, White Oak and Cedar. I might just wind up using poplar because it is easy to source and cheap. Especially for the wood parts that aren’t in direct contact with the CEBs. Not sure if black Locust everywhere that touches the CEBs is overkill …

Tip seems to think that poplar should be fine, especially if it is coated with pine tar in places it touches the CEBs.

Welcome

Hello, this is where I post content that I want to share. Most of it is simple information about programming problems I’ve run into. Hopefully there will be more posts about the house that I’m building on the land that we’re buying with a new cooperative we’re starting in Bloomington Indiana!

web.py: error: No socket could be created

This error message most often occurrs when trying to run web.py on an invalid address and port. An example of an invalid address would be example.net, instead of a proper ip address like 98.228.37.242.

Other Causes:

Was just trying to get a simple web.py test running:

1
2
3
4
5
6
7
8
9
10
11
12
import web

urls = (
'/x', 'X',
)

class X :
def GET(self) :
return 'x'

app = web.application(urls, globals())
app.run()

but I kept getting the error:

error: No socket could be created

The problem was that due to the way web.py loading works, you need to have the creation and running of the app only occur if this is the main entry point of the program. Otherwise, the class loader in web.py will reload this file again later, and wind up spawning a new server when its intent was simply to load a class:

1
2
3
if __name__ == '__main__' :
app = web.application(urls, globals())
app.run()

Ubuntu 11.04 on Thinkpad T420s

Just bought this thinkpad 420s. The first thing I did when I got it was install Ubuntu 11.04 on it. Most everything worked on first install, including things which many people seemed to have problems with on the forums.

Working:

  • Displays work fine with 3d effects and everything (dual monitor with and without docking station) (Intel HD Graphics 3000)
  • Built in speakers and headphone jack both work
  • Built-in mic and web-cam both work - I used skype and google hangouts and both worked flawlessly.
  • wireless worked with my open network connection (I haven’t yet tried it on secure networks)
  • Bay battery seems to work.

Not Working:

  • Audio output on docking station
  • Dual Displays sometimes reset to showing the same image on both rather than two seperate displays. This has always been fixed by reseting the settings in the Monitor configuration page.

I am impressed with how flawless the install was. I was dreading it because last time I did this on my last laptop 4 years ago, I spent a few hours getting everything in working order. So far I have not yet had to do any custom installation. Everything that I needed working, worked out of the box!

Let me know if you want me to test anything out and I’ll try if I can.

TP-Link TL-WN722N on Ubuntu 10.04

Note: according this guy this set of steps also works for Fedora 15.

I had a lot of trouble getting this card to work. Here is how I finally got it.

I am running 2.6.32-30-generic-pae #59-Ubuntu SMP
running “lsusb” shows the following line for my device: 0cf3:9271 Atheros Communications, Inc.

I tried a bunch of different compat-wireless versions and this one finally did it. At the time, it was the latest stable release. The daily snapshots were causing kernel panics … Download it, decompress it and build it:

$ tar xvf compat-wireless-2.6.38.2-2.tar.bz2
$ cd compat-wireless-2.6.38.2-2
$ ./scripts/driver-select ath9k_htc
$ sudo make
$ sudo make install

I had to download version 1.2 of htc_9271.fw the firmware from here and copied the file to /lib/firmware.

I was getting wlan%d instead of something reasonable like wlan0. Running sudo ifconfig wlan%d showed me the mac address which I could use to add an entry to /etc/udev/rules.d/70-persistent-net.rules. Heres the entry I added: (note that the browser adds newlines here, but you should add just two lines: one for the comment, and one for the rule)

USB device 0x0cf3:0x9271 (usb)

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?“, ATTR{address}==”54:e6:fc:94:91:35”, ATTR{dev_id}==”0x0”, ATTR{type}==”1”, KERNEL==”wlan“, NAME=”wlan2”

reload the drivers by running:

sudo modprobe ath9k_htc

Now plug in the device. There were a lot of other steps that I followed while trying to get this to work, so I may have left something out.