[TIP] virtual filesystem

Jonathan Lange jml at mumak.net
Wed Dec 7 08:30:59 PST 2011


On Tue, Dec 6, 2011 at 10:20 AM, Andrea Crotti
<andrea.crotti.0 at gmail.com> wrote:
> I have a lot of code which has to manipulate and handle the filesystem,
> creating
> directories and so on.
>
> The testing now is far from complete, because even if I tried to use a
> functional
> paradigm, still many things are too bound to the "real world".
> And it's really time for me to learn how to use mock objects ;)
>
> Before I waste too much time trying (and failing a few times), any
> suggestions of how
> it could be possible?
>

bzrlib[1] takes the approach of abstracting out the filesystem using
what it calls "Transports". It's not really the filesystem, it's
actually also for FTP, HTTP etc. Anyway, they have a MemoryTransport,
which never actually hits disk at all, and is great for testing. I've
found myself using this from bzrlib in other projects.

They prevent interface skew by having one set of tests that run
against every transport implementation. Whenever they discover some
buggy behaviour variance, they add tests to this "interface suite".

jml

[1] http://pypi.python.org/pypi/bzr



More information about the testing-in-python mailing list