ianb  committed caefe42

[svn r7086] add a guard against deleting a directory unintentionally. Fix last commit

  • Participants
  • Parent commits d79db40
  • Branches trunk

Comments (0)

Files changed (2)

File docs/index.txt

     >>> from scripttest import TestFileEnvironment
     >>> env = TestFileEnvironment('./test-output')
+.. note::
+   Everything in ``./test-output`` will be deleted every test run.  To
+   make sure you don't point at an important directory, the scratch
+   directory must be created by ScriptTest (a hidden file is written
+   by ScriptTest to confirm that it created the directory).  If the
+   directory already exists, you must delete it manually.
 Then you run scripts with ``, arg1, arg2, ...)``::
     >>> print'echo', 'hey')
   false, then if there is any error (return code != 0, or stderr
   output) the complete output of the script will be printed.
+* ScriptTest puts a marker file in scratch directories it deletes, so
+  that if you point it at a directory not created by ScriptTest it
+  will raise an error.  Without this, unwitting developers could point
+  ScriptTest at the project directory, which would cause the entire
+  project directory to be wiped.

File scripttest/

         ``stdin``: (default ``""``)
             Input to the script
         ``cwd``: (default ``self.cwd``)
-            The working directory to run in (default ``base_dir``)
+            The working directory to run in (default ``base_path``)
         ``quiet``: (default False)
             When there's an error (return code != 0), do not print stdout/stderr
         expect_stderr = _popget(kw, 'expect_stderr', expect_error)
         cwd = _popget(kw, 'cwd', self.cwd)
         stdin = _popget(kw, 'stdin', None)
+        quiet = _popget(kw, 'quiet', False)
         args = map(str, args)
         assert not kw, (
             "Arguments not expected: %s" % ', '.join(kw.keys()))
             result[path] = FoundFile(self.base_path, path)
-    def clear(self):
+    def clear(self, force=False):
         Delete all the files in the base directory.
+        marker_file = os.path.join(self.base_path, '.scripttest-test-dir.txt')
         if os.path.exists(self.base_path):
+            if not force and not os.path.exists(marker_file):
+                print >> sys.stderr, 'The directory %s does not appear to have been created by ScriptTest' % self.base_path
+                print >> sys.stderr, 'The directory %s must be a scratch directory; it will be wiped after every test run' % self.base_path
+                print >> sys.stderr, 'Please delete this directory manually'
+                raise AssertionError(
+                    "The directory %s was not created by ScriptTest; it must be deleted manually" % self.base_path)
+        f = open(marker_file, 'w')
+        f.write('placeholder')
+        f.close()
     def writefile(self, path, content=None,
         The return code of the script.
     ``files_created``, ``files_deleted``, ``files_updated``:
-        Dictionaries mapping filenames (relative to the ``base_dir``)
+        Dictionaries mapping filenames (relative to the ``base_path``)
         to `FoundFile <class-paste.fixture.FoundFile.html>`_ or
         `FoundDir <class-paste.fixture.FoundDir.html>`_ objects.