예제 #1
0
 def test_5(self, _reload):
     """Check that reload is called twice."""
     with ImportFail(['re'], ['one', 'two']):
         pass
     _reload.assert_has_calls(
         [call('one'), call('two'),
          call('one'), call('two')])
예제 #2
0
 def test_sync22(self):
     """Prevent TRE from being imported. Make sure there are no exceptions.
     """
     with ImportFail(['approx_match'], [enki.plugins.preview.preview_sync]):
         self.assertIsNone(enki.plugins.preview.preview_sync.findApproxTextInTarget)
     # Now, make sure that TRE imports correctly.
     self.assertTrue(enki.plugins.preview.preview_sync.findApproxTextInTarget)
예제 #3
0
 def test_2(self):
     """ Make sure ImportFail causes an exception for multiple fail_names.
     """
     with self.assertRaises(ImportError):
         with ImportFail(['os', 're']):
             import re
     # Make sure the same name now works
     import re
예제 #4
0
 def test_1(self):
     """ Make sure ImportFail causes an exception for a fail_name.
     """
     with self.assertRaises(ImportError):
         with ImportFail(['re']):
             import re
     # Make sure the same name now works
     import re
예제 #5
0
    def test_xsync22(self):
        """Prevent TRE from being imported. Make sure there are no exceptions.

        Note: Running this before test_click1/2/3 causes test failure -- the patches in those tests doesn't work after ImportFail in this test reloads the preview_sync module. So, name it test_xsync22 so that it will run after these tests.
        """
        with ImportFail(['approx_match'], [enki.plugins.preview.preview_sync]):
            self.assertIsNone(
                enki.plugins.preview.preview_sync.findApproxTextInTarget)
        # Now, make sure that TRE imports correctly.
        self.assertTrue(
            enki.plugins.preview.preview_sync.findApproxTextInTarget)
예제 #6
0
    def test_previewCheck22(self):
        """ Assume codechat is not installed, render a .rst file using
        restructuredText and then render using sphinx.
        """
        with ImportFail(['CodeChat']):
            self.testText = 'Underlying :download:`source code <file.rst>`.'
            self._doBasicTest('rst')
            self.assertTrue('Unknown interpreted text role "download".' in self._logText())
            self.assertTrue('red' in self._widget().prgStatus.styleSheet())

            self._doBasicSphinxConfig()
            core.uiSettingsManager().dialogAccepted.emit()
            self._assertHtmlReady(lambda: None, timeout=10000,
                                  numEmittedExpected=1)
            self.assertTrue("document isn't included in any toctree" in self._logText())
            self.assertTrue('#FF9955' in self._widget().prgStatus.styleSheet())
예제 #7
0
    def test_6(self, _reload):
        """Check that reload is called in the correct context."""
        class ImportTester(object):
            def __init__(self):
                # Save a list of success/failure of an import.
                self.import_success = []

            def try_import(self, *args, **kwargs):
                try:
                    import re
                    self.import_success += [True]
                except ImportError:
                    self.import_success += [False]

        it = ImportTester()
        _reload.side_effect = it.try_import
        with ImportFail(['re'], ['one']):
            pass
        self.assertEquals(it.import_success, [False, True])
예제 #8
0
    def test_settingUiCheck3(self):
        """ The Enable CodeChat checkbox should only be enabled if CodeChat can
            be imported; otherwise, it should be disabled."""
        # Trick Python into thinking that the CodeChat module doesn't exist.
        # Verify that the CodeChat checkbox is disabled, and the 'not installed'
        # notification is visible.
        with ImportFail(['CodeChat'], [enki.plugins.preview]):
            us, sw = self.setupSettingsWidget(CodeChatSettingsWidget)
            self.assertFalse(sw.cbCodeChat.isEnabled())
            self.assertTrue(sw.labelCodeChatNotInstalled.isVisible())
            self.assertTrue(sw.labelCodeChatNotInstalled.isEnabled())
            self.assertTrue(sw.labelCodeChatIntro.isEnabled())
            us.close()

        # Now, prove that the reload worked: CodeChat should now be enabled, but
        # remain unchecked just like the first time enki starts. 'not installed'
        # notification should be invisible.
        us, sw = self.setupSettingsWidget(CodeChatSettingsWidget)
        self.assertTrue(sw.cbCodeChat.isEnabled())
        self.assertFalse(sw.labelCodeChatNotInstalled.isVisible())
        self.assertTrue(sw.labelCodeChatIntro.isEnabled())
        us.close()
예제 #9
0
 def test_4(self, _reload):
     """Check that reload isn't called if no modules are given."""
     with ImportFail(['re']):
         pass
     self.assertFalse(_reload.called)
예제 #10
0
 def test_3(self):
     """Make sure import of other modules works.
     """
     with ImportFail(['re']):
         import os