summaryrefslogtreecommitdiff
path: root/morphlib/util_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-05 16:12:02 +0000
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2013-08-06 12:12:01 +0000
commit9dd0065a97e49e6e129cc6a5e656eb0d0e657d86 (patch)
tree3ef52969c4cbf53f41582a4c3f19ebb7aed09f69 /morphlib/util_tests.py
parent7b4c26f8ed053f27475cd8628502ae32cecd8e77 (diff)
downloadmorph-9dd0065a97e49e6e129cc6a5e656eb0d0e657d86.tar.gz
Add morphlib.util.find_root and find_leaf functions
These will be used to find workspace and system branch root directories. Also accidentally removed some whitespace from ends of lines. Too lazy to split that into a separate commit.
Diffstat (limited to 'morphlib/util_tests.py')
-rw-r--r--morphlib/util_tests.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/morphlib/util_tests.py b/morphlib/util_tests.py
index 89fe184e..eaff0821 100644
--- a/morphlib/util_tests.py
+++ b/morphlib/util_tests.py
@@ -14,6 +14,9 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import os
+import shutil
+import tempfile
import unittest
import morphlib
@@ -48,3 +51,39 @@ class MakeConcurrencyTests(unittest.TestCase):
def test_returns_6_for_4_cores(self):
self.assertEqual(morphlib.util.make_concurrency(cores=4), 6)
+
+
+class FindParentOfTests(unittest.TestCase):
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+ os.makedirs(os.path.join(self.tempdir, 'a', 'b', 'c'))
+ self.a = os.path.join(self.tempdir, 'a')
+ self.b = os.path.join(self.tempdir, 'a', 'b')
+ self.c = os.path.join(self.tempdir, 'a', 'b', 'c')
+
+ def tearDown(self):
+ shutil.rmtree(self.tempdir)
+
+ def test_find_root_finds_starting_directory(self):
+ os.mkdir(os.path.join(self.a, '.magic'))
+ self.assertEqual(morphlib.util.find_root(self.a, '.magic'), self.a)
+
+ def test_find_root_finds_ancestor(self):
+ os.mkdir(os.path.join(self.a, '.magic'))
+ self.assertEqual(morphlib.util.find_root(self.c, '.magic'), self.a)
+
+ def test_find_root_returns_none_if_not_found(self):
+ self.assertEqual(morphlib.util.find_root(self.c, '.magic'), None)
+
+ def test_find_leaf_finds_starting_directory(self):
+ os.mkdir(os.path.join(self.a, '.magic'))
+ self.assertEqual(morphlib.util.find_leaf(self.a, '.magic'), self.a)
+
+ def test_find_leaf_finds_child(self):
+ os.mkdir(os.path.join(self.c, '.magic'))
+ self.assertEqual(morphlib.util.find_leaf(self.a, '.magic'), self.c)
+
+ def test_find_leaf_returns_none_if_not_found(self):
+ self.assertEqual(morphlib.util.find_leaf(self.a, '.magic'), None)
+