Posts in category quality

Quick-and-dirty usage documentation for python integration tests

In addition to my addiction to python's doctest for WritingQualityCode, I'm developing a habit of letting my modules serve as their own integration tests when run as scripts. Python comes batteries-included with argparse, and Aargh is pretty cool, but for quick-and-dirty stuff like this, I tend not to bother at all. I just let python's stack traces serve as documentation.

For example, if it's been a while since I used source:raven-j/heron_wsgi/admin_lib/i2b2pm.py, I just run it, and I get:

(haenv):admin_lib$ python i2b2pm.py
Traceback (most recent call last):
  File "i2b2pm.py", line 319, in <module>
    _test_main()
  File "i2b2pm.py", line 289, in _test_main
    user_id, full_name = sys.argv[1:3]
ValueError: need more than 0 values to unpack

The user_id, full_name = sys.argv[1:3] line is typically enough of a clue to remind me what arguments are needed:

(haenv):admin_lib$ python i2b2pm.py dconnolly 'Dan Connolly'
DEBUG:__main__:generate authorization for: ('dconnolly', 'Dan Connolly')
INFO:sqlalchemy.engine.base.Engine:SELECT USER FROM DUAL
...
INFO:sqlalchemy.engine.base.Engine:{'param_1': u'dconnolly'}
('1f8c885f-43e3-4ace-8512-88e65494d59a', <User(dconnolly, Dan Connolly)>)