KevinGG commented on a change in pull request #11338: [BEAM-7923] Screendiff 
Integration Tests
URL: https://github.com/apache/beam/pull/11338#discussion_r405729704
 
 

 ##########
 File path: 
sdks/python/apache_beam/runners/interactive/testing/integration/notebook_executor.py
 ##########
 @@ -0,0 +1,131 @@
+#
+# 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.
+#
+
+"""Module to execute jupyter notebooks and gather the output into renderable
+HTML files."""
+
+# pytype: skip-file
+
+from __future__ import absolute_import
+
+import os
+import shutil
+
+from apache_beam.runners.interactive.utils import obfuscate
+
+try:
+  import nbformat
+  from nbconvert.preprocessors import ExecutePreprocessor
+  _interactive_integration_ready = True
+except ImportError:
+  _interactive_integration_ready = False
+
+
+class NotebookExecutor(object):
+  """Executor that reads notebooks, executes it and gathers outputs into static
+  HTML pages that can be served."""
+  def __init__(self, path):
+    # type: (str) -> None
+
+    assert _interactive_integration_ready, (
+        '[interactive_test] dependency is not installed.')
+    assert os.path.exists(path), '{} does not exist.'.format(path)
+    self._paths = []
+    if os.path.isdir(path):
+      for root, _, files in os.walk(path):
+        for filename in files:
+          if filename.endswith('.ipynb'):
+            self._paths.append(os.path.join(root, filename))
+    elif path.endswith('.ipynb'):
+      self._paths.append(path)
+    assert len(
+        self._paths) > 0, ('No notebooks to be executed under{}'.format(path))
+    self._dir = os.path.dirname(self._paths[0])
+    self._output_html_dir = os.path.join(self._dir, 'output')
+    self.cleanup()
+    self._output_html_paths = {}
+    self._notebook_path_to_execution_id = {}
+
+  def cleanup(self):
+    """Cleans up the output folder."""
+    _cleanup(self._output_html_dir)
+
+  def execute(self):
 
 Review comment:
   It's tempting to switch to `nbconvert`'s `HTMLExporter`, however, it has 
several drawbacks.
   
   - The HTMLExporter uses Jinja2 templates. Some of the templates such as 
`basic` generates broken JavaScripts while some of the templates such as `full` 
includes too many web elements ;
   - There is no guarantee that template provided by `nbconvert` will be stable 
in future `nbconvert` releases;
   - We have to rule out all code blocks that generates non-stable outputs in 
test notebooks even if they are not related to Interactive Beam and should not 
be included in the screenshot.
   - The more complicated the HTML is, the more flaky the screen diff test will 
be.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to