Example #1
0
class InMemoryEnvironment(object):
    @classmethod
    def attribute(selfclass, test_func):
        pass
    
    def __init__(self, name):
        self.name = name
        self.storage = MemStorage("testing")
        self.editor_content = ""
    
    def deft(self, *args, **kwargs):
        command = ["deft"] + list(args)
        
        editor_content = kwargs.get('editor_input', 'description-not-important')
        stdout = StringIO()
        stderr = StringIO()
        
        def fake_editor(path):
            relpath = self.storage.relpath(path)
            with self.storage.open(relpath, "w") as output:
                output.write(editor_content)
        
        cli = CommandLineInterface(self, out=stdout, err=stderr, editor=fake_editor)
        try:
            cli.run(command)
            return ProcessResult(command, 0, stdout.getvalue(), stderr.getvalue())
        except UserError:
            raise ProcessError(command, 1, stdout.getvalue(), 
                               traceback.format_exc() + "\n\nstderr:\n\n" + stderr.getvalue())
    
    def init_tracker(self, warning_listener, **config_overrides):
        return init_with_storage(self.storage, warning_listener, config_overrides)
    
    def load_tracker(self, warning_listener):
        return load_with_storage(self.storage, warning_listener)
    
    def abspath(self, subpath):
        return self.storage.abspath(subpath)