Added tests for double-init
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 18 May 2005 20:09:53 +0000 (20:09 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 18 May 2005 20:09:53 +0000 (20:09 +0000)
becommands/set_root.py
libbe/bugdir.py

index c83fd1aab2cff2dffc7ec63e7daef5f7e55e577b..df6072131164a0161b3f10b0898e8e36ab81b3e9 100644 (file)
@@ -34,13 +34,19 @@ def execute(args):
     >>> bd.root = dir.name
     >>> dir = tests.arch_dir()
     >>> os.chdir(dir.name)
-    >>> execute('.')
+    >>> execute(['.'])
     Using Arch for revision control.
     Directory initialized.
     >>> bd = bugdir.tree_root(dir.name+"/{arch}")
     >>> bd.root = dir.name
+    >>> try:
+    ...     execute(['.'])
+    ... except cmdutil.UserError, e:
+    ...     str(e).startswith("Directory already initialized ")
+    Using Arch for revision control.
+    True
     >>> tests.clean_up()
-    >>> execute(('/highly-unlikely-to-exist',))
+    >>> execute(['/highly-unlikely-to-exist'])
     Traceback (most recent call last):
     UserError: No such directory: /highly-unlikely-to-exist
     """
@@ -56,6 +62,8 @@ def execute(args):
         bugdir.create_bug_dir(args[0], dir_rcs)
     except bugdir.NoRootEntry:
         raise cmdutil.UserError("No such directory: %s" % args[0])
+    except bugdir.AlreadyInitialized:
+        raise cmdutil.UserError("Directory already initialized: %s" % args[0])
     print "Directory initialized."
 
 def get_parser():
index 8856db48450c147b2294e0ad42dd7f4057ee1349..c6a9b5b7a9a09c4057cf8b63b420b87127769e12 100644 (file)
@@ -65,20 +65,35 @@ class NoRootEntry(Exception):
         self.path = path
         Exception.__init__(self, "Specified root does not exist: %s" % path)
 
+class AlreadyInitialized(Exception):
+    def __init__(self, path):
+        self.path = path
+        Exception.__init__(self, 
+                           "Specified root is already initialized: %s" % path)
+
 def create_bug_dir(path, rcs):
     """
-    >>> import no_rcs
+    >>> import no_rcs, tests
     >>> create_bug_dir('/highly-unlikely-to-exist', no_rcs)
     Traceback (most recent call last):
     NoRootEntry: Specified root does not exist: /highly-unlikely-to-exist
+    >>> test_dir = os.path.dirname(tests.bug_arch_dir().dir)
+    >>> try:
+    ...     create_bug_dir(test_dir, no_rcs)
+    ... except AlreadyInitialized, e:
+    ...     print "Already Initialized"
+    Already Initialized
     """
     root = os.path.join(path, ".be")
     try:
         rcs.mkdir(root)
     except OSError, e:
-        if e.errno != errno.ENOENT:
+        if e.errno == errno.ENOENT:
+            raise NoRootEntry(path)
+        elif e.errno == errno.EEXIST:
+            raise AlreadyInitialized(path)
+        else:
             raise
-        raise NoRootEntry(path)
     rcs.mkdir(os.path.join(root, "bugs"))
     set_version(root, rcs)
     map_save(rcs, os.path.join(root, "settings"), {"rcs_name": rcs.name})