File tree Expand file tree Collapse file tree 2 files changed +71
-0
lines changed
Expand file tree Collapse file tree 2 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ # Copyright 2017 Google Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import warnings
16+
17+ import pkg_resources
18+
19+
20+ def complain (distribution_name ):
21+ """Issue a warning if `distribution_name` is installed.
22+
23+ In a future release, this method will be updated to raise ImportError
24+ rather than just send a warning.
25+
26+ Args:
27+ distribution_name (str): The name of the obselete distribution.
28+ """
29+ try :
30+ pkg_resources .get_distribution (distribution_name )
31+ warnings .warn (
32+ 'The {pkg} distribution is now obselete. '
33+ 'Please `pip uninstall {pkg}`. '
34+ 'In the future, this warning will become an ImportError.' .format (
35+ pkg = distribution_name ,
36+ ),
37+ DeprecationWarning ,
38+ )
39+ except pkg_resources .DistributionNotFound :
40+ pass
Original file line number Diff line number Diff line change 1+ # Copyright 2017 Google Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ import warnings
16+
17+ import mock
18+
19+ from google .cloud import obselete
20+
21+
22+ def test_complain_noop ():
23+ with mock .patch .object (warnings , 'warn' , autospec = True ) as warn :
24+ obselete .complain ('bogus_package' )
25+ assert warn .call_count == 0
26+
27+
28+ def test_complain ():
29+ with mock .patch .object (warnings , 'warn' , autospec = True ) as warn :
30+ obselete .complain ('google-cloud-core' )
31+ warn .assert_called_once_with (mock .ANY , DeprecationWarning )
You can’t perform that action at this time.
0 commit comments