changeset 264:3caa2ce52cd9

tests: inline unit tests into main test suite
author Augie Fackler <durin42@gmail.com>
date Tue, 27 Oct 2009 22:39:45 -0400
parents 9f5a7a5d52aa
children 5790ef252511
files tests/test-topo-sort.py tests/test-topo-sort.py.out tests/test-url-parsing.py tests/test-url-parsing.py.out unit-tests/topo-test.py unit-tests/url-test.py
diffstat 4 files changed, 61 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
old mode 100644
new mode 100755
rename from unit-tests/topo-test.py
rename to tests/test-topo-sort.py
--- a/unit-tests/topo-test.py
+++ b/tests/test-topo-sort.py
@@ -1,15 +1,14 @@
 import random, sys
-import unittest
 
 sys.path.append('../')
 
-import toposort
+from hggit import toposort
 
 class Ob:
     def __init__(self, eyedee, parents):
         self._id = eyedee
         self.parents = parents
-        
+
     def id(self):
         return self._id
 
@@ -21,26 +20,26 @@
 # |/  |
 # c   d
 # |\ /
-# h b 
+# h b
 # |/
-# a 
-
-class TestTopoSorting(unittest.TestCase):
+# a
 
-    def testsort(self):
-        data = {
-         'f' : Ob('f', ['d', 'e']),
-         'd' : Ob('d', ['b']),
-         'e' : Ob('e', ['c', 'g']),
-         'g' : Ob('g', ['c']),
-         'c' : Ob('c', ['b', 'h']),
-         'b' : Ob('b', ['a']),
-         'h' : Ob('h', ['a']),
-         'a' : Ob('a', []),
-        }
-        d = toposort.TopoSort(data).items()
-        sort = ['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
-        self.assertEquals(d, sort)
+def testsort():
+    data = {
+     'f' : Ob('f', ['d', 'e']),
+     'd' : Ob('d', ['b']),
+     'e' : Ob('e', ['c', 'g']),
+     'g' : Ob('g', ['c']),
+     'c' : Ob('c', ['b', 'h']),
+     'b' : Ob('b', ['a']),
+     'h' : Ob('h', ['a']),
+     'a' : Ob('a', []),
+    }
+    d = toposort.TopoSort(data).items()
+    sort = ['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
+    print '%% should sort to %r' % (sort, )
+    print d
+
 
 if __name__ == '__main__':
-    unittest.main()
+    testsort()
new file mode 100644
--- /dev/null
+++ b/tests/test-topo-sort.py.out
@@ -0,0 +1,2 @@
+% should sort to ['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
+['a', 'b', 'd', 'h', 'c', 'g', 'e', 'f']
old mode 100644
new mode 100755
rename from unit-tests/url-test.py
rename to tests/test-url-parsing.py
--- a/unit-tests/url-test.py
+++ b/tests/test-url-parsing.py
@@ -1,48 +1,59 @@
 import sys, tempfile, unittest, shutil
 from mercurial import ui, hg, commands
 
-sys.path.append('../hggit')
+sys.path.append('../')
 
-from git_handler import GitHandler
+from hggit.git_handler import GitHandler
 
 
-class TestUrlParsing(unittest.TestCase):
-  
+class TestUrlParsing(object):
     def setUp(self):
         # create a test repo location.
         self.tmpdir = tempfile.mkdtemp('hg-git_url-test')
         commands.init(ui.ui(), self.tmpdir)
         repo = hg.repository(ui.ui(), self.tmpdir)
         self.handler = GitHandler(repo, ui.ui())
-        
+
     def tearDown(self):
         # remove the temp repo
         shutil.rmtree(self.tmpdir)
-        
+
+    def assertEquals(self, l, r):
+        print '%% expect %r' % (r, )
+        print l
+        assert l == r
+
     def test_ssh_github_style_slash(self):
         url = "git+ssh://git@github.com/webjam/webjam.git"
         client, path = self.handler.get_transport_and_path(url)
         self.assertEquals(path, '/webjam/webjam.git')
         self.assertEquals(client.host, 'git@github.com')
-        
+
     def test_ssh_github_style_colon(self):
         url = "git+ssh://git@github.com:webjam/webjam.git"
         client, path = self.handler.get_transport_and_path(url)
         self.assertEquals(path, 'webjam/webjam.git')
         self.assertEquals(client.host, 'git@github.com')
-        
+
     def test_ssh_heroku_style(self):
         url = "git+ssh://git@heroku.com:webjam.git"
         client, path = self.handler.get_transport_and_path(url)
         self.assertEquals(path, 'webjam.git')
         self.assertEquals(client.host, 'git@heroku.com')
-        
+
     def test_gitdaemon_style(self):
         url = "git://github.com/webjam/webjam.git"
         client, path = self.handler.get_transport_and_path(url)
         self.assertEquals(path, '/webjam/webjam.git')
         self.assertEquals(client.host, 'github.com')
-        
+
 
 if __name__ == '__main__':
-    unittest.main()
+    tc = TestUrlParsing()
+    for test in ['test_ssh_github_style_slash',
+                 'test_ssh_github_style_colon',
+                 'test_ssh_heroku_style',
+                 'test_gitdaemon_style']:
+        tc.setUp()
+        getattr(tc, test)()
+        tc.tearDown()
new file mode 100644
--- /dev/null
+++ b/tests/test-url-parsing.py.out
@@ -0,0 +1,16 @@
+% expect '/webjam/webjam.git'
+/webjam/webjam.git
+% expect 'git@github.com'
+git@github.com
+% expect 'webjam/webjam.git'
+webjam/webjam.git
+% expect 'git@github.com'
+git@github.com
+% expect 'webjam.git'
+webjam.git
+% expect 'git@heroku.com'
+git@heroku.com
+% expect '/webjam/webjam.git'
+/webjam/webjam.git
+% expect 'github.com'
+github.com