PyProxyFS iconPyProxyFS 0.8

Simple filesystem abstraction
PyProxyFS is a proxy filesystem interface with a native filesystem implementation and a very simple test in-memory filesystem.

The aim of pyproxyfs is to provide a filesystem class that you can use for doing much of your file handling... but that can easi;ly be mocked for specific testing purposes.

If, instead of using open, os.rename and os.listdir you use the pyproxyfs equivalents you can expect to be able to make a simple filesystem using the builtin TestFS class and write tests around that.

For example:

def show_conf_files(dirtolist, filesystem=None):
 from pyproxyfs import Filesystem
 if not filesystem:
 filesystem = Filesystem()
 files = filesystem.listdir(dirtolist)
 import re
 cfgpat = re.compile(".*\\.cfg$")
 cfg_files = [fn for fn in files if cfgpat.match(fn)]
 return cfg_files

this might be your application code.

You could then test it relatively simply:

def test_show_conf_files():
>>> test_show_conf_files()
['a.cfg', 'b.cfg']
 from pyproxyfs import TestFS
 fs = TestFS({
 "somedir/a.cfg": "",
 "somedir/a.txt": "",
 "somedir/b.cfg": "",
 "somedir/": ""
 return show_conf_files("somedir", filesystem=fs)

last updated on:
November 19th, 2011, 0:05 GMT
developed by:
Nic Ferrier
license type:
GPL v3 
ROOT \ System \ Filesystems


In a hurry? Add it to your Download Basket!

user rating



Add your review!