Patchwork D9452: run-tests: fix a socket context manager for py2

login
register
mail settings
Submitter phabricator
Date Nov. 29, 2020, 4 a.m.
Message ID <differential-rev-PHID-DREV-isimdm56hj7gxf7dc35m-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47730/
State Superseded
Headers show

Comments

phabricator - Nov. 29, 2020, 4 a.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  I broke this in e1404a75cddd <https://phab.mercurial-scm.org/rHGe1404a75cddd453d1c75c80087ae2d054f8c9265>, because the socket class lacks `__exit__` on py2.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D9452

AFFECTED FILES
  tests/run-tests.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -47,6 +47,7 @@ 
 
 import argparse
 import collections
+import contextlib
 import difflib
 import distutils.version as version
 import errno
@@ -255,7 +256,7 @@ 
     else:
         family = socket.AF_INET
     try:
-        with socket.socket(family, socket.SOCK_STREAM) as s:
+        with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s:
             s.bind(('localhost', port))
         return True
     except socket.error as exc: