Exemplo n.º 1
0
    def test_has_attribute(self):
        mock = Object()
        mock.required_attribute = "TEST3"

        features.Provide("TEST3", mock)

        self.assertEqual(self.attr.required_attribute, "TEST3")
Exemplo n.º 2
0
    def test_provide(self):
        mock = Object()

        features.Provide("TEST1", mock)
        self.feature.test()

        mock.test.assert_called_once()
Exemplo n.º 3
0
    def test_has_method(self):
        mock = Object()
        mock.required_method = Mock()

        features.Provide("TEST2", mock)
        self.method.required_method()

        mock.required_method.assert_called_once()
Exemplo n.º 4
0
    def setUp(self):
        self.app = QApplication(sys.argv)
        self.content_ctrl_mock = ContentCtrlMock()
        self.connection_ctrl_mock = ConnectionCtrlMock()
        features.allowReplace = True
        features.Provide(ContentController.name, self.content_ctrl_mock)
        features.Provide(ViewerConnectionController.name,
                         self.connection_ctrl_mock)

        class TestViewerTool(ViewerToolController):
            connect = Mock()
            disconnect = Mock()
            setupContent = Mock()

            @property
            def item_config(self) -> ItemConfig:
                return ItemConfig()

        self.tool = TestViewerTool()
Exemplo n.º 5
0
class TestIoC(unittest.TestCase):
    feature: Object = RequiredFeature("TEST1")
    method: Object = RequiredFeature("TEST2", HasMethods("required_method"))
    attr: Object = RequiredFeature("TEST3",
                                   HasAttributes("required_attribute"))

    features.Provide("1", "1")
    features.Provide("2", "2")
    features.Provide("3", "3")
    features: List[str] = MatchingFeatures(IsInstanceOf(str))

    def test_provide(self):
        mock = Object()

        features.Provide("TEST1", mock)
        self.feature.test()

        mock.test.assert_called_once()

    def test_has_method(self):
        mock = Object()
        mock.required_method = Mock()

        features.Provide("TEST2", mock)
        self.method.required_method()

        mock.required_method.assert_called_once()

    def test_has_attribute(self):
        mock = Object()
        mock.required_attribute = "TEST3"

        features.Provide("TEST3", mock)

        self.assertEqual(self.attr.required_attribute, "TEST3")

    def test_matching(self):
        self.assertEqual(["1", "2", "3"], self.features)
Exemplo n.º 6
0
    def setUp(self):
        self.app = QApplication(sys.argv)
        self.content_ctrl_mock = ContentCtrlMock()
        features.allowReplace = True
        features.Provide(ContentController.name, self.content_ctrl_mock)

        class TestDataAction(DataActionController):
            modifyData = Mock()

            @property
            def item_config(self) -> ItemConfig:
                return ItemConfig()

        self.action = TestDataAction()
Exemplo n.º 7
0
def main():
    # prepare application
    app = QtWidgets.QApplication(sys.argv)
    QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates))

    prepareImports()
    registerControllers()
    registerViewers()
    loadResources()

    # start application
    app_ctrl = AppController()
    features.Provide(AppController.__name__, app_ctrl)
    app_ctrl.showMaximized()
    sys.exit(app.exec_())
Exemplo n.º 8
0
    def setUp(self):
        self.app = QApplication(sys.argv)
        self.content_ctrl_mock = ContentCtrlMock()
        features.allowReplace = True
        features.Provide(ContentController.name, self.content_ctrl_mock)

        class TestToolbar(ToolbarController):
            setup = Mock()
            onClose = Mock()

            @property
            def item_config(self) -> ItemConfig:
                return ItemConfig()

        self.toolbar = TestToolbar()
Exemplo n.º 9
0
    def setUp(self):
        self.app = QApplication(sys.argv)
        self.content_ctrl_mock = ContentCtrlMock()
        features.allowReplace = True
        features.Provide(ContentController.name, self.content_ctrl_mock)

        class TestDataTool(DataToolController):
            setupContent = Mock()
            onDataChanged = Mock()
            modifyData = Mock()

            @property
            def item_config(self) -> ItemConfig:
                return ItemConfig().addSupportedViewer(
                    ViewerType.MPL).addSupportedData(DataType.MAP)

        self.tool = TestDataTool()
Exemplo n.º 10
0
def main():
    # check sunpy download directory exists
    os.makedirs(sunpy.config.get("downloads", "download_dir"), exist_ok=True)
    # prepare application
    app = QtWidgets.QApplication(sys.argv)
    QLocale.setDefault(QLocale(QLocale.English, QLocale.UnitedStates))

    prepareImports()
    registerControllers()
    registerViewers()
    loadResources()

    # start application
    app_ctrl = AppController()
    features.Provide(AppController.name, app_ctrl)
    app_ctrl.showMaximized()
    sys.exit(app.exec_())
Exemplo n.º 11
0
def registerViewers():
    ctrls = ViewerController.__subclasses__()
    features.Provide(viewers_name, ctrls)
Exemplo n.º 12
0
def registerControllers():
    # load base controllers
    for c in getAllSubclasses(Controller):
        if isabstract(c):
            continue
        features.Provide(c.name, c())  # instantiate and add to ioc container