changeset 16:48a44546c12f

Add a basic system for running the hgsubversion tests (although not the svnwrap ones) without requiring Nose. Nose is still the recommended way to run the tests. Also added some tests for pushing.
author Augie Fackler <durin42@gmail.com>
date Tue, 07 Oct 2008 22:13:14 -0500
parents db32dee803a8
children 31aa63ac778c
files tests/run.py tests/test_fetch_command.py tests/test_fetch_command_regexes.py tests/test_push_command.py tests/test_util.py tests/util.py
diffstat 5 files changed, 199 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/tests/run.py
@@ -0,0 +1,19 @@
+import os
+import sys
+import unittest
+
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import test_fetch_command
+import test_fetch_command_regexes
+import test_push_command
+
+def suite():
+    return unittest.TestSuite([test_fetch_command.suite(),
+                               test_fetch_command_regexes.suite(),
+                               test_fetch_command_regexes.suite(),
+                              ])
+
+if __name__ == '__main__':
+    runner = unittest.TextTestRunner()
+    runner.run(suite())
--- a/tests/test_fetch_command.py
+++ b/tests/test_fetch_command.py
@@ -8,7 +8,7 @@ from mercurial import ui
 from mercurial import node
 
 import fetch_command
-import util
+import test_util
 
 class TestBasicRepoLayout(unittest.TestCase):
     def setUp(self):
@@ -22,7 +22,7 @@ class TestBasicRepoLayout(unittest.TestC
         os.chdir(self.oldwd)
 
     def test_fresh_fetch_single_rev(self):
-        util.load_svndump_fixture(self.repo_path, 'single_rev.svndump')
+        test_util.load_svndump_fixture(self.repo_path, 'single_rev.svndump')
         fetch_command.fetch_revisions(ui.ui(), 
                                       svn_url='file://%s' % self.repo_path, 
                                       hg_repo_path=self.wc_path)
@@ -32,7 +32,7 @@ class TestBasicRepoLayout(unittest.TestC
         self.assertEqual(repo['tip'], repo[0])
 
     def test_fresh_fetch_two_revs(self):
-        util.load_svndump_fixture(self.repo_path, 'two_revs.svndump')
+        test_util.load_svndump_fixture(self.repo_path, 'two_revs.svndump')
         fetch_command.fetch_revisions(ui.ui(), 
                                       svn_url='file://%s' % self.repo_path, 
                                       hg_repo_path=self.wc_path)
@@ -45,7 +45,7 @@ class TestBasicRepoLayout(unittest.TestC
         self.assertEqual(repo['tip'], repo[1])
 
     def test_branches(self):
-        util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump')
+        test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump')
         fetch_command.fetch_revisions(ui.ui(), 
                                       svn_url='file://%s' % self.repo_path, 
                                       hg_repo_path=self.wc_path)
@@ -60,7 +60,7 @@ class TestBasicRepoLayout(unittest.TestC
         self.assertEqual(len(repo.heads()), 1)
 
     def test_two_branches_with_heads(self):
-        util.load_svndump_fixture(self.repo_path, 'two_heads.svndump')
+        test_util.load_svndump_fixture(self.repo_path, 'two_heads.svndump')
         fetch_command.fetch_revisions(ui.ui(), 
                                       svn_url='file://%s' % self.repo_path, 
                                       hg_repo_path=self.wc_path)
@@ -77,3 +77,6 @@ class TestBasicRepoLayout(unittest.TestC
         self.assertEqual(len(repo['tip'].parents()), 1)
         self.assertEqual(repo['tip'], repo['default'])
         self.assertEqual(len(repo.heads()), 2)
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(TestBasicRepoLayout)
--- a/tests/test_fetch_command_regexes.py
+++ b/tests/test_fetch_command_regexes.py
@@ -1,4 +1,5 @@
 import fetch_command
+import unittest
 
 two_empties = """Index: __init__.py
 ===================================================================
@@ -14,21 +15,6 @@ Index: bar/test_muhaha.py
 \ No newline at end of file
 """
 
-def test_empty_file_re():
-    matches = fetch_command.empty_file_patch_wont_make_re.findall(two_empties)
-    assert sorted(matches) == ['__init__.py', 'bar/__init__.py']
-
-def test_any_matches_just_one():
-    pat = '''Index: trunk/django/contrib/admin/urls/__init__.py
-===================================================================
-'''
-    matches = fetch_command.any_file_re.findall(pat)
-    assert len(matches) == 1
-
-def test_any_file_re():
-    matches = fetch_command.any_file_re.findall(two_empties)
-    assert sorted(matches) == ['__init__.py', 'bar/__init__.py',
-                               'bar/test_muhaha.py']
 binary_delta = """Index: trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures_fixtures.pyc
 ===================================================================
 Cannot display: file marked as a binary type.
@@ -42,7 +28,27 @@ Added: svn:mime-type
 Index: trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures.rst
 ===================================================================
 """
-def test_binary_file_re():
-    matches = fetch_command.binary_file_re.findall(binary_delta)
-    print matches
-    assert matches == ['trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures_fixtures.pyc']
+
+class RegexTests(unittest.TestCase):
+    def test_empty_file_re(self):
+        matches = fetch_command.empty_file_patch_wont_make_re.findall(two_empties)
+        assert sorted(matches) == ['__init__.py', 'bar/__init__.py']
+    
+    def test_any_matches_just_one(self):
+        pat = '''Index: trunk/django/contrib/admin/urls/__init__.py
+===================================================================
+'''
+        matches = fetch_command.any_file_re.findall(pat)
+        assert len(matches) == 1
+    
+    def test_any_file_re(self):
+        matches = fetch_command.any_file_re.findall(two_empties)
+        assert sorted(matches) == ['__init__.py', 'bar/__init__.py',
+                                   'bar/test_muhaha.py']
+
+    def test_binary_file_re(self):
+        matches = fetch_command.binary_file_re.findall(binary_delta)
+        assert matches == ['trunk/functional_tests/doc_tests/test_doctest_fixtures/doctest_fixtures_fixtures.pyc']
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(RegexTests)
new file mode 100644
--- /dev/null
+++ b/tests/test_push_command.py
@@ -0,0 +1,147 @@
+import os
+import shutil
+import tempfile
+import unittest
+
+from mercurial import context
+from mercurial import hg
+from mercurial import node
+from mercurial import ui
+from mercurial import revlog
+
+import fetch_command
+import push_cmd
+import test_util
+
+class PushTests(unittest.TestCase):
+    def setUp(self):
+        self.oldwd = os.getcwd()
+        self.tmpdir = tempfile.mkdtemp('svnwrap_test')
+        self.repo_path = '%s/testrepo' % self.tmpdir
+        self.wc_path = '%s/testrepo_wc' % self.tmpdir
+        test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump')
+        fetch_command.fetch_revisions(ui.ui(), 
+                                      svn_url='file://%s' % self.repo_path, 
+                                      hg_repo_path=self.wc_path)
+
+    # define this as a property so that it reloads anytime we need it
+    @property
+    def repo(self):
+        return hg.repository(ui.ui(), self.wc_path)
+
+    def tearDown(self):
+        shutil.rmtree(self.tmpdir)
+        os.chdir(self.oldwd)
+
+    def test_push_to_default(self, commit=True):
+        repo = self.repo
+        old_tip = repo['tip'].node()
+        expected_parent = repo['default'].node()
+        def file_callback(repo, memctx, path):
+            if path == 'adding_file':
+                return context.memfilectx(path=path,
+                                          data='foo',
+                                          islink=False,
+                                          isexec=False,
+                                          copied=False)
+            raise IOError()
+        ctx = context.memctx(repo,
+                             (repo['default'].node(), node.nullid),
+                             'automated test',
+                             ['adding_file'],
+                             file_callback,
+                             'an_author',
+                             '2008-10-07 20:59:48 -0500',
+                             {'branch': 'default',})
+        new_hash = repo.commitctx(ctx)
+        if not commit:
+            return # some tests use this test as an extended setup.
+        hg.update(repo, repo['tip'].node())
+        push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
+                                              hg_repo_path=self.wc_path,
+                                              svn_url='file://'+self.repo_path)
+        tip = self.repo['tip']
+        self.assertNotEqual(tip.node(), old_tip)
+        self.assertEqual(tip.parents()[0].node(), expected_parent)
+        self.assertEqual(tip['adding_file'].data(), 'foo')
+        self.assertEqual(tip.branch(), 'default')
+
+    def test_push_two_revs(self):
+        # set up some work for us
+        self.test_push_to_default(commit=False)
+        repo = self.repo
+        old_tip = repo['tip'].node()
+        expected_parent = repo['tip'].parents()[0].node()
+        def file_callback(repo, memctx, path):
+            if path == 'adding_file2':
+                return context.memfilectx(path=path,
+                                          data='foo2',
+                                          islink=False,
+                                          isexec=False,
+                                          copied=False)
+            raise IOError()
+        ctx = context.memctx(repo,
+                             (repo['default'].node(), node.nullid),
+                             'automated test',
+                             ['adding_file2'],
+                             file_callback,
+                             'an_author',
+                             '2008-10-07 20:59:48 -0500',
+                             {'branch': 'default',})
+        new_hash = repo.commitctx(ctx)
+        hg.update(repo, repo['tip'].node())
+        push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
+                                              hg_repo_path=self.wc_path,
+                                              svn_url='file://'+self.repo_path)
+        tip = self.repo['tip']
+        self.assertNotEqual(tip.node(), old_tip)
+        self.assertNotEqual(tip.parents()[0].node(), old_tip)
+        self.assertEqual(tip.parents()[0].parents()[0].node(), expected_parent)
+        self.assertEqual(tip['adding_file2'].data(), 'foo2')
+        self.assertEqual(tip['adding_file'].data(), 'foo')
+        self.assertEqual(tip.parents()[0]['adding_file'].data(), 'foo')
+        try:
+            self.assertEqual(tip.parents()[0]['adding_file2'].data(), 'foo')
+            assert False, "this is impossible, adding_file2 should not be in this manifest."
+        except revlog.LookupError, e:
+            pass
+        self.assertEqual(tip.branch(), 'default')
+
+    def test_push_to_branch(self):
+        repo = self.repo
+        def file_callback(repo, memctx, path):
+            if path == 'adding_file':
+                return context.memfilectx(path=path,
+                                          data='foo',
+                                          islink=False,
+                                          isexec=False,
+                                          copied=False)
+            raise IOError()
+        ctx = context.memctx(repo,
+                             (repo['the_branch'].node(), node.nullid),
+                             'automated test',
+                             ['adding_file'],
+                             file_callback,
+                             'an_author',
+                             '2008-10-07 20:59:48 -0500',
+                             {'branch': 'the_branch',})
+        new_hash = repo.commitctx(ctx)
+        push_cmd.push_revisions_to_subversion(ui.ui(), repo=self.repo,
+                                              hg_repo_path=self.wc_path,
+                                              svn_url='file://'+self.repo_path)
+        tip = self.repo['tip']
+        self.assertEqual(tip['adding_file'].data(), 'foo')
+        self.assertEqual(tip.branch(), 'the_branch')
+
+#
+#    def test_delete_file(self):
+#        assert False
+#
+#    def test_push_executable_file(self):
+#        assert False
+#
+#    def test_push_symlink_file(self):
+#        assert False
+
+def suite():
+    return unittest.TestLoader().loadTestsFromTestCase(PushTests)
rename from tests/util.py
rename to tests/test_util.py