Patchwork [2,of,4,V4] hghave: add "py3k" feature to check whether test runs with Python 3.x

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 4, 2013, 4:19 p.m.
Message ID <8fb6dc24cd54553cfafe.1380903546@juju>
Download mbox | patch
Permalink /patch/2734/
State Accepted
Commit 8bbe208c181228b7974b98e62e1732d2263d6b4d
Headers show

Comments

Katsunori FUJIWARA - Oct. 4, 2013, 4:19 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1380902542 -32400
#      Sat Oct 05 01:02:22 2013 +0900
# Node ID 8fb6dc24cd54553cfafe43d6c6d4b6c598340da5
# Parent  6b27b9c806334c88e3f0190ed345e84dbc8a894d
hghave: add "py3k" feature to check whether test runs with Python 3.x

This patch adds "py3k" feature to check whether test runs with Python
3.x.

This check is needed for portability of test code: for example, in the
default, modules are imported relatively first with python 2.x, but
imported absolutely with Python 3.x.

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -282,6 +282,9 @@ 
     from mercurial import util
     return util.safehasattr(__future__, "absolute_import")
 
+def has_py3k():
+    return 3 == sys.version_info[0]
+
 checks = {
     "true": (lambda: True, "yak shaving"),
     "false": (lambda: False, "nail clipper"),
@@ -324,4 +327,5 @@ 
     "msys": (has_msys, "Windows with MSYS"),
     "aix": (has_aix, "AIX"),
     "absimport": (has_absimport, "absolute_import in __future__"),
+    "py3k": (has_py3k, "running with Python 3.x"),
 }