[
https://issues.apache.org/jira/browse/BEAM-5745?focusedWorklogId=158918&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-158918
]
ASF GitHub Bot logged work on BEAM-5745:
----------------------------------------
Author: ASF GitHub Bot
Created on: 25/Oct/18 22:24
Start Date: 25/Oct/18 22:24
Worklog Time Spent: 10m
Work Description: swegner closed pull request #6687: [BEAM-5745] Fix
annotation test for py3
URL: https://github.com/apache/beam/pull/6687
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/sdks/python/apache_beam/utils/annotations.py
b/sdks/python/apache_beam/utils/annotations.py
index 4f41a1b1e49..12a6ecb1cb3 100644
--- a/sdks/python/apache_beam/utils/annotations.py
+++ b/sdks/python/apache_beam/utils/annotations.py
@@ -87,12 +87,6 @@ def exp_multiply(arg1, arg2):
from functools import partial
from functools import wraps
-# Produce only the first occurrence of matching warnings regardless of
-# location per line of execution. Since the number of lines of execution
-# depends on the concrete runner, the number of warnings produced will
-# vary depending on the runner.
-warnings.simplefilter("once")
-
def annotate(label, since, current, extra_message, custom_message=None):
"""Decorates an API with a deprecated or experimental annotation.
diff --git a/sdks/python/apache_beam/utils/annotations_test.py
b/sdks/python/apache_beam/utils/annotations_test.py
index f9a16b046cf..1493d365478 100644
--- a/sdks/python/apache_beam/utils/annotations_test.py
+++ b/sdks/python/apache_beam/utils/annotations_test.py
@@ -31,9 +31,12 @@ def test_deprecated_with_since_current_message(self):
@deprecated(since='v.1', current='multiply', extra_message='Do this')
def fnc_test_deprecated_with_since_current_message():
return 'lol'
+ # Deprecation warnings are ignored by default, turn them on
+ # to enable testing.
+ warnings.simplefilter("always", DeprecationWarning)
fnc_test_deprecated_with_since_current_message()
self.check_annotation(
- warning=w, warning_size=1,
+ warning=w,
warning_type=DeprecationWarning,
obj_name='fnc_test_deprecated_with_since_current_message',
annotation_type='deprecated',
@@ -46,8 +49,11 @@ def test_deprecated_with_since_current(self):
@deprecated(since='v.1', current='multiply')
def fnc_test_deprecated_with_since_current():
return 'lol'
+ # Deprecation warnings are ignored by default, turn them on
+ # to enable testing.
+ warnings.simplefilter("once", DeprecationWarning)
fnc_test_deprecated_with_since_current()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=DeprecationWarning,
obj_name='fnc_test_deprecated_with_since_current',
annotation_type='deprecated',
@@ -59,8 +65,11 @@ def test_deprecated_without_current(self):
@deprecated(since='v.1')
def fnc_test_deprecated_without_current():
return 'lol'
+ # Deprecation warnings are ignored by default, turn them on
+ # to enable testing.
+ warnings.simplefilter("once", DeprecationWarning)
fnc_test_deprecated_without_current()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=DeprecationWarning,
obj_name='fnc_test_deprecated_without_current',
annotation_type='deprecated',
@@ -93,7 +102,7 @@ def fnc_test_experimental_with_current_message():
return 'lol'
fnc_test_experimental_with_current_message()
self.check_annotation(
- warning=w, warning_size=1,
+ warning=w,
warning_type=FutureWarning,
obj_name='fnc_test_experimental_with_current_message',
annotation_type='experimental',
@@ -106,7 +115,7 @@ def test_experimental_with_current(self):
def fnc_test_experimental_with_current():
return 'lol'
fnc_test_experimental_with_current()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=FutureWarning,
obj_name='fnc_test_experimental_with_current',
annotation_type='experimental',
@@ -118,78 +127,12 @@ def test_experimental_without_current(self):
def fnc_test_experimental_without_current():
return 'lol'
fnc_test_experimental_without_current()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=FutureWarning,
obj_name='fnc_test_experimental_without_current',
annotation_type='experimental',
label_check_list=[('instead', False)])
- def test_frequency(self):
- """Tests that the filter 'once' is sufficient to print once per
- warning independently of location."""
- with warnings.catch_warnings(record=True) as w:
- @experimental()
- def fnc_test_annotate_frequency():
- return 'lol'
-
- @experimental()
- def fnc2_test_annotate_frequency():
- return 'lol'
- fnc_test_annotate_frequency()
- fnc_test_annotate_frequency()
- fnc2_test_annotate_frequency()
- self.check_annotation(warning=[w[0]], warning_size=1,
- warning_type=FutureWarning,
- obj_name='fnc_test_annotate_frequency',
- annotation_type='experimental',
- label_check_list=[])
- self.check_annotation(warning=[w[1]], warning_size=1,
- warning_type=FutureWarning,
- obj_name='fnc2_test_annotate_frequency',
- annotation_type='experimental',
- label_check_list=[])
-
- def test_frequency_class(self):
- """Tests that the filter 'once' is sufficient to print once per
- warning independently of location."""
- with warnings.catch_warnings(record=True) as w:
- @experimental()
- class Class_test_annotate_frequency(object):
- fooo = 'lol'
-
- def __init__(self):
- pass
-
- def foo(self):
- return 'lol'
-
- @experimental()
- class Class2_test_annotate_frequency(object):
- fooo = 'lol'
-
- def __init__(self):
- pass
-
- def foo(self):
- return 'lol'
-
- foo = Class_test_annotate_frequency()
- foo.foo()
- foo1 = Class_test_annotate_frequency()
- foo1.foo()
- foo2 = Class2_test_annotate_frequency()
- foo2.foo()
- self.check_annotation(warning=[w[0]], warning_size=1,
- warning_type=FutureWarning,
- obj_name='Class_test_annotate_frequency',
- annotation_type='experimental',
- label_check_list=[])
- self.check_annotation(warning=[w[1]], warning_size=1,
- warning_type=FutureWarning,
- obj_name='Class2_test_annotate_frequency',
- annotation_type='experimental',
- label_check_list=[])
-
def test_decapreted_custom_no_replacements(self):
"""Tests if custom message prints an empty string
for each replacement token when only the
@@ -201,8 +144,11 @@ def test_decapreted_custom_no_replacements(self):
@deprecated(since=strSince, custom_message=strCustom)
def fnc_test_experimental_custom_no_replacements():
return 'lol'
+ # Deprecation warnings are ignored by default, turn them on
+ # to enable testing.
+ warnings.simplefilter("always", DeprecationWarning)
fnc_test_experimental_custom_no_replacements()
- self.check_custom_annotation(warning=w, warning_size=1,
+ self.check_custom_annotation(warning=w,
warning_type=DeprecationWarning,
obj_name='fnc_test_experimental_custom_no_\
replacements',
@@ -239,9 +185,12 @@ def
test_deprecated_with_since_current_message_custom(self):
custom_message=strCustom)
def fnc_test_deprecated_with_since_current_message_custom():
return 'lol'
+ # Deprecation warnings are ignored by default, turn them
+ # on to enable testing.
+ warnings.simplefilter("always", DeprecationWarning)
strName = fnc_test_deprecated_with_since_current_message_custom .__name__
fnc_test_deprecated_with_since_current_message_custom()
- self.check_custom_annotation(warning=w, warning_size=1,
+ self.check_custom_annotation(warning=w,
warning_type=DeprecationWarning,
obj_name='fnc_test_deprecated_with_since_\
current_message_custom',
@@ -264,10 +213,14 @@ def __init__(self):
def foo(self):
return 'lol'
+ # Deprecation warnings are ignored by default, turn them
+ # on to enable testing.
+ warnings.simplefilter("always", DeprecationWarning)
+
foo = Class_test_deprecated_with_since_current_message()
strName = Class_test_deprecated_with_since_current_message.__name__
foo.foo()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=DeprecationWarning,
obj_name=strName,
annotation_type='deprecated',
@@ -286,9 +239,14 @@ def test_experimental_with_current_message_custom(self):
custom_message=strCustom)
def fnc_test_experimental_with_current_message_custom():
return 'lol'
+
+ # Deprecation warnings are ignored by default, turn them
+ # on to enable testing.
+ warnings.simplefilter("always", DeprecationWarning)
+
strName = fnc_test_experimental_with_current_message_custom.__name__
fnc_test_experimental_with_current_message_custom()
- self.check_custom_annotation(warning=w, warning_size=1,
+ self.check_custom_annotation(warning=w,
warning_type=FutureWarning,
obj_name='fnc_test_experimental\
_with_current_message_custom',
@@ -313,7 +271,7 @@ def foo(self):
foo = Class_test_experimental_with_current_message()
strName = Class_test_experimental_with_current_message.__name__
foo.foo()
- self.check_annotation(warning=w, warning_size=1,
+ self.check_annotation(warning=w,
warning_type=FutureWarning,
obj_name=strName,
annotation_type='experimental',
@@ -321,9 +279,8 @@ def foo(self):
('Do this', True)])
# helper function
- def check_annotation(self, warning, warning_size, warning_type, obj_name,
+ def check_annotation(self, warning, warning_type, obj_name,
annotation_type, label_check_list):
- self.assertEqual(1, warning_size)
self.assertTrue(issubclass(warning[-1].category, warning_type))
self.assertIn(obj_name + ' is ' + annotation_type,
str(warning[-1].message))
for label in label_check_list:
@@ -333,10 +290,8 @@ def check_annotation(self, warning, warning_size,
warning_type, obj_name,
self.assertNotIn(label[0], str(warning[-1].message))
# Helper function for custom messages
- def check_custom_annotation(self, warning, warning_size, warning_type,
- obj_name,
+ def check_custom_annotation(self, warning, warning_type, obj_name,
annotation_type, intended_message):
- self.assertEqual(1, warning_size)
self.assertTrue(issubclass(warning[-1].category, warning_type))
self.assertIn(intended_message, str(warning[-1].message))
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 158918)
Time Spent: 5h (was: 4h 50m)
> Util test on annotations fails
> -------------------------------
>
> Key: BEAM-5745
> URL: https://issues.apache.org/jira/browse/BEAM-5745
> Project: Beam
> Issue Type: Sub-task
> Components: sdk-py-core
> Reporter: Ruoyun Huang
> Assignee: Ruoyun Huang
> Priority: Minor
> Time Spent: 5h
> Remaining Estimate: 0h
>
> Traceback (most recent call last):
> File
> "/usr/local/google/home/ruoyun/projects/beam/sdks/python/apache_beam/utils/annotations_test.py",
> line 142, in test_frequency
> label_check_list=[])
> File
> "/usr/local/google/home/ruoyun/projects/beam/sdks/python/apache_beam/utils/annotations_test.py",
> line 149, in check_annotation
> self.assertIn(fnc_name + ' is ' + annotation_type,
> str(warning[-1].message))
> AssertionError: 'fnc2_test_annotate_frequency is experimental' not found in
> 'fnc_test_annotate_frequency is experimental.'
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)