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_())
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_())
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))