Rev 4688: Revert the jail_root parameter addition. in file:///home/vila/src/bzr/experimental/shell-like-tests/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Sep 18 14:07:23 BST 2009


At file:///home/vila/src/bzr/experimental/shell-like-tests/

------------------------------------------------------------
revno: 4688
revision-id: v.ladeuil+lp at free.fr-20090918130723-sq6fml55uyed5hee
parent: v.ladeuil+lp at free.fr-20090918125401-fb3gl822abfc8omt
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: shell-like-tests
timestamp: Fri 2009-09-18 15:07:23 +0200
message:
  Revert the jail_root parameter addition.
  
  * bzrlib/tests/script.py:
  (ScriptRunner): Since we can access the test_case when we need the
  jail root and it's defined by the test case anyway, no need to
  provide it ahead of time.
-------------- next part --------------
=== modified file 'bzrlib/tests/script.py'
--- a/bzrlib/tests/script.py	2009-09-18 12:54:01 +0000
+++ b/bzrlib/tests/script.py	2009-09-18 13:07:23 +0000
@@ -159,8 +159,7 @@
 
 class ScriptRunner(object):
 
-    def __init__(self, jail_root='/'):
-        self.jail_root = jail_root
+    def __init__(self):
         self.output_checker = doctest.OutputChecker()
         self.check_options = doctest.ELLIPSIS
 
@@ -302,18 +301,20 @@
                 return 1, None, '%s: No such file or directory\n' % (out_name,)
         return 0, output, None
 
-    def _ensure_in_jail(self, path):
-        if not osutils.is_inside(self.jail_root, osutils.normalizepath(path)):
-            raise ValueError('%s is not inside %s' % (path, self.jail_root))
+    def _ensure_in_jail(self, test_case, path):
+        jail_root = test_case.get_jail_root()
+        if not osutils.is_inside(jail_root, osutils.normalizepath(path)):
+            raise ValueError('%s is not inside %s' % (path, jail_root))
 
     def do_cd(self, test_case, input, args):
         if len(args) > 1:
             raise SyntaxError('Usage: cd [dir]')
         if len(args) == 1:
             d = args[0]
-            self._ensure_in_jail(d)
+            self._ensure_in_jail(test_case, d)
         else:
-            d = self.jail_root
+            # The test "home" directory is the root of its jail
+            d = test_case.get_jail_root()
         os.chdir(d)
         return 0, None, None
 
@@ -321,7 +322,7 @@
         if not args or len(args) != 1:
             raise SyntaxError('Usage: mkdir dir')
         d = args[0]
-        self._ensure_in_jail(d)
+        self._ensure_in_jail(test_case, d)
         os.mkdir(d)
         return 0, None, None
 
@@ -344,7 +345,7 @@
         if not args or opts:
             raise SyntaxError('Usage: rm [-fr] path+')
         for p in args:
-            self._ensure_in_jail(p)
+            self._ensure_in_jail(test_case, p)
             # FIXME: Should we put that in osutils ?
             try:
                 os.remove(p)
@@ -378,9 +379,11 @@
 
     def setUp(self):
         super(TestCaseWithMemoryTransportAndScript, self).setUp()
-        # We don't have a jail_root to provide here. Yet.
         self.script_runner = ScriptRunner()
 
+    def get_jail_root(self):
+        raise NotImplementedError(self.get_jail_root)
+
     def run_script(self, script):
         return self.script_runner.run_script(script, self)
 
@@ -408,7 +411,10 @@
 
     def setUp(self):
         super(TestCaseWithTransportAndScript, self).setUp()
-        self.script_runner = ScriptRunner(self.test_dir)
+        self.script_runner = ScriptRunner()
+
+    def get_jail_root(self):
+        return self.test_dir
 
     def run_script(self, script):
         return self.script_runner.run_script(script, self)



More information about the bazaar-commits mailing list