Commits

Andrew Godwin committed a6b2d5e

Moving tests inside main module.

  • Participants
  • Parent commits 8998ec8

Comments (0)

Files changed (7)

heechee/tests/__init__.py

Empty file added.

heechee/tests/base.py

+"""
+Base classes for the test suite.
+"""
+
+import os
+import unittest
+import tempfile
+import subprocess
+import shutil
+import time
+import socket
+try:
+    from cStringIO import StringIO
+except ImportError:
+    from StringIO import StringIO
+
+class HeecheeTest(unittest.TestCase):
+    
+    def setUp(self):
+        "Sets up a target directory and a source repo."
+        self.source_dir = tempfile.mkdtemp(suffix="-heechee-src")
+        self.init_repo()
+        self.target_dir = tempfile.mkdtemp(suffix="-heechee-tgt")
+        self.server = subprocess.Popen(
+            ["python", "-m", "heechee.webdav.__init__", self.source_dir],
+            stdout=subprocess.PIPE,
+            #stderr=subprocess.PIPE,
+        )
+        # Wait for server to come up
+        for i in range(20):
+            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+            try:
+                s.connect(('localhost', 8080))
+            except socket.error:
+                time.sleep(0.25)
+            else:
+                return
+        raise RuntimeError("Cannot seem to launch Heechee")
+    
+    def tearDown(self):
+        "Deletes the target directory"
+        shutil.rmtree(self.source_dir)
+        shutil.rmtree(self.target_dir)
+        # Kill server, and wait till it dies
+        self.server.kill()
+        self.server.wait()
+    
+    def init_repo(self):
+        "Should be overridden to initialise the repository."
+        raise NotImplementedError()
+    
+    def run_cmds(self, cmds, cwd=None):
+        if isinstance(cmds, basestring):
+            cmds = [cmds]
+        output = ""
+        for cmd in cmds:
+            process = subprocess.Popen(cmd, shell=True, cwd=cwd, stdout=subprocess.PIPE)
+            stdout, stderr = process.communicate()
+            output += stdout
+        return output
+    
+    def source_cmds(self, cmds):
+        "Runs a command[s] in the source (mercurial/git) directory."
+        return self.run_cmds(cmds, self.source_dir)
+    
+    def target_cmds(self, cmds):
+        "Runs a command[s] in the target (svn) directory."
+        return self.run_cmds(cmds, self.target_dir)
+    
+    def assert_exists(self, path):
+        "Asserts that a file exists in the target."
+        assert os.path.exists(os.path.join(self.target_dir, path)), "%s does not exist" % path
+    
+    def assert_exists_source(self, path):
+        "Asserts that a file exists in the source."
+        assert os.path.exists(os.path.join(self.source_dir, path)), "%s does not exist" % path
+    
+    def assert_not_exists(self, path):
+        "Asserts that a file does not exist in the target."
+        assert not os.path.exists(os.path.join(self.target_dir, path)), "%s exists" % path
+    
+    def assert_not_exists_source(self, path):
+        "Asserts that a file exists in the source."
+        assert not os.path.exists(os.path.join(self.source_dir, path)), "%s exists" % path
+    
+    def assert_contents(self, path, supposed_contents):
+        "Asserts that a the contents of the given file are exactly as provided."
+        fh = open(os.path.join(self.target_dir, path))
+        contents = fh.read()
+        fh.close()
+        self.assertEqual(contents, supposed_contents)
+    
+    def assert_contents_source(self, path, supposed_contents):
+        "Asserts that a the contents of the given file are exactly as provided."
+        fh = open(os.path.join(self.source_dir, path))
+        contents = fh.read()
+        fh.close()
+        self.assertEqual(contents, supposed_contents)
+    
+    def assert_contains(self, haystack, needle):
+        "Asserts that needle is somewhere in the string haystack."
+        assert needle in haystack, "String %r not found in %r" % (needle, haystack)
+    
+    def assert_not_contains(self, haystack, needle):
+        "Asserts that needle is not somewhere in the string haystack."
+        assert needle not in haystack, "String %r found in %r" % (needle, haystack)
+    
+    def assert_equal(self, item1, item2):
+        "assertEqual doesn't follow PEP8, damnit."
+        return self.assertEqual(item1, item2)

heechee/tests/mercurial.py

+"""
+Mercurial backend unit tests.
+"""
+
+import unittest
+from heechee.base import HeecheeTest
+
+class BasicMercurialTests(HeecheeTest):
+    
+    def init_repo(self):
+        self.source_cmds([
+            "hg init",
+            "echo a > a",
+            "hg ci -Am adda",
+            "hg branch branch1",
+            "echo b > b",
+            "hg ci -Am addb",
+            "mkdir dir",
+            "echo c > dir/c",
+            "hg ci -Am addc",
+            "hg tag tag1",
+        ])
+    
+    def test_checkout_all(self):
+        # Checkout the whole repo
+        self.target_cmds([
+            "svn co http://localhost:8080/ checkout"
+        ])
+        # Check things are there
+        self.assert_contents("checkout/trunk/a", "a\n")
+        self.assert_contents("checkout/tags/tip/a", "a\n")
+        self.assert_contents("checkout/branches/branch1/b", "b\n")
+        self.assert_contents("checkout/branches/branch1/dir/c", "c\n")
+        # Check there's no default branch (it's trunk)
+        self.assert_not_exists("checkout/branches/default/a")
+    
+    def test_checkout_trunk(self):
+        # Checkout a subdir
+        self.target_cmds([
+            "svn co http://localhost:8080/trunk/ checkout"
+        ])
+        # Make sure it only has file a
+        self.assert_contents("checkout/a", "a\n")
+        self.assert_not_exists("checkout/b")
+        self.assert_not_exists("checkout/c")
+    
+    def test_checkout_tag(self):
+        # Checkout the tag
+        self.target_cmds([
+            "svn co http://localhost:8080/tags/tag1/ checkout"
+        ])
+        # Make sure the files are there
+        self.assert_contents("checkout/a", "a\n")
+        self.assert_contents("checkout/b", "b\n")
+        self.assert_contents("checkout/dir/c", "c\n")
+    
+    def test_checkout_subdir(self):
+        self.target_cmds([
+            "svn co http://localhost:8080/branches/branch1/dir/ checkout"
+        ])
+        self.assert_contents("checkout/c", "c\n")
+        self.assert_not_exists("checkout/a")
+        self.assert_not_exists("checkout/b")
+    
+    def test_ls(self):
+        self.assert_equal(
+            self.target_cmds("svn ls http://localhost:8080/"),
+            "branches/\ntags/\ntrunk/\n",
+        )
+        self.assert_equal(
+            self.target_cmds("svn ls http://localhost:8080/trunk/"),
+            "a\n",
+        )
+    
+    def test_update(self):
+        # First, get a checkout.
+        self.target_cmds("svn co http://localhost:8080/trunk/ checkout")
+        # Make sure there's no file d (or b)
+        self.assert_not_exists("checkout/b")
+        self.assert_not_exists("checkout/d")
+        # Add one and commit to the source repo
+        self.source_cmds([
+            "hg up -C default",
+            "echo d > d",
+            "hg ci -Am addd",
+        ])
+        # Update
+        self.target_cmds("svn up checkout")
+        # Check d has appeared
+        self.assert_not_exists("checkout/b")
+        self.assert_contents("checkout/d", "d\n")
+    
+    def test_log(self):
+        # Get the log directly
+        log = self.target_cmds("svn log http://localhost:8080/")
+        # Check it contains certain vital things
+        self.assert_contains(log, "r1 |")
+        self.assert_contains(log, "r2 |")
+        self.assert_contains(log, "r3 |")
+        self.assert_contains(log, "r4 |")
+        self.assert_not_contains(log, "r5 |")
+        self.assert_contains(log, "\nadda\n")
+        self.assert_contains(log, "\naddb\n")
+        self.assert_contains(log, "\naddc\n")
+        self.assert_contains(log, "\nAdded tag tag1")
+        # Get the log for trunk (only had one commit)
+        log = self.target_cmds("svn log http://localhost:8080/trunk/")
+        self.assert_contains(log, "r1 |")
+        self.assert_not_contains(log, "r2 |")
+        # Check out the code, get the log from there (well, server still...)
+        self.target_cmds("svn co http://localhost:8080/ checkout")
+        log = self.target_cmds("svn log checkout")
+        # Check it contains certain vital things
+        self.assert_contains(log, "r1 |")
+        self.assert_contains(log, "r2 |")
+        self.assert_contains(log, "r3 |")
+        self.assert_contains(log, "r4 |")
+        self.assert_not_contains(log, "r5 |")
+        self.assert_contains(log, "\nadda\n")
+        self.assert_contains(log, "\naddb\n")
+        self.assert_contains(log, "\naddc\n")
+        self.assert_contains(log, "\nAdded tag tag1")
+    
+    def test_commit(self):
+        "Tests committing to the fake SVN repo"
+        # Check out a copy of trunk, create a new file, add it, and commit it
+        self.target_cmds([
+            "svn co http://localhost:8080/trunk/ checkout",
+            "echo e > checkout/e",
+            "echo aa > checkout/a",
+            "svn add checkout/e",
+            "svn ci checkout -m 'Commit from SVN'",
+        ])
+        # Update the mercurial repo to default, make sure it's there
+        self.source_cmds("hg up -C default")
+        self.assert_exists_source("e")
+        self.assert_contents_source("e", "e\n")
+        self.assert_contents_source("a", "aa\n")
+        # Remove that new file, make sure it goes.
+        self.target_cmds([
+            "svn rm checkout/e",
+            "svn ci checkout -m 'Second commit from SVN'",
+        ])
+        self.source_cmds("hg up -C default")
+        self.assert_not_exists_source("e")
+        self.assert_contents_source("a", "aa\n")
+    
+    def test_commit_directories(self):
+        "Tests committing directories. Mercurial should ignore these."
+        # Check out a copy of trunk, create a new file, add it, and commit it
+        self.target_cmds([
+            "svn co http://localhost:8080/trunk/ checkout",
+            "svn mkdir checkout/newdir",
+            "svn ci checkout -m 'Commit from SVN'",
+        ])
+        # Update the mercurial repo to default, make sure it's not there
+        self.source_cmds("hg up -C default")
+        self.assert_not_exists_source("newdir")
+        # Add a file into it, make sure that appears
+        self.target_cmds([
+            "echo ff > checkout/newdir/f",
+            "svn add checkout/newdir/f",
+            "svn ci checkout -m 'Commit 2 from SVN'",
+        ])
+        self.source_cmds("hg up -C default")
+        self.assert_exists_source("newdir/f")
+
+
+if __name__ == '__main__':
+    unittest.main()

heechee/tests/svndiff.py

+
+import unittest
+
+from heechee.svndiff import StringIO, make_cheap_diff, undiff
+from heechee.base import HeecheeTest
+
+class SvnDiffTests(HeecheeTest):
+    pass

tests/base.py

-"""
-Base classes for the test suite.
-"""
-
-import os
-import unittest
-import tempfile
-import subprocess
-import shutil
-import time
-import socket
-try:
-    from cStringIO import StringIO
-except ImportError:
-    from StringIO import StringIO
-
-class HeecheeTest(unittest.TestCase):
-    
-    def setUp(self):
-        "Sets up a target directory and a source repo."
-        self.source_dir = tempfile.mkdtemp(suffix="-heechee-src")
-        self.init_repo()
-        self.target_dir = tempfile.mkdtemp(suffix="-heechee-tgt")
-        self.server = subprocess.Popen(
-            ["python", "-m", "heechee.webdav.__init__", self.source_dir],
-            stdout=subprocess.PIPE,
-            #stderr=subprocess.PIPE,
-        )
-        # Wait for server to come up
-        for i in range(20):
-            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-            try:
-                s.connect(('localhost', 8080))
-            except socket.error:
-                time.sleep(0.25)
-            else:
-                return
-        raise RuntimeError("Cannot seem to launch Heechee")
-    
-    def tearDown(self):
-        "Deletes the target directory"
-        shutil.rmtree(self.source_dir)
-        shutil.rmtree(self.target_dir)
-        # Kill server, and wait till it dies
-        self.server.kill()
-        self.server.wait()
-    
-    def init_repo(self):
-        "Should be overridden to initialise the repository."
-        raise NotImplementedError()
-    
-    def run_cmds(self, cmds, cwd=None):
-        if isinstance(cmds, basestring):
-            cmds = [cmds]
-        output = ""
-        for cmd in cmds:
-            process = subprocess.Popen(cmd, shell=True, cwd=cwd, stdout=subprocess.PIPE)
-            stdout, stderr = process.communicate()
-            output += stdout
-        return output
-    
-    def source_cmds(self, cmds):
-        "Runs a command[s] in the source (mercurial/git) directory."
-        return self.run_cmds(cmds, self.source_dir)
-    
-    def target_cmds(self, cmds):
-        "Runs a command[s] in the target (svn) directory."
-        return self.run_cmds(cmds, self.target_dir)
-    
-    def assert_exists(self, path):
-        "Asserts that a file exists in the target."
-        assert os.path.exists(os.path.join(self.target_dir, path)), "%s does not exist" % path
-    
-    def assert_exists_source(self, path):
-        "Asserts that a file exists in the source."
-        assert os.path.exists(os.path.join(self.source_dir, path)), "%s does not exist" % path
-    
-    def assert_not_exists(self, path):
-        "Asserts that a file does not exist in the target."
-        assert not os.path.exists(os.path.join(self.target_dir, path)), "%s exists" % path
-    
-    def assert_not_exists_source(self, path):
-        "Asserts that a file exists in the source."
-        assert not os.path.exists(os.path.join(self.source_dir, path)), "%s exists" % path
-    
-    def assert_contents(self, path, supposed_contents):
-        "Asserts that a the contents of the given file are exactly as provided."
-        fh = open(os.path.join(self.target_dir, path))
-        contents = fh.read()
-        fh.close()
-        self.assertEqual(contents, supposed_contents)
-    
-    def assert_contents_source(self, path, supposed_contents):
-        "Asserts that a the contents of the given file are exactly as provided."
-        fh = open(os.path.join(self.source_dir, path))
-        contents = fh.read()
-        fh.close()
-        self.assertEqual(contents, supposed_contents)
-    
-    def assert_contains(self, haystack, needle):
-        "Asserts that needle is somewhere in the string haystack."
-        assert needle in haystack, "String %r not found in %r" % (needle, haystack)
-    
-    def assert_not_contains(self, haystack, needle):
-        "Asserts that needle is not somewhere in the string haystack."
-        assert needle not in haystack, "String %r found in %r" % (needle, haystack)
-    
-    def assert_equal(self, item1, item2):
-        "assertEqual doesn't follow PEP8, damnit."
-        return self.assertEqual(item1, item2)

tests/mercurial.py

-"""
-Mercurial backend unit tests.
-"""
-
-import unittest
-from heechee.base import HeecheeTest
-
-class BasicMercurialTests(HeecheeTest):
-    
-    def init_repo(self):
-        self.source_cmds([
-            "hg init",
-            "echo a > a",
-            "hg ci -Am adda",
-            "hg branch branch1",
-            "echo b > b",
-            "hg ci -Am addb",
-            "mkdir dir",
-            "echo c > dir/c",
-            "hg ci -Am addc",
-            "hg tag tag1",
-        ])
-    
-    def test_checkout_all(self):
-        # Checkout the whole repo
-        self.target_cmds([
-            "svn co http://localhost:8080/ checkout"
-        ])
-        # Check things are there
-        self.assert_contents("checkout/trunk/a", "a\n")
-        self.assert_contents("checkout/tags/tip/a", "a\n")
-        self.assert_contents("checkout/branches/branch1/b", "b\n")
-        self.assert_contents("checkout/branches/branch1/dir/c", "c\n")
-        # Check there's no default branch (it's trunk)
-        self.assert_not_exists("checkout/branches/default/a")
-    
-    def test_checkout_trunk(self):
-        # Checkout a subdir
-        self.target_cmds([
-            "svn co http://localhost:8080/trunk/ checkout"
-        ])
-        # Make sure it only has file a
-        self.assert_contents("checkout/a", "a\n")
-        self.assert_not_exists("checkout/b")
-        self.assert_not_exists("checkout/c")
-    
-    def test_checkout_tag(self):
-        # Checkout the tag
-        self.target_cmds([
-            "svn co http://localhost:8080/tags/tag1/ checkout"
-        ])
-        # Make sure the files are there
-        self.assert_contents("checkout/a", "a\n")
-        self.assert_contents("checkout/b", "b\n")
-        self.assert_contents("checkout/dir/c", "c\n")
-    
-    def test_checkout_subdir(self):
-        self.target_cmds([
-            "svn co http://localhost:8080/branches/branch1/dir/ checkout"
-        ])
-        self.assert_contents("checkout/c", "c\n")
-        self.assert_not_exists("checkout/a")
-        self.assert_not_exists("checkout/b")
-    
-    def test_ls(self):
-        self.assert_equal(
-            self.target_cmds("svn ls http://localhost:8080/"),
-            "branches/\ntags/\ntrunk/\n",
-        )
-        self.assert_equal(
-            self.target_cmds("svn ls http://localhost:8080/trunk/"),
-            "a\n",
-        )
-    
-    def test_update(self):
-        # First, get a checkout.
-        self.target_cmds("svn co http://localhost:8080/trunk/ checkout")
-        # Make sure there's no file d (or b)
-        self.assert_not_exists("checkout/b")
-        self.assert_not_exists("checkout/d")
-        # Add one and commit to the source repo
-        self.source_cmds([
-            "hg up -C default",
-            "echo d > d",
-            "hg ci -Am addd",
-        ])
-        # Update
-        self.target_cmds("svn up checkout")
-        # Check d has appeared
-        self.assert_not_exists("checkout/b")
-        self.assert_contents("checkout/d", "d\n")
-    
-    def test_log(self):
-        # Get the log directly
-        log = self.target_cmds("svn log http://localhost:8080/")
-        # Check it contains certain vital things
-        self.assert_contains(log, "r1 |")
-        self.assert_contains(log, "r2 |")
-        self.assert_contains(log, "r3 |")
-        self.assert_contains(log, "r4 |")
-        self.assert_not_contains(log, "r5 |")
-        self.assert_contains(log, "\nadda\n")
-        self.assert_contains(log, "\naddb\n")
-        self.assert_contains(log, "\naddc\n")
-        self.assert_contains(log, "\nAdded tag tag1")
-        # Get the log for trunk (only had one commit)
-        log = self.target_cmds("svn log http://localhost:8080/trunk/")
-        self.assert_contains(log, "r1 |")
-        self.assert_not_contains(log, "r2 |")
-        # Check out the code, get the log from there (well, server still...)
-        self.target_cmds("svn co http://localhost:8080/ checkout")
-        log = self.target_cmds("svn log checkout")
-        # Check it contains certain vital things
-        self.assert_contains(log, "r1 |")
-        self.assert_contains(log, "r2 |")
-        self.assert_contains(log, "r3 |")
-        self.assert_contains(log, "r4 |")
-        self.assert_not_contains(log, "r5 |")
-        self.assert_contains(log, "\nadda\n")
-        self.assert_contains(log, "\naddb\n")
-        self.assert_contains(log, "\naddc\n")
-        self.assert_contains(log, "\nAdded tag tag1")
-    
-    def test_commit(self):
-        "Tests committing to the fake SVN repo"
-        # Check out a copy of trunk, create a new file, add it, and commit it
-        self.target_cmds([
-            "svn co http://localhost:8080/trunk/ checkout",
-            "echo e > checkout/e",
-            "echo aa > checkout/a",
-            "svn add checkout/e",
-            "svn ci checkout -m 'Commit from SVN'",
-        ])
-        # Update the mercurial repo to default, make sure it's there
-        self.source_cmds("hg up -C default")
-        self.assert_exists_source("e")
-        self.assert_contents_source("e", "e\n")
-        self.assert_contents_source("a", "aa\n")
-        # Remove that new file, make sure it goes.
-        self.target_cmds([
-            "svn rm checkout/e",
-            "svn ci checkout -m 'Second commit from SVN'",
-        ])
-        self.source_cmds("hg up -C default")
-        self.assert_not_exists_source("e")
-        self.assert_contents_source("a", "aa\n")
-    
-    def test_commit_directories(self):
-        "Tests committing directories. Mercurial should ignore these."
-        # Check out a copy of trunk, create a new file, add it, and commit it
-        self.target_cmds([
-            "svn co http://localhost:8080/trunk/ checkout",
-            "svn mkdir checkout/newdir",
-            "svn ci checkout -m 'Commit from SVN'",
-        ])
-        # Update the mercurial repo to default, make sure it's not there
-        self.source_cmds("hg up -C default")
-        self.assert_not_exists_source("newdir")
-        # Add a file into it, make sure that appears
-        self.target_cmds([
-            "echo ff > checkout/newdir/f",
-            "svn add checkout/newdir/f",
-            "svn ci checkout -m 'Commit 2 from SVN'",
-        ])
-        self.source_cmds("hg up -C default")
-        self.assert_exists_source("newdir/f")
-
-
-if __name__ == '__main__':
-    unittest.main()

tests/svndiff.py

-
-import unittest
-
-from heechee.svndiff import StringIO, make_cheap_diff, undiff
-from heechee.base import HeecheeTest
-
-class SvnDiffTests(HeecheeTest):
-    pass