X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/991d037e7b4741450dff745d22b0758170fe4ed9..9997ada67ce36d2fbe831bce473aa61250727aff:/sdk/python/tests/arvados_testutil.py diff --git a/sdk/python/tests/arvados_testutil.py b/sdk/python/tests/arvados_testutil.py index 23f00b6415..21b3f15dc6 100644 --- a/sdk/python/tests/arvados_testutil.py +++ b/sdk/python/tests/arvados_testutil.py @@ -1,4 +1,6 @@ -#!/usr/bin/env python +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 from future import standard_library standard_library.install_aliases() @@ -22,9 +24,10 @@ import tempfile import unittest if sys.version_info >= (3, 0): - from io import StringIO + from io import StringIO, BytesIO else: from cStringIO import StringIO + BytesIO = StringIO # Use this hostname when you want to make sure the traffic will be # instantly refused. 100::/64 is a dedicated black hole. @@ -90,7 +93,7 @@ class VersionChecker(object): # Python 2 writes version info on stderr. self.assertEqual(out.getvalue(), '') v = err.getvalue() - self.assertRegexpMatches(v, "[0-9]+\.[0-9]+\.[0-9]+$\n") + self.assertRegex(v, r"[0-9]+\.[0-9]+\.[0-9]+$\n") class FakeCurl(object): @@ -261,3 +264,13 @@ class ArvadosBaseTestCase(unittest.TestCase): testfile.write(text) testfile.flush() return testfile + +if sys.version_info < (3, 0): + # There is no assert[Not]Regex that works in both Python 2 and 3, + # so we backport Python 3 style to Python 2. + def assertRegex(self, *args, **kwargs): + return self.assertRegexpMatches(*args, **kwargs) + def assertNotRegex(self, *args, **kwargs): + return self.assertNotRegexpMatches(*args, **kwargs) + unittest.TestCase.assertRegex = assertRegex + unittest.TestCase.assertNotRegex = assertNotRegex