deepyaman commented on code in PR #29061: URL: https://github.com/apache/flink/pull/29061#discussion_r3928266452
########## flink-python/pyflink/util/tests/test_api_stability_decorators.py: ########## @@ -0,0 +1,443 @@ +################################################################################ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +################################################################################ +import abc +import enum +import inspect +import os +import subprocess +import sys +import textwrap +import unittest +import warnings + +from pyflink.util.api_stability_decorators import ( + Deprecated, + Experimental, + Internal, + Public, + PublicEvolving, +) + + +class DeprecatedTests(unittest.TestCase): + """ + Tests for the :class:`Deprecated` decorator, which must warn when a deprecated API is + used, and not when it is defined. + + Blocks that must not warn turn warnings into errors, so that one fails where it is + raised rather than in a comparison afterwards. + """ + + def test_decoration_does_not_warn(self): + with warnings.catch_warnings(): + warnings.simplefilter("error") + + @Deprecated(since="1.0.0", detail="Use :func:`new_func` instead.") + def func(): + pass + + @Deprecated(since="1.0.0") + class Cls: + def __init__(self): + pass + + def test_importing_pyflink_table_does_not_warn(self): + # A fresh interpreter is the only way to observe an import: pyflink.table is + # already in sys.modules here, so importing it again is a no-op. Only this + # decorator's own warnings are inspected, so third-party noise cannot fail it. Review Comment: How about removing it from sys.modules (I've done stuff in the past where I've mocked a module being uninstalled or unloaded, or maybe you actually unload it, or perhaps even just trigger reloading the module to look for the errors?)? Would that be a cleaner, or at least more idiomatic, approach? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
