ThomasDelteil commented on a change in pull request #10608: [MXNET-292] Add 
tutorial tests to the CI
URL: https://github.com/apache/incubator-mxnet/pull/10608#discussion_r182784791
 
 

 ##########
 File path: tests/tutorials/test_tutorials.py
 ##########
 @@ -0,0 +1,187 @@
+# 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.
+
+#pylint: disable=no-member, too-many-locals, too-many-branches, no-self-use, 
broad-except, lost-exception, too-many-nested-blocks, too-few-public-methods, 
invalid-name
+"""
+    This script converts all python tutorials into python script
+    and tests whether there is any warning or error.
+    After running python script, it will also convert markdown files
+    to notebooks to make sure notebook execution has no error.
+"""
+import os
+import warnings
+import imp
+import shutil
+import time
+import argparse
+import traceback
+import nbformat
+from nbconvert.preprocessors import ExecutePreprocessor
+import sys
+
+
+TIME_OUT = 1800
+temp_dir = 'tmp_notebook'
+
+def _test_tutorial_nb(tutorial):
+    """Run tutorial jupyter notebook to catch any execution error.
+
+    Parameters
+    ----------
+    tutorial : str
+        tutorial name in folder/tutorial format
+    """
+
+    tutorial_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'docs', 
'_build', 'html', 'tutorials')
+    tutorial_path = os.path.join(*([tutorial_dir] + tutorial.split('/')))
+
+    kernel = os.getenv('MXNET_TUTORIAL_TEST_KERNEL', None)
+    no_cache = os.getenv('MXNET_TUTORIAL_TEST_NO_CACHE', False)
+
+    working_dir = os.path.join(*([temp_dir] + tutorial.split('/')))
+
+    if no_cache:
+        print("Cleaning and setting up temp directory 
'{}'".format(working_dir))
+        shutil.rmtree(temp_dir, ignore_errors=True)
+
+    errors = []
+    notebook = None
+    if not os.path.isdir(working_dir):
+        os.makedirs(working_dir)
+    try:
+        notebook = nbformat.read(tutorial_path + '.ipynb', as_version=4)
+        if kernel is not None:
+            eprocessor = ExecutePreprocessor(timeout=TIME_OUT, 
kernel_name=kernel)
 
 Review comment:
   that is the timeout for the execution of a single notebook. Good point, I am 
not sure whether that would fail the test or just move on.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to