def init(self, project): """ Create a new instance of Eddy loading the given project from the '@resources' directory. :type project: str """ # COPY TEST PROJECT OVER cpdir('@tests/%s/' % project, '@tests/.tests/%s' % project) # CREATE AN INSTANCE OF EDDY arguments = [ '--nosplash', '--tests', '--open', '@tests/.tests/%s' % project ] parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) options, _ = parser.parse_known_args(args=arguments) with LoggingDisabled(): self.eddy = Eddy(options, arguments) self.eddy.configure(options) self.eddy.start(options) # WAIT FOR THE SESSION TO BE COMPLETELY INITIALIZED QtTest.QTest.qWaitForWindowActive(self.eddy.sessions[0]) # SET SHORTCUTS self.project = self.eddy.sessions[0].project self.session = self.eddy.sessions[0]
def setUp(self): """ Initialize test case environment. """ self.app = Eddy(['--nosplash', '--tests']) self.mainwindow = self.app.mainwindow self.mainwindow.snapToGrid = False self.mainwindow.activateWindow() QTest.qWaitForWindowActive(self.mainwindow)
def qapp(qapp_args, tmpdir_factory): """ Overrides pytest-qt default qapp fixture to provide an instance of Eddy. You can use the ``qapp`` fixture in tests which require a ``QApplication`` to run, but where you don't need full ``qtbot`` functionality. """ app = QtWidgets.QApplication.instance() if app is None: global _qapp_instance os.environ['JAVA_HOME'] = findJavaHome() or '' if sys.platform.startswith('win'): path = os.getenv('PATH', '') path = path.split(os.pathsep) path.insert(0, os.path.join(os.environ['JAVA_HOME'], 'jre', 'bin')) if platform.architecture()[0] == '32bit': path.insert( 0, os.path.join(os.environ['JAVA_HOME'], 'jre', 'bin', 'client')) else: path.insert( 0, os.path.join(os.environ['JAVA_HOME'], 'jre', 'bin', 'server')) os.environ['PATH'] = os.pathsep.join(path) for path in pkg_resources.resource_listdir(eddy.core.jvm.__name__, 'lib'): if File.forPath(path) is File.Jar: addJVMClasspath( pkg_resources.resource_filename(eddy.core.jvm.__name__, os.path.join('lib', path))) # noinspection PyTypeChecker addJVMOptions('-ea', '-Xmx512m') workspace_tmpdir = tmpdir_factory.mktemp('settings') QtCore.QSettings.setPath(QtCore.QSettings.NativeFormat, QtCore.QSettings.UserScope, str(workspace_tmpdir)) settings = QtCore.QSettings(ORGANIZATION, APPNAME) settings.setValue('workspace/home', str(workspace_tmpdir)) settings.setValue('update/check_on_startup', False) argparser = getArgumentParser() options, args = argparser.parse_known_args(qapp_args) _qapp_instance = Eddy(options, args) _qapp_instance.configure(options) yield _qapp_instance else: yield app
def main(): """ Application entry point. """ parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) sys.excepthook = base_except_hook options, _ = parser.parse_known_args(args=sys.argv) global app app = Eddy(options, sys.argv) if app.isRunning(): sys.exit(0) LOGGER.separator(separator='-') LOGGER.frame('%s v%s', APPNAME, VERSION, separator='|') LOGGER.frame(COPYRIGHT, separator='|') LOGGER.separator(separator='-') LOGGER.frame('OS: %s %s', platform.system(), platform.release(), separator='|') LOGGER.frame('Python version: %s', platform.python_version(), separator='|') LOGGER.frame('Qt version: %s', QtCore.QT_VERSION_STR, separator='|') LOGGER.frame('PyQt version: %s', Qt.PYQT_VERSION_STR, separator='|') LOGGER.frame('SIP version: %s', SIP_VERSION_STR, separator='|') LOGGER.separator(separator='-') app.configure(options) app.start(options) sys.exit(app.exec_())
class EddyTestCase(unittest.TestCase): def setUp(self): """ Initialize test case environment. """ self.app = Eddy(['--nosplash', '--tests']) self.mainwindow = self.app.mainwindow self.mainwindow.snapToGrid = False self.mainwindow.activateWindow() QTest.qWaitForWindowActive(self.mainwindow) def tearDown(self): """ Perform operation on test end. """ self.app.quit() ############################################## CUSTOM ASSERTIONS ################################################### def assertDictHasKey(self, key, container, msg=None): """Check for a given key to be in the given dictionary.""" if key not in container.keys(): standardMsg = '{} not found in {}'.format(safe_repr(key), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDictHasValue(self, value, container, msg=None): """Check for a given value to be in the given dictionary.""" if value not in container.value(): standardMsg = '{} not found in {}'.format(safe_repr(value), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) != 0: standardMsg = '{} is not empty: found {} elements'.format(safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertLen(self, count, container, msg=None): """Check for a given container to have the specified length.""" if len(container) != count: standardMsg = 'found {} elements in {}: expecting {}'.format(len(container), safe_repr(container), count) self.fail(self._formatMessage(msg, standardMsg)) def assertNotEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) == 0: standardMsg = '{} unexpectedly empty: found {} elements'.format(safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg))
def main(): """ Application entry point. """ global app sys.excepthook = base_except_hook app = Eddy(sys.argv) if app.isRunning: # If the application is already running in another process send a message to the # process containing all the sys.argv elements joined into a string. This will # cause the other process to activate itself and handle the received message. app.sendMessage(' '.join(sys.argv)) sys.exit(0) sys.exit(app.exec_())
def main(): """ Application entry point. """ parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) sys.excepthook = base_except_hook options, _ = parser.parse_known_args(args=sys.argv) global app app = Eddy(options, sys.argv) if app.isRunning(): sys.exit(0) LOGGER.separator(separator='-') LOGGER.frame('%s v%s', APPNAME, VERSION, separator='|') LOGGER.frame(COPYRIGHT, separator='|') LOGGER.separator(separator='-') LOGGER.frame('Python version: %s', platform.python_version(), separator='|') LOGGER.frame('Qt version: %s', QtCore.QT_VERSION_STR, separator='|') LOGGER.frame('PyQt version: %s', Qt.PYQT_VERSION_STR, separator='|') LOGGER.frame('SIP version: %s', SIP_VERSION_STR, separator='|') LOGGER.separator(separator='-') app.configure(options) app.start(options) sys.exit(app.exec_())
def init(self, project): """ Create a new instance of Eddy loading the given project from the '@resources' directory. :type project: str """ # COPY TEST PROJECT OVER cpdir('@tests/%s/' % project, '@tests/.tests/%s' % project) # CREATE AN INSTANCE OF EDDY arguments = ['--nosplash', '--tests', '--open', '@tests/.tests/%s' % project] parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) options, _ = parser.parse_known_args(args=arguments) self.eddy = Eddy(options, arguments) self.eddy.configure(options) self.eddy.start(options) # WAIT FOR THE SESSION TO BE COMPLETELY INITIALIZED QtTest.QTest.qWaitForWindowActive(self.eddy.sessions[0]) # SET SHORTCUTS self.project = self.eddy.sessions[0].project self.session = self.eddy.sessions[0]
class EddyTestCase(TestCase): """ Base class for all Eddy test cases. """ ############################################# # HOOKS ################################# def setUp(self): """ Initialize test case environment. """ # MAKE SURE TO USE CORRECT SETTINGS settings = QtCore.QSettings(ORGANIZATION, APPNAME) settings.setValue('workspace/home', WORKSPACE) settings.setValue('update/check_on_startup', False) settings.sync() # MAKE SURE THE WORKSPACE DIRECTORY EXISTS mkdir(expandPath(WORKSPACE)) # MAKE SURE TO HAVE A CLEAN TEST ENVIRONMENT rmdir('@tests/.tests/') mkdir('@tests/.tests/') # INITIALIZED VARIABLES self.eddy = None self.project = None self.session = None def tearDown(self): """ Perform operation on test end. """ # SHUTDOWN EDDY self.eddy.quit() # REMOVE TEST DIRECTORY rmdir('@tests/.tests/') ############################################# # INTERFACE ################################# def init(self, project): """ Create a new instance of Eddy loading the given project from the '@resources' directory. :type project: str """ # COPY TEST PROJECT OVER cpdir('@tests/%s/' % project, '@tests/.tests/%s' % project) # CREATE AN INSTANCE OF EDDY arguments = ['--nosplash', '--tests', '--open', '@tests/.tests/%s' % project] parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) options, _ = parser.parse_known_args(args=arguments) self.eddy = Eddy(options, arguments) self.eddy.configure(options) self.eddy.start(options) # WAIT FOR THE SESSION TO BE COMPLETELY INITIALIZED QtTest.QTest.qWaitForWindowActive(self.eddy.sessions[0]) # SET SHORTCUTS self.project = self.eddy.sessions[0].project self.session = self.eddy.sessions[0] ############################################# # CUSTOM ASSERTIONS ################################# def assertAll(self, iterable, msg=None): """Check for all the value in the given iterable to be True""" if not all(iterable): standardMsg = 'found false value in %s' % safe_repr(iterable) self.fail(self._formatMessage(msg, standardMsg)) def assertAllIn(self, iterable, container, msg=None): """Check for all the item in iterable to be in the given container""" for member in iterable: if member not in container: if member not in container: standardMsg = '%s not found in %s' % (safe_repr(member), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertAny(self, iterable, msg=None): """Check for at least a True value in the given iterable""" if not any(iterable): standardMsg = 'true value not found in %s' % safe_repr(iterable) self.fail(self._formatMessage(msg, standardMsg)) def assertAnyIn(self, iterable, container, msg=None): """Check for at least a one of the item in iterable to be in the given container""" for member in iterable: if member in container: break else: standardMsg = 'no item of %s found in %s' % (safe_repr(iterable), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDictHasKey(self, key, container, msg=None): """Check for a given key to be in the given dictionary.""" if key not in container.keys(): standardMsg = '%s not found in %s' % (safe_repr(key), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDictHasValue(self, value, container, msg=None): """Check for a given value to be in the given dictionary.""" if value not in container.value(): standardMsg = '%s not found in %s' % (safe_repr(value), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) != 0: standardMsg = '%s is not empty: found %s elements' % (safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDirectoryExists(self, dirpath, msg=None): """Assert for the given path to represent a file""" if not isdir(dirpath): standardMsg = '%s is not a directory' % safe_repr(expandPath(dirpath)) self.fail(self._formatMessage(msg, standardMsg)) def assertFileExists(self, filepath, msg=None): """Assert for the given path to represent a file""" if not fexists(filepath): standardMsg = '%s is not a file' % safe_repr(expandPath(filepath)) self.fail(self._formatMessage(msg, standardMsg)) def assertLen(self, count, container, msg=None): """Check for a given container to have the specified length.""" if len(container) != count: standardMsg = 'found %s elements in %s: expecting %s' % (len(container), safe_repr(container), count) self.fail(self._formatMessage(msg, standardMsg)) def assertNotEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) == 0: standardMsg = '%s unexpectedly empty: found %s elements' % (safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg))
class EddyTestCase(TestCase): """ Base class for all Eddy test cases. """ ############################################# # HOOKS ################################# def setUp(self): """ Initialize test case environment. """ # ACQUIRE LOCK AND FLUSH STREAMS testcase_lock.acquire() sys.stderr.flush() sys.stdout.flush() # MAKE SURE TO USE CORRECT SETTINGS settings = QtCore.QSettings(ORGANIZATION, APPNAME) settings.setValue('workspace/home', WORKSPACE) settings.setValue('update/check_on_startup', False) settings.sync() # MAKE SURE THE WORKSPACE DIRECTORY EXISTS mkdir(expandPath(WORKSPACE)) # MAKE SURE TO HAVE A CLEAN TEST ENVIRONMENT rmdir('@tests/.tests/') mkdir('@tests/.tests/') # INITIALIZED VARIABLES self.eddy = None self.project = None self.session = None def tearDown(self): """ Perform operation on test end. """ # SHUTDOWN EDDY self.eddy.quit() self.eddy.closeAllWindows() # REMOVE TEST DIRECTORY rmdir('@tests/.tests/') # RELEASE LOCK AND FLUSH STREAMS sys.stderr.flush() sys.stdout.flush() testcase_lock.release() ############################################# # INTERFACE ################################# def init(self, project): """ Create a new instance of Eddy loading the given project from the '@resources' directory. :type project: str """ # COPY TEST PROJECT OVER cpdir('@tests/%s/' % project, '@tests/.tests/%s' % project) # CREATE AN INSTANCE OF EDDY arguments = [ '--nosplash', '--tests', '--open', '@tests/.tests/%s' % project ] parser = ArgumentParser() parser.add_argument('--nosplash', dest='nosplash', action='store_true') parser.add_argument('--tests', dest='tests', action='store_true') parser.add_argument('--open', dest='open', default=None) options, _ = parser.parse_known_args(args=arguments) with LoggingDisabled(): self.eddy = Eddy(options, arguments) self.eddy.configure(options) self.eddy.start(options) # WAIT FOR THE SESSION TO BE COMPLETELY INITIALIZED QtTest.QTest.qWaitForWindowActive(self.eddy.sessions[0]) # SET SHORTCUTS self.project = self.eddy.sessions[0].project self.session = self.eddy.sessions[0] ############################################# # CUSTOM ASSERTIONS ################################# def assertAll(self, iterable, msg=None): """Check for all the value in the given iterable to be True""" if not all(iterable): standardMsg = 'found false value in %s' % safe_repr(iterable) self.fail(self._formatMessage(msg, standardMsg)) def assertAllIn(self, iterable, container, msg=None): """Check for all the item in iterable to be in the given container""" for member in iterable: if member not in container: if member not in container: standardMsg = '%s not found in %s' % (safe_repr(member), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertAny(self, iterable, msg=None): """Check for at least a True value in the given iterable""" if not any(iterable): standardMsg = 'true value not found in %s' % safe_repr(iterable) self.fail(self._formatMessage(msg, standardMsg)) def assertAnyIn(self, iterable, container, msg=None): """Check for at least a one of the item in iterable to be in the given container""" for member in iterable: if member in container: break else: standardMsg = 'no item of %s found in %s' % (safe_repr(iterable), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDictHasKey(self, key, container, msg=None): """Check for a given key to be in the given dictionary.""" if key not in container.keys(): standardMsg = '%s not found in %s' % (safe_repr(key), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDictHasValue(self, value, container, msg=None): """Check for a given value to be in the given dictionary.""" if value not in container.value(): standardMsg = '%s not found in %s' % (safe_repr(value), safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) != 0: standardMsg = '%s is not empty: found %s elements' % ( safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg)) def assertDirectoryExists(self, dirpath, msg=None): """Assert for the given path to represent a file""" if not isdir(dirpath): standardMsg = '%s is not a directory' % safe_repr( expandPath(dirpath)) self.fail(self._formatMessage(msg, standardMsg)) def assertFileExists(self, filepath, msg=None): """Assert for the given path to represent a file""" if not fexists(filepath): standardMsg = '%s is not a file' % safe_repr(expandPath(filepath)) self.fail(self._formatMessage(msg, standardMsg)) def assertLen(self, count, container, msg=None): """Check for a given container to have the specified length.""" if len(container) != count: standardMsg = 'found %s elements in %s: expecting %s' % ( len(container), safe_repr(container), count) self.fail(self._formatMessage(msg, standardMsg)) def assertNotEmpty(self, container, msg=None): """Assert for a given container to be empty.""" if len(container) == 0: standardMsg = '%s unexpectedly empty: found %s elements' % ( safe_repr(container), len(container)) self.fail(self._formatMessage(msg, standardMsg))