Esempio n. 1
0
    def test_usage(self):
        # no arguments
        with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
            status = ipy2to3.main([executable])
            out = str(mock_stdout.getvalue()).replace('\r', '')
        self.assertEqual(status, 1)
        self.assertTrue('Usage' in out)

        # one argument
        with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
            status = ipy2to3.main([executable])
            out = str(mock_stdout.getvalue()).replace('\r', '')
        self.assertEqual(status, 1)
        self.assertTrue('Usage' in out)
Esempio n. 2
0
    def test_main(self, mock_convert_ipy2to3: mock.Mock):
        mock_convert_ipy2to3.return_value = ''
        open_ = mock.mock_open(read_data=test_stubs.str_notebook_v3)

        with mock.patch('io.open', open_):
            with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
                status = ipy2to3.main([executable, "testing/test-format-v3.ipynb", "testing/test-format-v3-result.ipynb"])
                out = str(mock_stdout.getvalue()).replace('\r', '')

        self.assertEqual(status, 0)
        self.assertEqual(out, '')
        self.assertTrue(mock_convert_ipy2to3.called)
        self.assertEqual(open_.call_count, 2)

        # should show an error
        mock_convert_ipy2to3.return_value = 'error converting cell, cell left unconverted: \n\nrun github_datapull.py;'
        open_ = mock.mock_open(read_data=test_stubs.str_notebook_v3)
        with mock.patch('io.open', open_):
            with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
                status = ipy2to3.main([executable, "testing/test-format-v3.ipynb", "testing/test-format-v3-result.ipynb"])
                out = str(mock_stdout.getvalue()).replace('\r', '')

        self.assertEqual(status, 0)
        self.assertEqual(out, 'error converting cell, cell left unconverted: \n\nrun github_datapull.py;\n')
        self.assertTrue(mock_convert_ipy2to3.called)
        self.assertEqual(open_.call_count, 2)

        # should not save
        mock_convert_ipy2to3.return_value = 'notebook-format-error: error'
        open_ = mock.mock_open(read_data=test_stubs.str_notebook_v3)
        with mock.patch('io.open', open_):
            with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
                status = ipy2to3.main([executable, "testing/test-format-v3.ipynb", "testing/test-format-v3-result.ipynb"])
                out = str(mock_stdout.getvalue()).replace('\r', '')

        self.assertEqual(status, 1)
        self.assertEqual(out, 'notebook-format-error: error\n')
        self.assertTrue(mock_convert_ipy2to3.called)
        self.assertEqual(open_.call_count, 1)
Esempio n. 3
0
 def test_format_v4(self):
     with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
         status = ipy2to3.main([executable, "testing/test-format-v4.ipynb", "testing/test-format-v4-result.ipynb"])
         out = str(mock_stdout.getvalue()).replace('\r', '')
     self.assertEqual(status, 0)
     self.assertEqual(out, '')
Esempio n. 4
0
 def test_format_v3(self):
     with unittest.mock.patch('sys.stdout', new=io.StringIO()) as mock_stdout:
         status = ipy2to3.main([executable, "testing/test-format-v3.ipynb", "testing/test-format-v3-result.ipynb"])
         out = str(mock_stdout.getvalue()).replace('\r', '')
     self.assertEqual(status, 0)
     self.assertEqual(out, 'error converting cell, cell left unconverted: \nrun github_datapull.py;\n')