Exemple #1
0
    def test_data(self):
        input_keys = ["key1", "key2", "key3"]
        config = ExtParamConfig("Key", input_keys)
        data = ExtParam(config)

        with self.assertRaises(IndexError):
            d = data[100]

        with self.assertRaises(KeyError):
            d = data["NoSuchKey"]

        self.assertIn("key1", data)

        data[0] = 177
        self.assertEqual(data["key1"], 177)

        data["key2"] = 321
        self.assertEqual(data[1], 321)

        with self.assertRaises(ValueError):
            data.set_vector([1, 2])

        data.set_vector([1, 2, 3])
        for i in range(len(data)):
            self.assertEqual(i + 1, data[i])

        with TestAreaContext("json"):
            data.export("file.json")
            d = json.load(open("file.json"))

        for key in data.keys():
            self.assertEqual(data[key], d[key])
Exemple #2
0
    def test_data_with_suffixes(self):
        input_suffixes = [
            ["a", "b", "c"],
            ["2"],
            ["asd", "qwe", "zxc"],
        ]
        input_dict = {
            "key1": input_suffixes[0],
            "key2": input_suffixes[1],
            "key3": input_suffixes[2],
        }
        config = ExtParamConfig("Key", input_dict)
        data = ExtParam(config)

        with self.assertRaises(IndexError):
            data[0]  # Cannot use indices when we have suffixes
        with self.assertRaises(TypeError):
            data["key1", 1]
        with self.assertRaises(KeyError):
            data["NoSuchKey"]
        with self.assertRaises(KeyError):
            data["key1"]  # requires a suffix
        with self.assertRaises(KeyError):
            data["key1", "no_such_suffix"]

        data["key1", "a"] = 1
        data["key1", "b"] = 500.5
        data["key2", "2"] = 2.1
        data["key3", "asd"] = -85
        self.assertEqual(data["key1", "a"], 1)
        self.assertEqual(data["key1", "b"], 500.5)
        self.assertEqual(data["key2", "2"], 2.1)
        self.assertEqual(data["key3", "asd"], -85)

        # We don't know what the value is, but it should be possible to read it
        _ = data["key3", "zxc"]
Exemple #3
0
    def as_ext_param(self):
        """ @rtype: ExtParam """
        impl_type = self.getImplType()
        assert impl_type == ErtImplType.EXT_PARAM

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