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_r182790921
 
 

 ##########
 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")
+            nbformat.write(notebook, output_file)
+            output_nb = open(output_file, mode='r')
+            for line in output_nb:
+                if "Warning:" in line:
+                    errors.append("Warning:\n"+line)
+        if len(errors) > 0:
+            print('\n'.join(errors))
+            return False
+        return True
+
+
+
+def test_basic_ndarray():
+   assert _test_tutorial_nb('basic/ndarray')
+
+def test_basic_ndarray_indexing():
+    assert _test_tutorial_nb('basic/ndarray_indexing')
+
+def test_basic_symbol():
+    assert _test_tutorial_nb('basic/symbol')
+
+def test_basic_module():
+    assert _test_tutorial_nb('basic/module')
+
+def test_basic_data():
+    assert _test_tutorial_nb('basic/data')
+
+def test_gluon_customop():
+    assert _test_tutorial_nb('gluon/customop')
+
+def test_gluon_data_augmentation():
+    assert _test_tutorial_nb('gluon/data_augmentation')
+
+def test_gluon_datasets():
+    assert True
+    # Investigating flakiness with docker
+    #assert _test_tutorial_nb('gluon/datasets')
 
 Review comment:
   That is a weird one, might leave out for this iteration and investigate more 
next week. It runs fine outside the container and in the notebook but hangs 
indefinitely when run through nosetest in a container using up all CPUs

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