Ejemplo n.º 1
0
        def get_input(self,
                      source: CharDataSourceBase,
                      key: str,
                      default: str = "") -> str:
            """
            Gets the input string that was used to set data_source[key] in the data_source specified by where / target_type / target_desc.

            Note about data_source behaviour:
            If data_source supports input_lookup, but key is not present, this returns default (empty string unless specified).
            If data_source does not support input_lookup, we return either None or some information string.
            We do NOT raise an exception.

            See also get_input_source for a version that determines data_source from the key.
            """
            return source.get_input(key, default=default)
Ejemplo n.º 2
0
def _test_dict_like_data_source(data_source: CharDataSourceBase):
    assert "x" not in data_source
    assert data_source.contains_unrestricted or data_source.contains_restricted
    assert data_source.stores_parsed_data or data_source.stores_input_data
    assert not data_source.read_only
    if data_source.default_write:
        assert data_source.type_unique
    assert "__x__" not in data_source
    if data_source.contains_unrestricted:
        test_key = "x.y"
        test_key2 = "x.y.z"
    else:
        test_key = "__x__.y"
        test_key2 = "__x__.y.z"

    if data_source.stores_input_data:
        data_source.set_input(test_key, "12")
        assert data_source.get_input(test_key) == "12"
        assert data_source[test_key] == 12
        assert test_key in data_source
        data_source.set_input(test_key, "=1+2")
        assert data_source.get_input(test_key) == "=1+2"
        assert isinstance(data_source[test_key], Parser.AST)
        data_source.set_input(test_key, "'abc")
        assert data_source.get_input(test_key) == "'abc"
        assert data_source[test_key] == "abc"
        data_source.bulk_set_inputs({test_key: "3", test_key2: "'4"})
        assert data_source.bulk_get_inputs((test_key, test_key2)) == {
            test_key: "3",
            test_key2: "'4"
        }
        assert data_source.bulk_get_items((test_key, test_key2)) == {
            test_key: 3,
            test_key2: "4"
        }

        data_source.set_input(test_key, "")
        assert test_key not in data_source
        data_source.set_input(test_key, "")
        assert test_key not in data_source

        data_source.set_input(test_key, "1")
        assert test_key in data_source
        del data_source[test_key]
        assert test_key not in data_source
    else:
        test_key += ".z"
        assert test_key not in data_source
        data_source[test_key] = "=a"
        assert data_source[test_key] == "=a"
        data_source.get_input(
            test_key)  # Just verifies that this does not raise an exception
        data_source[test_key] = 1
        assert data_source[test_key] == 1
        del data_source[test_key]
        assert test_key not in data_source
        data_source.bulk_set_items({test_key: 5, test_key2: "6"})
        assert data_source.bulk_get_items((test_key, test_key2)) == {
            test_key: 5,
            test_key2: "6"
        }
Ejemplo n.º 3
0
 def bulk_get_inputs(self,
                     source: CharDataSourceBase,
                     keys: Iterable[str],
                     default: str = "") -> Dict[str, str]:
     return source.bulk_get_inputs(keys, default=default)
Ejemplo n.º 4
0
 def bulk_delete(self, source: CharDataSourceBase,
                 keys: Iterable[str]) -> None:
     source.bulk_del_items(keys)
     if keys:
         self._update_last_changed()
Ejemplo n.º 5
0
 def bulk_set_input(self, source: CharDataSourceBase,
                    key_values: Dict[str, str]) -> None:
     source.bulk_set_inputs(key_values)
     if key_values:
         self._update_last_changed()
Ejemplo n.º 6
0
 def set_input(self, source: CharDataSourceBase, key: str,
               value: str) -> None:
     source.set_input(key, value)
     self._update_last_changed()