astropy/astropy — pull request #1102 by hamogu (2013-05-16 17:10:00+00:00)
Title: Fix failure when creating votables

The following code
```
from astropy.io.votable.tree import VOTableFile, Resource, Table, Field
votable = VOTableFile()

resource = Resource()
votable.resources.append(resource)

table = Table(votable)
resource.tables.append(table)
table.fields.extend([Field(votable, name='XXX', datatype="float", unit = "mag")])
```

fails with

```
ERROR: KeyError: 'unit_format' [astropy.io.votable.tree]
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
in ()
----> 1 table.fields.extend([Field(votable, name='XXX', datatype="float", unit = "mag")])

/data/guenther/anaconda/lib/python2.7/site-packages/astropy-0.3.dev4321-py2.7-linux-x86_64.egg/astropy/io/votable/tree.pyc in __init__(self, votable, ID, name, datatype, arraysize, ucd, unit, width, precision, utype, ref, type, id, xtype, config, pos, **extra)
1152 self.arraysize = arraysize
1153 self.ucd = ucd
-> 1154 self.unit = unit
1155 self.width = width
1156 self.precision = precision

/data/guenther/anaconda/lib/python2.7/site-packages/astropy-0.3.dev4321-py2.7-linux-x86_64.egg/astropy/io/votable/tree.pyc in unit(self, unit)
1323 self._config, self._pos)
1324
-> 1325 format = _get_unit_format(self._config)
1326 if format != default_format:
1327 unit_obj = u.Unit(

/data/guenther/anaconda/lib/python2.7/site-packages/astropy-0.3.dev4321-py2.7-linux-x86_64.egg/astropy/io/votable/tree.pyc in _get_unit_format(config)
180 Get the unit format based on the configuration.
181 """
--> 182 if config['unit_format'] is None:
183 format = _get_default_unit_format(config)
184 else:

KeyError: 'unit_format'
```

There is any easy fix for this (and I have implemented it in this pull request); I have also written a unit test.
However, this implementation breaks a different test when reading unrecognized units and I have been unable to figure out why that is.

@mdboom : Maybe you understand this?