Random notes from mg

a blog by Marius Gedminas

Marius is a Python hacker. He works for Programmers of Vilnius, a small Python/Zope 3 startup. He has a personal home page at http://gedmin.as. His email is marius@gedmin.as. He does not like spam, but is not afraid of it.

Thu, 23 Oct 2008

All hail our robotic overlords?

Yesterday I held a G1 phone in my hands. An interesting little device. I'd buy one in a heartbeat, if I could. T-Mobile sells them only with a data plan, and T-Mobile doesn't operate in Lithuania.

Openness is the primary reason I'm interested in Android phones. I don't see how that can be compatible with operator lock-in.

posted at 21:13 | random, android permanent link to this entry | 0 comments

On narrative doctests

Andrew Bennetts writes why narrative tests are lousy unit tests. I completely agree.

Narratives are great as documentation, and the embedded doctest sections help (1) keep the documentation up-to-date and (2) provide concrete examples that make the documentation easier to understand. Here's a good example of that: Storm ORM tutorial. But for unit tests you want many small, isolated tests rather than one big narrative, for reasons that Andrew so clearly elucidated in his post.

My preferred way of writing unit tests is a mixture of unittest and doctest:

import unittest
import doctest
from cStringIO import StringIO

from mysuperduperpackage import Gronkulator

def doctest_Gronkulator_parseXML():
    """Tests that Gronculator.parseXML does the right thing

        >>> g = Gronkulator()

    You pass a file-like object to Gronkulator's parseXML():

        >>> g.parseXML(StringIO('''
        ... <gronk id="g42">
        ...   <item id="a">One</a>
        ...   <item id="b">Two</a>
        ...   <item id="c" important="yes">Three</a>
        ... </gronk>
        ... ''')

    and the items are loaded into ``g.items``:

        >>> for item in g.items:
        ...     print item.id + ':', item.title, '!' if item.important else ''
        a: One
        b: Two
        c: Three !


def doctest_Gronkulator_parseXML_error_handling()

def test_suite():
    return doctest.DocTestSuite(optionflags=doctest.NORMALIZE_WHITESPACE)

if __name__ == '__main__':

I've written more about this on Zope mailing lists on several occasions.

posted at 04:59 | python permanent link to this entry | 0 comments

Tue, 14 Oct 2008

Chaining operators in Python

One of the little things I love about Python is that you can chain comparison operators like this:

10 <= x <= 20


x == y == z

Strangely, I hadn't realized until yesterday that this also works with the is operator:

x is y is z
posted at 03:17 | python permanent link to this entry | 0 comments

Mon, 13 Oct 2008

N810: death and rebirth

My beloved N810 died last Tuesday. Well, not died died, but the screen stopped working. The topmost plastic layer is fine, but the LCD is probably cracked underneath. This probably happened while I was in an Apple store watching a friend of mine buy an iPhone. Coincidence?

I ordered a new one from Amazon that evening, and it arrived on Thursday. It had the oldest possible OS2008 version (and an incorrectly-formatted internal flash card), so I had to reflash it, and then install the OS feature updates one at a time, with forced a reboot in between. Untimely breakage of extras-devel didn't help either, and neither did the broken maemo-mapper package in extras. (Both are fixed now.)

Almost all of my data was on the miniSD card (including a week-old backup). To get the rest I had to blindly get the old N810 online and open a browser page (measuring distances from the corner of the screen) to get past the hotel wireless nag screen, and then guess its IP address, so that I could ssh in.

It thought maybe I could use arping on its MAC address to get the IP, but had no luck there. It didn't respond to broadcast pings either. Finally I had to ping every IP in my subnet individually and then grep for the MAC address in my kernel's ARP cache. Oh, how I wish Maemo came with avahi-daemon preinstalled! ssh mg-n810.local would have been so much simpler!

I'll try to get the old one repaired.

Update: thp describes how to get avahi-daemon on the tablet.

Update 2: the old N810 is repaired (screen replacement cost me 510 LTL, which is ~200 USD, at the local Nokia service center). It now serves as an Internet Radio station at home.

posted at 03:19 | maemo permanent link to this entry | 0 comments