def test_edit_document_no_no(self, mock_launch): """Verify 'doorstop edit' can be called with a document (no, no).""" path = "TUT-456.yml" self.assertIs(None, main(['edit', 'tut', '-T', 'my_editor'])) common.delete(path) mock_launch.assert_called_once_with(os.path.normpath(path), tool='my_editor')
def _export_import(args, cwd, error, document, ext): """Edit a document by calling export followed by import. :param args: Namespace of CLI arguments :param cwd: current working directory :param error: function to call for CLI errors :param document: :class:`~doorstop.core.document.Document` to edit :param ext: extension for export format """ # Export the document to file args.prefix = document.prefix path = "{}-{}{}".format(args.prefix, int(time.time()), ext) args.path = path get('export')(args, cwd, error, catch=False, auto=True, _tree=document.tree) # Open the exported file editor.edit(path, tool=args.tool) # Import the file to the same document if utilities.ask("import from '{}'?".format(path)): args.attrs = {} args.map = {} get('import')(args, cwd, error, catch=False, _tree=document.tree) common.delete(path) else: utilities.show("import canceled") if utilities.ask("delete '{}'?".format(path)): common.delete(path) else: msg = "to manually import: doorstop import {0}".format(path) utilities.show(msg)
def delete(self, path): """Delete the object's file from the file system.""" if self._exists: log.info("deleting {}...".format(self)) common.delete(path) self._loaded = False # force the object to reload self._exists = False # but, prevent future access else: log.warning("already deleted: {}".format(self))
def delete(self, path=None): """Delete the document and its items.""" prefix = Prefix(str(self.prefix)) for item in self: item.delete() super().delete(self.config) common.delete(self.path) if settings.CACHE_DOCUMENTS and self.tree: self.tree._document_cache[prefix] = None # pylint: disable=W0212 log.trace("expunged document: {}".format(prefix))
def tearDown(self): common.delete(os.path.join(ROOT, 'tmp')) common.delete(os.path.join(REQS, 'REQ099.yml'))
def tearDown(self): """Clean up temporary files.""" for filename in os.listdir(EMPTY): path = os.path.join(EMPTY, filename) common.delete(path)
def move_file(src, dst): """Move a file from one path to another.""" common.delete(dst) shutil.move(src, dst)
def index(self): """Delete the document's index if it exists.""" log.info("deleting {} index...".format(self)) common.delete(self.index)
def tearDown(self): common.delete(self.path)
def tearDown(self): common.delete(os.path.join(ROOT, "tmp")) common.delete(os.path.join(REQS, "REQ099.yml"))
def test_edit_document_no_no(self, mock_launch): """Verify 'doorstop edit' can be called with a document (no, no).""" path = "TUT-456.yml" self.assertIs(None, main(['edit', 'tut'])) common.delete(path) mock_launch.assert_called_once_with(os.path.normpath(path), tool=None)