[PATCH 4 of 9 hglib] tests: add check code test
Idan Kamara
idankk86 at gmail.com
Tue Aug 23 14:04:32 CDT 2011
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1314125825 -10800
# Node ID 4204eeea96a16864abd77f351fa78ec258313d39
# Parent d73a516dfb6a9216ee3770e06a421da54516c397
tests: add check code test
and fix 2 errors
diff -r d73a516dfb6a -r 4204eeea96a1 hglib/util.py
--- a/hglib/util.py Tue Aug 23 21:41:33 2011 +0300
+++ b/hglib/util.py Tue Aug 23 21:57:05 2011 +0300
@@ -83,7 +83,10 @@
arg = arg.replace('_', '-')
if arg != '-':
- arg = '-' + arg if len(arg) == 1 else '--' + arg
+ if len(arg) == 1:
+ arg = '-' + arg
+ else:
+ arg = '--' + arg
if isinstance(val, bool):
if val:
cmd.append(arg)
diff -r d73a516dfb6a -r 4204eeea96a1 tests/test-check-code.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-check-code.py Tue Aug 23 21:57:05 2011 +0300
@@ -0,0 +1,32 @@
+import unittest, hglib, os, sys, imp, cStringIO
+
+class test_check_code(unittest.TestCase):
+ def test_code(self):
+ rootdir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
+
+ # hg 1.9.1 needs os.getcwd() to work (dispatch._checkshellalias)
+ os.chdir(rootdir)
+
+ try:
+ repo = hglib.open(rootdir)
+ except hglib.error.ServerError:
+ sys.stderr.write('cannot check code on non-repository sources\n')
+ return
+
+ checkpath = os.path.join(rootdir, 'tests/check-code.py')
+ checkcode = imp.load_source('checkcode', checkpath)
+
+ checked = 0
+
+ checkcodeoutput = sys.stdout = cStringIO.StringIO()
+ for (node, perm, ex, sym, f) in repo.manifest():
+ checked += 1
+ checkcode.checkfile(os.path.join(rootdir, f))
+ sys.stdout = sys.__stdout__
+
+ if checkcodeoutput.getvalue():
+ print checkcodeoutput.getvalue()
+ self.assertFalse(checkcodeoutput.getvalue())
+
+ if not checked:
+ sys.stderr.write('no file checked!\n')
diff -r d73a516dfb6a -r 4204eeea96a1 tests/test-commit.py
--- a/tests/test-commit.py Tue Aug 23 21:41:33 2011 +0300
+++ b/tests/test-commit.py Tue Aug 23 21:57:05 2011 +0300
@@ -9,7 +9,8 @@
def test_no_user(self):
self.append('a', 'a')
- self.assertRaises(hglib.error.CommandError, self.client.commit, 'first', user='')
+ self.assertRaises(hglib.error.CommandError, self.client.commit, 'first',
+ user='')
def test_close_branch(self):
self.append('a', 'a')
More information about the Mercurial-devel
mailing list