On 02/12/2009, at 4:52 AM, Chris Brannon wrote:
>> On Nov 30, 2009, at 11:00 PM, Christopher Brannon wrote:
>>
>>> I want to test package uploading thoroughly. Here's the first step.
>>> This was suggested by Xilon on the AUR_2 page from the Arch wiki.
>>> The temporary tree is removed when the application terminates.
>>>
>>> Signed-off-by: Christopher Brannon <
cmbra...@gmail.com>
>>> ---
>>> archlinux/settings.py | 8 ++++++++
>>> 1 files changed, 8 insertions(+), 0 deletions(-)
>>>
>>> diff --git a/archlinux/settings.py b/archlinux/settings.py
>>> index a7d1813..63958fa 100644
>>> --- a/archlinux/settings.py
>>> +++ b/archlinux/settings.py
>>> @@ -1,4 +1,8 @@
>>> import os.path
>>> +import sys
>>> +import tempfile
>>> +import shutil
>>> +import atexit
>>>
>>> DEPLOY_PATH = os.path.dirname(__file__) # This is the base dir for
>>> everything
>>>
>>> @@ -75,3 +79,7 @@ try:
>>> from settings_local import *
>>> except ImportError:
>>> pass
>>> +
>>> +if len(sys.argv) > 1 and sys.argv[1] == 'test':
>>> + MEDIA_ROOT = tempfile.mkdtemp(prefix='testaur2')
>>> + atexit.register(lambda : shutil.rmtree(MEDIA_ROOT))
>>> --
>> Hmm, it's kind of a hack (mainly the use of sys.argv). It's a great
>> idea to isolate the test environment like this, but I think a better
>> solution is in order. I'm considering implementing something like
>> FakeFS (Ruby) in python, to mock the filesystem for the tests. This
>> should suffice for the time being (assuming it works :P) though.
>
> Yes it is a hack. I ran across this idea somewhere on the net, while
> looking at info about Django testing.
> The FakeFS concept sounds nice.
>
> -- Chris
I just came across mockfs[1], which is exactly what we want! Yay!
Not sure if it has open(), but it seems that it would be easy to alias
it.
[1]: http://mockfs.github.com/