mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-19 13:07:56 +00:00
Merge pull request #638 from tahoe-lafs/3232.deprecated-testing-helpers
Avoid failing CI when dependencies trigger deprecation warnings.
This commit is contained in:
commit
d5f647d03e
@ -1,6 +1,6 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys, os, io
|
||||
import sys, os, io, re
|
||||
from twisted.internet import reactor, protocol, task, defer
|
||||
from twisted.python.procutils import which
|
||||
from twisted.python import usage
|
||||
@ -12,6 +12,7 @@ from twisted.python import usage
|
||||
class Options(usage.Options):
|
||||
optParameters = [
|
||||
["warnings", None, None, "file to write warnings into at end of test run"],
|
||||
["package", None, None, "Python package to which to restrict warning collection"]
|
||||
]
|
||||
|
||||
def parseArgs(self, command, *args):
|
||||
@ -19,7 +20,7 @@ class Options(usage.Options):
|
||||
self["args"] = list(args)
|
||||
|
||||
description = """Run as:
|
||||
PYTHONWARNINGS=default::DeprecationWarning python run-deprecations.py [--warnings=STDERRFILE] COMMAND ARGS..
|
||||
PYTHONWARNINGS=default::DeprecationWarning python run-deprecations.py [--warnings=STDERRFILE] [--package=PYTHONPACKAGE ] COMMAND ARGS..
|
||||
"""
|
||||
|
||||
class RunPP(protocol.ProcessProtocol):
|
||||
@ -34,6 +35,34 @@ class RunPP(protocol.ProcessProtocol):
|
||||
rc = reason.value.exitCode
|
||||
self.d.callback((signal, rc))
|
||||
|
||||
|
||||
def make_matcher(options):
|
||||
"""
|
||||
Make a function that matches a line with a relevant deprecation.
|
||||
|
||||
A deprecation warning line looks something like this::
|
||||
|
||||
somepath/foo/bar/baz.py:43: DeprecationWarning: Foo is deprecated, try bar instead.
|
||||
|
||||
Sadly there is no guarantee warnings begin at the beginning of a line
|
||||
since they are written to output without coordination with whatever other
|
||||
Python code is running in the process.
|
||||
|
||||
:return: A one-argument callable that accepts a string and returns
|
||||
``True`` if it contains an interesting warning and ``False``
|
||||
otherwise.
|
||||
"""
|
||||
pattern = r".*\.py[oc]?:\d+:" # (Pending)?DeprecationWarning: .*"
|
||||
if options["package"]:
|
||||
pattern = r".*/{}/".format(
|
||||
re.escape(options["package"]),
|
||||
) + pattern
|
||||
expression = re.compile(pattern)
|
||||
def match(line):
|
||||
return expression.match(line) is not None
|
||||
return match
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def run_command(main):
|
||||
config = Options()
|
||||
@ -63,6 +92,8 @@ def run_command(main):
|
||||
reactor.spawnProcess(pp, exe, [exe] + config["args"], env=None)
|
||||
(signal, rc) = yield pp.d
|
||||
|
||||
match = make_matcher(config)
|
||||
|
||||
# maintain ordering, but ignore duplicates (for some reason, either the
|
||||
# 'warnings' module or twisted.python.deprecate isn't quashing them)
|
||||
already = set()
|
||||
@ -75,12 +106,12 @@ def run_command(main):
|
||||
|
||||
pp.stdout.seek(0)
|
||||
for line in pp.stdout.readlines():
|
||||
if "DeprecationWarning" in line:
|
||||
if match(line):
|
||||
add(line) # includes newline
|
||||
|
||||
pp.stderr.seek(0)
|
||||
for line in pp.stderr.readlines():
|
||||
if "DeprecationWarning" in line:
|
||||
if match(line):
|
||||
add(line)
|
||||
|
||||
if warnings:
|
||||
|
0
newsfragments/3232.minor
Normal file
0
newsfragments/3232.minor
Normal file
4
tox.ini
4
tox.ini
@ -97,7 +97,7 @@ commands =
|
||||
setenv =
|
||||
PYTHONWARNINGS=default::DeprecationWarning
|
||||
commands =
|
||||
python misc/build_helpers/run-deprecations.py --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata}
|
||||
python misc/build_helpers/run-deprecations.py --package allmydata --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata}
|
||||
|
||||
[testenv:upcoming-deprecations]
|
||||
setenv =
|
||||
@ -109,7 +109,7 @@ deps =
|
||||
git+https://github.com/warner/foolscap
|
||||
commands =
|
||||
flogtool --version
|
||||
python misc/build_helpers/run-deprecations.py --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata}
|
||||
python misc/build_helpers/run-deprecations.py --package allmydata --warnings={env:TAHOE_LAFS_WARNINGS_LOG:_trial_temp/deprecation-warnings.log} trial {env:TAHOE_LAFS_TRIAL_ARGS:--rterrors} {posargs:allmydata}
|
||||
|
||||
[testenv:checkmemory]
|
||||
commands =
|
||||
|
Loading…
Reference in New Issue
Block a user