summaryrefslogtreecommitdiff
path: root/morphlib/workspace_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-07-31 11:46:39 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-07-31 16:05:19 +0000
commitf188c5755c30117884867c19b233f85db66c1060 (patch)
tree853a55598bb271fbda10565017eab0bada237afb /morphlib/workspace_tests.py
parentd15bbb2544d52ed53c344fa29c25e6928da3c55b (diff)
downloadmorph-f188c5755c30117884867c19b233f85db66c1060.tar.gz
Add a Workspace class
Diffstat (limited to 'morphlib/workspace_tests.py')
-rw-r--r--morphlib/workspace_tests.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/morphlib/workspace_tests.py b/morphlib/workspace_tests.py
new file mode 100644
index 00000000..7837481a
--- /dev/null
+++ b/morphlib/workspace_tests.py
@@ -0,0 +1,85 @@
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# =*= License: GPL-2 =*=
+
+
+import os
+import shutil
+import tempfile
+import unittest
+
+import morphlib
+
+
+class WorkspaceTests(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+ self.workspace_dir = os.path.join(self.tempdir, 'workspace')
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def assertIsWorkspace(self, dirname):
+ self.assertTrue(os.path.isdir(dirname))
+ self.assertTrue(os.path.isdir(os.path.join(dirname, '.morph')))
+
+ def create_it(self):
+ morphlib.workspace.create(self.workspace_dir)
+
+ def test_creates_workspace(self):
+ ws = morphlib.workspace.create(self.workspace_dir)
+ self.assertIsWorkspace(self.workspace_dir)
+ self.assertEqual(ws.root, self.workspace_dir)
+
+ def test_create_initialises_existing_but_empty_directory(self):
+ os.mkdir(self.workspace_dir)
+ ws = morphlib.workspace.create(self.workspace_dir)
+ self.assertIsWorkspace(self.workspace_dir)
+ self.assertEqual(ws.root, self.workspace_dir)
+
+ def test_fails_to_create_workspace_when_dir_exists_and_is_not_empty(self):
+ os.mkdir(self.workspace_dir)
+ os.mkdir(os.path.join(self.workspace_dir, 'somedir'))
+ self.assertRaises(
+ morphlib.workspace.WorkspaceDirExists,
+ morphlib.workspace.create, self.workspace_dir)
+
+ def test_fails_to_recreate_workspace(self):
+ # Create it once.
+ morphlib.workspace.create(self.workspace_dir)
+ # Creating it again must fail.
+ self.assertRaises(
+ morphlib.workspace.WorkspaceDirExists,
+ morphlib.workspace.create, self.workspace_dir)
+
+ def test_opens_workspace_when_given_its_root(self):
+ self.create_it()
+ ws = morphlib.workspace.open(self.workspace_dir)
+ self.assertEqual(ws.root, self.workspace_dir)
+
+ def test_opens_workspace_when_given_subdirectory(self):
+ self.create_it()
+ subdir = os.path.join(self.workspace_dir, 'subdir')
+ os.mkdir(subdir)
+ ws = morphlib.workspace.open(subdir)
+ self.assertEqual(ws.root, self.workspace_dir)
+
+ def test_fails_to_open_workspace_when_no_workspace_anywhere(self):
+ self.assertRaises(
+ morphlib.workspace.NotInWorkspace,
+ morphlib.workspace.open, self.tempdir)
+