# HG changeset patch # User Augie Fackler # Date 2015-09-01 02:44:20 # Node ID 99e8a9ff1f5f049692e8f0b90cfd7a04fd357aae # Parent 6defc74f30667c52088f35d8874426b4a46a2c8c hghave: use subprocess instead of os.popen os.popen was deprecated in Python 2.6 in favor of subprocess, so let's move into the future. diff --git a/tests/hghave.py b/tests/hghave.py --- a/tests/hghave.py +++ b/tests/hghave.py @@ -1,6 +1,9 @@ -import os, stat +import errno +import os import re import socket +import stat +import subprocess import sys import tempfile @@ -69,14 +72,16 @@ def matchoutput(cmd, regexp, ignorestatu is matched by the supplied regular expression. """ r = re.compile(regexp) - fh = os.popen(cmd) - s = fh.read() try: - ret = fh.close() - except IOError: - # Happen in Windows test environment - ret = 1 - return (ignorestatus or ret is None) and r.search(s) + p = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + except OSError as e: + if e.errno != errno.ENOENT: + raise + ret = -1 + ret = p.wait() + s = p.stdout.read() + return (ignorestatus or not ret) and r.search(s) @check("baz", "GNU Arch baz client") def has_baz():