"""Checks that tutorial notebooks behave as expected.
"""

import unittest
import os
import shutil
import tempfile

from flaky import flaky

from notebook_tester import NotebookTestRunner


class TutorialNotebookTests(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.tmp_dir = tempfile.mkdtemp()
        git_url = 'https://github.com/tensorflow/swift.git'
        os.system('git clone %s %s -b jupyter-test-branch' % (git_url, cls.tmp_dir))

    @classmethod
    def tearDownClass(cls):
        shutil.rmtree(cls.tmp_dir)

    @flaky(max_runs=5, min_passes=1)
    @unittest.skip  # TODO(TF-747): Reenable.
    def test_iris(self):
        notebook = os.path.join(self.tmp_dir, 'docs', 'site', 'tutorials',
                                'model_training_walkthrough.ipynb')
        runner = NotebookTestRunner(notebook, verbose=False)
        runner.run()
        self.assertEqual([], runner.unexpected_errors)
        all_stdout = '\n\n'.join(runner.stdout)
        self.assertIn('Epoch 100:', all_stdout)
        self.assertIn('Example 2 prediction:', all_stdout)

@@ -1,8 +1,37 @@
+# TODO(TF-747): Reenable.%0A%0A# 
 %22%22%22Check
@@ -80,13 +80,19 @@
 ed.%0A
+# 
 %22%22%22%0A
-%0A
+# %0A# 
 impo
@@ -103,16 +103,18 @@
 nittest%0A
+# 
 import o
@@ -115,16 +115,18 @@
 port os%0A
+# 
 import s
@@ -131,16 +131,18 @@
  shutil%0A
+# 
 import t
@@ -149,17 +149,21 @@
 empfile%0A
-%0A
+# %0A# 
 from fla
@@ -178,17 +178,21 @@
 t flaky%0A
-%0A
+# %0A# 
 from not
@@ -230,18 +230,24 @@
 tRunner%0A
-%0A%0A
+# %0A# %0A# 
 class Tu
@@ -286,16 +286,18 @@
 tCase):%0A
+# 
     @cla
@@ -297,32 +297,34 @@
    @classmethod%0A
+# 
     def setUpCla
@@ -324,32 +324,34 @@
 etUpClass(cls):%0A
+# 
         cls.tmp_
@@ -375,16 +375,18 @@
 dtemp()%0A
+# 
         
@@ -437,16 +437,18 @@
 ft.git'%0A
+# 
         
@@ -524,17 +524,21 @@
 p_dir))%0A
-%0A
+# %0A# 
     @cla
@@ -546,16 +546,18 @@
 smethod%0A
+# 
     def 
@@ -576,16 +576,18 @@
 s(cls):%0A
+# 
         
@@ -613,17 +613,21 @@
 mp_dir)%0A
-%0A
+# %0A# 
     @fla
@@ -659,58 +659,14 @@
 =1)%0A
+#
   
-  @unittest.skip  # TODO(TF-747): Reenable.%0A
    
- 
 def 
@@ -682,16 +682,18 @@
 (self):%0A
+# 
         
@@ -759,16 +759,18 @@
 rials',%0A
+# 
         
@@ -829,16 +829,18 @@
 ipynb')%0A
+# 
         
@@ -892,16 +892,18 @@
 =False)%0A
+# 
         
@@ -915,16 +915,18 @@
 r.run()%0A
+# 
         
@@ -972,16 +972,18 @@
 errors)%0A
+# 
         
@@ -1014,32 +1014,34 @@
 (runner.stdout)%0A
+# 
         self.ass
@@ -1072,16 +1072,18 @@
 stdout)%0A
+# 
         

disable cloning repo in skipped test