示例#1
0
    def test_custom_kw_creation(self):
        data = {"VALUE_1": 2345.234,
                "VALUE_2": 0.001234,
                "VALUE_3": "string_1",
                "VALUE_4": "string_2"}

        with TestAreaContext("python/enkf/data/custom_kw_creation") as test_area:

            self.createResultFile("result_file", data)

            custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

            self.assertEqual(len(custom_kw_config), 0)

            custom_kw = CustomKW(custom_kw_config)

            custom_kw.fload("result_file")
            self.assertEqual(len(custom_kw_config), 4)

            for key in data:
                index = custom_kw_config.indexOfKey(key)
                self.assertEqual(data[key], custom_kw[key])

            with self.assertRaises(KeyError):
                value = custom_kw["VALUE_5"]
示例#2
0
    def test_custom_kw_creation(self):
        data = {
            "VALUE_1": 2345.234,
            "VALUE_2": 0.001234,
            "VALUE_3": "string_1",
            "VALUE_4": "string_2"
        }

        with TestAreaContext(
                "python/enkf/data/custom_kw_creation") as test_area:

            self.createResultFile("result_file", data)

            custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

            self.assertEqual(len(custom_kw_config), 0)

            custom_kw = CustomKW(custom_kw_config)

            custom_kw.fload("result_file")
            self.assertEqual(len(custom_kw_config), 4)

            for key in data:
                index = custom_kw_config.indexOfKey(key)
                self.assertEqual(data[key], custom_kw[key])

            with self.assertRaises(KeyError):
                value = custom_kw["VALUE_5"]
示例#3
0
    def test_custom_kw_config_data_is_null(self):
        data_1 = {"VALUE_1": 123453.3, "VALUE_2": 0.234234}

        data_2 = {"VALUE_1": 965689, "VALUE_3": 1.1222}

        with TestAreaContext(
                "python/enkf/data/custom_kw_null_element") as test_area:

            self.createResultFile("result_file_1", data_1)
            self.createResultFile("result_file_2", data_2)

            custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

            custom_kw_1 = CustomKW(custom_kw_config)
            custom_kw_1.fload("result_file_1")

            custom_kw_2 = CustomKW(custom_kw_config)
            custom_kw_2.fload("result_file_2")

            index_1 = custom_kw_config.indexOfKey("VALUE_1")
            index_2 = custom_kw_config.indexOfKey("VALUE_2")

            self.assertEqual(custom_kw_1["VALUE_1"], data_1["VALUE_1"])
            self.assertEqual(custom_kw_2["VALUE_1"], data_2["VALUE_1"])

            self.assertIsNone(custom_kw_2["VALUE_2"])
            self.assertFalse("VALUE_3" in custom_kw_config)
示例#4
0
    def test_custom_kw_config_data_is_null(self):
            data_1 = {"VALUE_1": 123453.3,
                      "VALUE_2": 0.234234}

            data_2 = {"VALUE_1": 965689,
                      "VALUE_3": 1.1222}

            with TestAreaContext("python/enkf/data/custom_kw_null_element") as test_area:

                self.createResultFile("result_file_1", data_1)
                self.createResultFile("result_file_2", data_2)

                custom_kw_config = CustomKWConfig("CUSTOM_KW", "result_file")

                custom_kw_1 = CustomKW(custom_kw_config)
                custom_kw_1.fload("result_file_1")

                custom_kw_2 = CustomKW(custom_kw_config)
                custom_kw_2.fload("result_file_2")

                index_1 = custom_kw_config.indexOfKey("VALUE_1")
                index_2 = custom_kw_config.indexOfKey("VALUE_2")

                self.assertEqual(custom_kw_1["VALUE_1"], data_1["VALUE_1"])
                self.assertEqual(custom_kw_2["VALUE_1"], data_2["VALUE_1"])

                self.assertIsNone(custom_kw_2["VALUE_2"])
                self.assertFalse( "VALUE_3" in custom_kw_config )
示例#5
0
    def test_custom_kw_set_values(self):
        definition = {"STRING": str, "FLOAT": float, "INT": float}

        ckwc = CustomKWConfig("Test", None, definition=definition)

        ckw = CustomKW(ckwc)
        with self.assertRaises(KeyError):
            ckw["ANOTHER_STRING"] = "another string"

        ckw["STRING"] = "string"
        ckw["FLOAT"] = 3.1415
        ckw["INT"] = 1

        self.assertEqual(ckw["STRING"], "string")
        self.assertEqual(ckw["FLOAT"], 3.1415)
        self.assertEqual(ckw["INT"], 1)
示例#6
0
    def asCustomKW(self):
        """ @rtype: CustomKW """
        impl_type = self.getImplType()
        assert impl_type == ErtImplType.CUSTOM_KW

        return CustomKW.createCReference(self.valuePointer(), self)
示例#7
0
文件: enkf_node.py 项目: agchitu/ert
    def asCustomKW(self):
        """ @rtype: CustomKW """
        impl_type = self.getImplType( )
        assert impl_type == ErtImplType.CUSTOM_KW

        return CustomKW.createCReference(self.valuePointer(), self)
示例#8
0
    def asCustomKW(self):
        """ @rtype: CustomKW """
        impl_type = EnkfNode.cNamespace().get_impl_type(self)
        assert impl_type == ErtImplType.CUSTOM_KW

        return CustomKW.createCReference(self.valuePointer(), self)