Esempio n. 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):
            self.storage.save_text(self.storage.relpath(path), 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, **config_overrides):
        return init_with_storage(self.storage, config_overrides)
    
    def load_tracker(self):
        return load_with_storage(self.storage)

    def abspath(self, subpath):
        return self.storage.abspath(subpath)
Esempio n. 2
0
 def __init__(self, name):
     self.name = name
     self.storage = MemStorage("testing")
     self.editor_content = ""