@@ -0,0 +1,1419 @@
+%0A# coding=utf-8%0A%22%22%22Fake QGIS App provided by QGIS Core.%22%22%22%0A%0Aimport mock%0A%0Afrom qgis.testing import start_app%0Afrom qgis.gui import QgisInterface, QgsMapCanvas%0Afrom qgis.PyQt.QtWidgets import QMainWindow%0Afrom qgis.PyQt.QtCore import QSize%0A%0A%0Adef qgis_app():%0A    %22%22%22Start a QGIS application and get the iface.%0A%0A    Mostly inspired by%0A    https://github.com/qgis/QGIS/blob/release-2_18/python/testing/mocked.py%0A%0A    The application is returned as first argument. The QgisInterface is%0A    returned as second argument.%0A%0A    The parent can be accessed by iface.mainWindow()%0A    The canvas can be access by iface.mapCanvas()%0A%0A    You can further control its behavior%0A    by using the mock infrastructure.%0A    Refer to https://docs.python.org/3/library/unittest.mock.html%0A    for more details.%0A%0A    :return: The QGIS interface.%0A    :rtype: QgisInterface%0A    %22%22%22%0A    from qgis.utils import iface%0A    if iface:%0A        # We are already in QGIS.%0A        # I don't know if I can get the current QApplication.%0A        # But I guess we shouldn't use it too much.%0A        return None, iface%0A%0A    # We are not in QGIS, we need to start an app.%0A    application = start_app()%0A%0A    my_iface = mock.Mock(spec=QgisInterface)%0A    my_iface.mainWindow.return_value = QMainWindow()%0A%0A    canvas = QgsMapCanvas(my_iface.mainWindow())%0A    canvas.resize(QSize(400, 400))%0A%0A    my_iface.mapCanvas.return_value = canvas%0A%0A    return application, my_iface%0A

Add qgis_app.py