コード例 #1
0
def test_DataBlock_key_management(dataspace):  # noqa: F811
    my_tm = dataspace.get_taskmanagers()[0]  # fetch one of our loaded examples
    header = datablock.Header(my_tm["taskmanager_id"])
    dblock = datablock.DataBlock(dataspace, my_tm["name"],
                                 my_tm["taskmanager_id"])

    dblock.put("example_test_key", "example_test_value", header)

    assert "example_test_key" in dblock.keys()
    assert "example_test_key" in dblock

    assert dblock.get("example_test_key") == "example_test_value"

    # Test product-retriever interface
    retriever = datablock.ProductRetriever("example_test_key", None, None)
    assert retriever(dblock) == "example_test_value"
    assert (
        str(retriever) ==
        "Product retriever for {'name': 'example_test_key', 'type': None, 'creator': None}"
    )

    # FIXME: The following behavior should be disallowed for data-integrity reasons!
    #        i.e. replacing a product name with a different value.
    newDict = {"subKey": "newValue"}
    dblock.put("example_test_key", newDict, header)
    assert dblock["example_test_key"] == newDict
コード例 #2
0
    def test_DataBlock_key_management(self):
        dataproduct = self.data["dataproduct"][0]
        header = datablock.Header(dataproduct["taskmanager_id"])

        self.datablock.put(dataproduct["key"], dataproduct["value"], header)

        self.assertIn(dataproduct["key"], self.datablock.keys())
        self.assertIn(dataproduct["key"], self.datablock)

        self.assertEqual(self.datablock.get(dataproduct["key"]),
                         dataproduct["value"])

        # Test product-retriever interface
        retriever = datablock.ProductRetriever(dataproduct["key"], None, None)
        assert retriever(self.datablock) == dataproduct["value"]
        assert str(
            retriever
        ) == "Product retriever for {'name': 'test_key1', 'type': None, 'creator': None}"

        # FIXME: The following behavior should be disallowed for data-integrity reasons!
        #        i.e. replacing a product name with a different value.
        newDict = {"subKey": "newValue"}
        self.datablock.put(dataproduct["key"], newDict, header)
        self.assertEqual(self.datablock[dataproduct["key"]], newDict)

        with self.assertRaises(KeyError):
            self.datablock["invalidKey"]
コード例 #3
0
def test_DataBlock_key_management(dataspace):  # noqa: F811
    my_tm = dataspace.get_taskmanagers()[0]  # fetch one of our loaded examples
    header = datablock.Header(my_tm["taskmanager_id"])
    metadata = datablock.Metadata(
        my_tm["taskmanager_id"],
        generation_id=dataspace.get_last_generation_id(
            my_tm["name"], my_tm["taskmanager_id"]),
    )
    dblock = datablock.DataBlock(dataspace, my_tm["name"],
                                 my_tm["taskmanager_id"])

    # test with automatic metadata and string value
    dblock.put("example_test_key", "example_test_value", header)

    assert "example_test_key" in dblock.keys()
    assert "example_test_key" in dblock

    assert dblock.get("example_test_key") == "example_test_value"

    # Test product-retriever interface
    retriever = datablock.ProductRetriever("example_test_key", None, None)
    assert retriever(dblock) == "example_test_value"
    assert (
        str(retriever) ==
        "Product retriever for {'name': 'example_test_key', 'type': None, 'creator': None}"
    )

    # test new key with manual metadata and dict value
    newDict = {"subKey": "newValue"}
    dblock.put("new_example_test_key", newDict, header, metadata)
    assert dblock["new_example_test_key"] == newDict
コード例 #4
0
 def new_and_add_members(class_type, module_parameters, *args, **kwargs):
     consumer = user_provided_new(class_type)
     product_specifications = module_parameters.get('product_creators', {})
     for name, product_type in cls._consumes.items():
         # FIXME: Need to adjust configuration usage in next line!
         setattr(consumer, name,
                 datablock.ProductRetriever(name,
                                            product_type,
                                            product_specifications.get(name, Any)))
     return consumer