[PATCH 1 of 2 hglib] tests: add a nose plugin that allows specifying a custom hg to run tests

Idan Kamara idankk86 at gmail.com
Sat Oct 15 13:11:12 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1318701784 -7200
# Node ID f4f636ecca3ee65d39fd2dd9621a738121b1187c
# Parent  a5dd7b5d0be11a52a5207f421db6e90751fe548e
tests: add a nose plugin that allows specifying a custom hg to run tests

diff --git a/tests/with_hg.py b/tests/with_hg.py
new file mode 100644
--- /dev/null
+++ b/tests/with_hg.py
@@ -0,0 +1,33 @@
+import os
+from nose.plugins import Plugin
+
+class WithHgPlugin(Plugin):
+    name = 'with-hg'
+    enabled = False
+
+    def options(self, parser, env):
+        Plugin.options(self, parser, env)
+        parser.add_option('--with-hg',
+                          action='store',
+                          type='string',
+                          metavar='HG',
+                          dest='with_hg',
+                          help='test using specified hg script.')
+
+    def configure(self, options, conf):
+        Plugin.configure(self, options, conf)
+        if options.with_hg:
+            self.enabled = True
+            self.hgpath = os.path.realpath(options.with_hg)
+
+    def begin(self):
+        import hglib
+
+        p = hglib.util.popen([self.hgpath, 'version'])
+        p.communicate()
+
+        if p.returncode:
+            raise ValueError("custom hg %r doesn't look like Mercurial"
+                             % self.hgpath)
+
+        hglib.HGPATH = self.hgpath


More information about the Mercurial-devel mailing list