You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by al...@apache.org on 2020/10/06 21:18:14 UTC

[beam] branch master updated: [BEAM-11025] Make PCollection Visualization tests robust

This is an automated email from the ASF dual-hosted git repository.

altay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 826dd72  [BEAM-11025] Make PCollection Visualization tests robust
     new eefb76f  Merge pull request #13020 from KevinGG/BEAM-11025
826dd72 is described below

commit 826dd726846a47970802b6bfc07fdb11491fe81f
Author: Ning Kang <ni...@google.com>
AuthorDate: Tue Oct 6 11:47:41 2020 -0700

    [BEAM-11025] Make PCollection Visualization tests robust
    
    1. Added 2 patches to affected tests to make sure get_ipython does not
       return None and is_in_notebook returns True.
    2. Added 1 new test to test the failure path when is_in_notebook returns
       False.
    3. There could be some race condition on Jenkins that tests might be
       running in parallel on the same machine sharing the same global variable.
       In that case, a test's SetUp cannot guarantee the global variable is
       not changed during test execution. We use patch to ensure that
       we are not using the real global variable.
---
 .../display/pcoll_visualization_test.py            | 34 +++++++++++++++++++---
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization_test.py b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization_test.py
index eba726a..5d01b88 100644
--- a/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization_test.py
+++ b/sdks/python/apache_beam/runners/interactive/display/pcoll_visualization_test.py
@@ -32,6 +32,7 @@ from apache_beam.runners.interactive import interactive_environment as ie
 from apache_beam.runners.interactive import interactive_runner as ir
 from apache_beam.runners.interactive.display import pcoll_visualization as pv
 from apache_beam.runners.interactive.recording_manager import RecordingManager
+from apache_beam.runners.interactive.testing.mock_ipython import mock_get_ipython
 from apache_beam.transforms.window import GlobalWindow
 from apache_beam.transforms.window import IntervalWindow
 from apache_beam.utils.windowed_value import PaneInfo
@@ -40,9 +41,9 @@ from apache_beam.utils.windowed_value import PaneInfoTiming
 # TODO(BEAM-8288): clean up the work-around of nose tests using Python2 without
 # unittest.mock module.
 try:
-  from unittest.mock import patch, ANY
+  from unittest.mock import patch, ANY, PropertyMock
 except ImportError:
-  from mock import patch, ANY  # type: ignore[misc]
+  from mock import patch, ANY, PropertyMock  # type: ignore[misc]
 
 try:
   import timeloop
@@ -84,15 +85,40 @@ class PCollectionVisualizationTest(unittest.TestCase):
     self.assertNotEqual(pv_1._overview_display_id, pv_2._overview_display_id)
     self.assertNotEqual(pv_1._df_display_id, pv_2._df_display_id)
 
-  def test_one_shot_visualization_not_return_handle(self):
+  @patch('IPython.get_ipython', new_callable=mock_get_ipython)
+  @patch(
+      'apache_beam.runners.interactive.interactive_environment'
+      '.InteractiveEnvironment.is_in_notebook',
+      new_callable=PropertyMock)
+  def test_one_shot_visualization_not_return_handle(
+      self, mocked_is_in_notebook, unused):
+    mocked_is_in_notebook.return_value = True
     self.assertIsNone(pv.visualize(self._stream, display_facets=True))
 
-  def test_dynamic_plotting_return_handle(self):
+  @patch('IPython.get_ipython', new_callable=mock_get_ipython)
+  @patch(
+      'apache_beam.runners.interactive.interactive_environment'
+      '.InteractiveEnvironment.is_in_notebook',
+      new_callable=PropertyMock)
+  def test_dynamic_plotting_return_handle(self, mocked_is_in_notebook, unused):
+    mocked_is_in_notebook.return_value = True
     h = pv.visualize(
         self._stream, dynamic_plotting_interval=1, display_facets=True)
     self.assertIsInstance(h, timeloop.Timeloop)
     h.stop()
 
+  @patch('IPython.get_ipython', new_callable=mock_get_ipython)
+  @patch(
+      'apache_beam.runners.interactive.interactive_environment'
+      '.InteractiveEnvironment.is_in_notebook',
+      new_callable=PropertyMock)
+  def test_no_dynamic_plotting_when_not_in_notebook(
+      self, mocked_is_in_notebook, unused):
+    mocked_is_in_notebook.return_value = False
+    h = pv.visualize(
+        self._stream, dynamic_plotting_interval=1, display_facets=True)
+    self.assertIsNone(h)
+
   @patch(
       'apache_beam.runners.interactive.display.pcoll_visualization'
       '.PCollectionVisualization._display_dive')