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_r182786851
 
 

 ##########
 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)
+        else:
+            eprocessor = ExecutePreprocessor(timeout=TIME_OUT)
+        nb, stuff = eprocessor.preprocess(notebook, {'metadata': {'path': 
working_dir}})
+        print(stuff)
+    except Exception as err:
+        err_msg = str(err)
+        errors.append(err_msg)
+    finally:
+        if notebook is not None:
+            output_file = os.path.join(working_dir, "output.txt")
 
 Review comment:
   The filepath is unique per tutorial, it actually supports parallelization 
pretty well.
   Parallelization with nose test is much simpler than we discussed last time, 
just add:
   `--processes=8 --process-timeout=1800 (--process-restartworker)`
   It does work with this test, reducing the time necessary to run them by 60% 
with 8 workers. However, I am not sure how mature this nosetest plugin is. I 
think the fact these tests spawn an extra process confuses nosetest and I have 
witnessed some nostests workers crashing that leave python processes orphans, 
using up GPU memory, and on top of that that particular test case was 
considered successful.

----------------------------------------------------------------
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