Example #1
0
def test_overwrites_existing(tmpdir):
    """Double writes to the same registry overwrites the first value"""
    the_key = "akey"
    first_value = "Some value"
    disk_registry.write_key(tmpdir, the_key, first_value)
    assert disk_registry.get_value(tmpdir, the_key) == first_value
    second_value = "Some value"
    disk_registry.write_key(tmpdir, the_key, second_value)
    assert disk_registry.get_value(tmpdir, the_key) == second_value
Example #2
0
def test_delete(tmpdir):
    """Delete removes a key"""
    the_key = "akey"
    first_value = "Some value"
    disk_registry.write_key(tmpdir, the_key, first_value)
    assert disk_registry.get_value(tmpdir, the_key) == first_value

    existed_p = disk_registry.delete_value(tmpdir, the_key)
    assert disk_registry.get_value(tmpdir, the_key) is None
    # They key existed
    assert existed_p
Example #3
0
    def check_cache(self, model_register_dir: Union[os.PathLike, str]):
        """
        Checks if the model is cached, and returns its path if it exists.

        Parameters
        ----------
        model_register_dir: [os.PathLike, None]
            The register dir where the model lies.
        cache_key: str
            A 512 byte hex value as a string based on the content of the parameters.

         Returns
        -------
        Union[os.PathLike, None]:
            The path to the cached model, or None if it does not exist.
        """
        existing_model_location = disk_registry.get_value(
            model_register_dir, self.cache_key)

        # Check that the model is actually there
        if existing_model_location and Path(existing_model_location).exists():
            logger.debug(
                f"Found existing model at path {existing_model_location}, returning it"
            )
            return existing_model_location
        elif existing_model_location:
            logger.warning(
                f"Found that the model-path {existing_model_location} stored in the "
                f"registry did not exist.")
            return None
        else:
            logger.info(
                f"Did not find the model with key {self.cache_key} in the register at "
                f"{model_register_dir}.")
            return None
Example #4
0
def test_complicated_happy_path(tmpdir):
    """Tests that it works to write and read a 'complicated' value"""
    value = """
    A long
    value with many weird character lie åøæ
    and some linebreaks"""
    disk_registry.write_key(tmpdir, "akey", value)
    assert disk_registry.get_value(tmpdir, "akey") == value
Example #5
0
def test_new_registry(tmpdir):
    """
    Tests that it works to write and read a simple value to a fresh registry with
    a non-existing directory
    """
    registry = pathlib.Path(tmpdir).joinpath("newregistry")
    disk_registry.write_key(registry, "akey", "aval")
    assert disk_registry.get_value(registry, "akey") == "aval"
Example #6
0
def test_simple_happy_path(tmpdir):
    """Tests that it works to write and read a simple value to a fresh registry"""
    disk_registry.write_key(tmpdir, "akey", "aval")
    assert disk_registry.get_value(tmpdir, "akey") == "aval"
Example #7
0
def test_get_value_without_registry_dir():
    """Test that it works to have registry_dir as None, and that it returns None as expected"""
    assert disk_registry.get_value(None, "akey") is None
Example #8
0
def test_double_delete(tmpdir):
    """Delete works on non-existing key, returning False"""
    the_key = "akey"
    existed_p = disk_registry.delete_value(tmpdir, the_key)
    assert disk_registry.get_value(tmpdir, the_key) is None
    assert not existed_p