astropy/astropy — pull request #292 by mdboom (2012-06-19 15:25:49+00:00)
Title: Only use tempdir in testing

Somewhat inspired by #291, this ensures that the tests don't write to any files outside of the /tmp
heirarchy.

This works by replacing the open builtin with one that performs a
check and raises an exception if writing to a file in the wrong place.
It's a bit of a kludge, and certainly incomplete (it doesn't check for
other operations that could write to files, such as os.unlink for
example). I experimented with some Unixy way to drop permissions like
this, and it seems the standard way is to setuid to nobody, but that
requires running as root in the first place, so not really appropriate
here. Despite the incompleteness, I think this is better than
nothing.