示例#1
0
 def test_notify_destination(self):
     self.toolbox.msg = MagicMock()
     self.toolbox.msg.attach_mock(MagicMock(), "emit")
     self.toolbox.msg_warning = MagicMock()
     self.toolbox.msg_warning.attach_mock(MagicMock(), "emit")
     source_item = NonCallableMagicMock()
     source_item.name = "source name"
     source_item.item_type = MagicMock(return_value="Data Connection")
     self.importer.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established. You can define mappings on data from <b>source name</b> using item <b>importer</b>."
     )
     source_item.item_type = MagicMock(return_value="Data Store")
     self.importer.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with("Link established.")
     source_item.item_type = MagicMock(return_value="Exporter")
     self.importer.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>Exporter</b> and a <b>Importer</b> has not been implemented yet."
     )
     source_item.item_type = MagicMock(return_value="Tool")
     self.importer.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established."
         " You can define mappings on output files from <b>source name</b> using item <b>importer</b>."
     )
     source_item.item_type = MagicMock(return_value="View")
     self.importer.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>View</b> and a <b>Importer</b> has not been implemented yet.")
示例#2
0
 def test_notify_destination(self):
     self.toolbox.msg = MagicMock()
     self.toolbox.msg.attach_mock(MagicMock(), "emit")
     self.toolbox.msg_warning = MagicMock()
     self.toolbox.msg_warning.attach_mock(MagicMock(), "emit")
     source_item = NonCallableMagicMock()
     source_item.name = "source name"
     source_item.item_type = MagicMock(return_value="Importer")
     self.data_connection.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with("Link established.")
     source_item.item_type = MagicMock(return_value="Data Store")
     self.data_connection.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with("Link established.")
     source_item.item_type = MagicMock(return_value="Exporter")
     self.data_connection.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a <b>Exporter</b> and"
         " a <b>Data Connection</b> has not been implemented yet.")
     source_item.item_type = MagicMock(return_value="Tool")
     self.data_connection.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established. Tool <b>source name</b> output files"
         " will be passed as references to item <b>DC</b> after execution.")
     source_item.item_type = MagicMock(return_value="View")
     self.data_connection.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a <b>View</b> and"
         " a <b>Data Connection</b> has not been implemented yet.")
示例#3
0
 def test_notify_destination(self):
     self.toolbox.msg = MagicMock()
     self.toolbox.msg.attach_mock(MagicMock(), "emit")
     self.toolbox.msg_warning = MagicMock()
     self.toolbox.msg_warning.attach_mock(MagicMock(), "emit")
     source_item = NonCallableMagicMock()
     source_item.name = "source name"
     source_item.item_type = MagicMock(return_value="Data Connection")
     self.view.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a <b>Data Connection</b> and"
         " a <b>View</b> has not been implemented yet.")
     source_item.item_type = MagicMock(return_value="Importer")
     self.view.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a <b>Importer</b> and a <b>View</b> has not been implemented yet."
     )
     source_item.item_type = MagicMock(return_value="Data Store")
     self.view.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established. You can visualize Data Store <b>source name</b> in View <b>V</b>."
     )
     source_item.item_type = MagicMock(return_value="Exporter")
     self.view.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a <b>Exporter</b> and a <b>View</b> has not been implemented yet."
     )
     source_item.item_type = MagicMock(return_value="Tool")
     self.view.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established. You can visualize the ouput from Tool <b>source name</b> in View <b>V</b>."
     )
示例#4
0
 def test_notify_destination(self):
     self.toolbox.msg = MagicMock()
     self.toolbox.msg.attach_mock(MagicMock(), "emit")
     self.toolbox.msg_warning = MagicMock()
     self.toolbox.msg_warning.attach_mock(MagicMock(), "emit")
     source_item = NonCallableMagicMock()
     source_item.name = "source name"
     source_item.item_type = MagicMock(return_value="Data Connection")
     self.exporter.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>Data Connection</b> and a <b>Exporter</b> has not been implemented yet."
     )
     source_item.item_type = MagicMock(return_value="Importer")
     self.exporter.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>Importer</b> and a <b>Exporter</b> has not been implemented yet."
     )
     source_item.item_type = MagicMock(return_value="Data Store")
     self.exporter.notify_destination(source_item)
     self.toolbox.msg.emit.assert_called_with(
         "Link established. Data Store <b>source name</b> will be "
         "exported to a .gdx file by <b>exporter</b> when executing.")
     source_item.item_type = MagicMock(return_value="Tool")
     self.exporter.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>Tool</b> and a <b>Exporter</b> has not been implemented yet.")
     source_item.item_type = MagicMock(return_value="View")
     self.exporter.notify_destination(source_item)
     self.toolbox.msg_warning.emit.assert_called_with(
         "Link established. Interaction between a "
         "<b>View</b> and a <b>Exporter</b> has not been implemented yet.")
示例#5
0
def _get_user_mock(screen_name: Any = TWITTER_USER_SAMPLE['screen_name']) -> NonCallableMagicMock:
    user_mock = NonCallableMagicMock(spec=TwitterUser)
    user_mock.name = TWITTER_USER_SAMPLE['name']
    user_mock.screen_name = screen_name
    user_mock.user_id = TWITTER_USER_SAMPLE['id']
    user_mock.profile_image_url = TWITTER_USER_SAMPLE['profile_image_url_orig']
    return user_mock
示例#6
0
 def test_insert_item_leaf_item(self):
     root = RootProjectTreeItem()
     model = ProjectItemModel(self.toolbox, root)
     category = CategoryProjectTreeItem("category", "category description")
     model.insert_item(category)
     category_index = model.find_category("category")
     mock_project_item = NonCallableMagicMock()
     mock_project_item.name = "project item"
     mock_project_item.description = "project item description"
     leaf = LeafProjectTreeItem(mock_project_item, self.toolbox)
     model.insert_item(leaf, category_index)
     self.assertEqual(model.rowCount(), 1)
     self.assertEqual(model.rowCount(category_index), 1)
     self.assertEqual(model.n_items(), 1)
     self.assertEqual(model.items("category"), [leaf])
示例#7
0
    def _mock_item(name,
                   resources_forward=None,
                   resources_backward=None,
                   execute_outcome=ItemExecutionFinishState.SUCCESS):
        """Returns a mock project item.

        Args:
            name (str)
            resources_forward (list): Forward output_resources return value.
            resources_backward (list): Backward output_resources return value.
            execute_outcome (ItemExecutionFinishState): Execution return state.

        Returns:
            NonCallableMagicMock
        """
        if resources_forward is None:
            resources_forward = []
        if resources_backward is None:
            resources_backward = []
        item = NonCallableMagicMock()
        item.name = name
        item.short_name = name.lower().replace(' ', '_')
        item.fwd_flt_stacks = []
        item.bwd_flt_stacks = []

        def execute(forward_resources, backward_resources, item=item):
            item.fwd_flt_stacks += [
                r.metadata.get("filter_stack", ()) for r in forward_resources
            ]
            item.bwd_flt_stacks += [
                r.metadata.get("filter_stack", ()) for r in backward_resources
            ]
            return execute_outcome

        item.execute.side_effect = execute
        item.exclude_execution = MagicMock()
        for r in resources_forward + resources_backward:
            r.provider_name = item.name
        item.output_resources.side_effect = lambda direction: {
            ExecutionDirection.FORWARD: resources_forward,
            ExecutionDirection.BACKWARD: resources_backward,
        }[direction]
        return item