Ejemplo n.º 1
0
def test_artefact_update() -> None:
    """Test updating a const artefact."""
    db = Redis()
    store = RedisStorage(db)
    art = _graph.constant_artefact(db, store, b"bla bla")
    with pytest.raises(TypeError):
        _graph.set_data(db, store, art.hash, b"b", _graph.ArtefactStatus.done)
Ejemplo n.º 2
0
    def __init__(self, host: str, port: int = 6379, db: int = 0):
        if environ.env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
            from fakeredis import FakeRedis as Redis
        else:
            from redis import Redis

        self.redis = Redis(host=host, port=port, db=db)
Ejemplo n.º 3
0
def test_error_propagation_shell() -> None:
    """Test propagation of errors."""
    db = Redis()
    store = RedisStorage(db)
    s1 = funsies.shell(
        "cp file1 file3",
        inp=dict(file1="bla"),
        out=["file2"],
        connection=(db, store),
        opt=options(),
    )
    s2 = funsies.shell(
        "cat file2",
        inp=dict(file2=s1.out["file2"]),
        connection=(db, store),
        opt=options(),
    )
    s3 = funsies.shell(
        "cat file2",
        inp=dict(file2=s1.out["file2"]),
        strict=False,
        connection=(db, store),
        opt=options(),
    )

    run_op(db, store, s1.op.hash)
    run_op(db, store, s2.op.hash)
    with pytest.raises(UnwrapError):
        funsies.take(s2.stderr, connection=(db, store))

    run_op(db, store, s3.op.hash)
    assert funsies.take(s3.stderr, connection=(db, store)) != b""
    assert isinstance(funsies.take(s3.returncode, connection=(db, store)), int)
    assert funsies.take(s3.returncode, connection=(db, store)) != 0
Ejemplo n.º 4
0
Archivo: redis.py Proyecto: Xlzman/dino
    def __init__(self, env, host: str, port: int = 6379, db: int = 0):
        if env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
            from fakeredis import FakeStrictRedis as Redis
        else:
            from redis import Redis

        self.redis = Redis(host=host, port=port, db=db)
        self.cache = MemoryCache()
Ejemplo n.º 5
0
def test_artefact_add() -> None:
    """Test adding const artefacts."""
    db = Redis()
    store = RedisStorage(db)
    a = _graph.constant_artefact(db, store, b"bla bla")
    b = _graph.Artefact[bytes].grab(db, a.hash)
    assert b is not None
    assert a == b
Ejemplo n.º 6
0
    def __init__(self, env: GNEnvironment, host: str, port: int = 6379, db: int = 0):
        if environ.env.config.get(ConfigKeys.TESTING, False) or host == 'mock':
            from fakeredis import FakeStrictRedis as Redis
        else:
            from redis import Redis

        self.env = env
        self.redis = Redis(host=host, port=port, db=db)
        self.acl_validator = AclValidator()
Ejemplo n.º 7
0
def test_artefact_add_large() -> None:
    """Test adding large artefacts to a Redis store."""
    db = Redis()
    store = RedisStorage(db, block_size=8)
    art = _graph.variable_artefact(db, hash_t("1"), "file", cons.Encoding.blob)
    data = b"12345" * 100
    _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done)
    data2 = _graph.get_data(db, store, art)
    assert db.llen(cons.join(cons.ARTEFACTS, art.hash, "data")) == 63
    assert data == data2
Ejemplo n.º 8
0
def test_artefact_disk() -> None:
    """Test saving an artefact to disk and restoring it."""
    with tempfile.TemporaryDirectory() as td:
        db = Redis()
        store = DiskStorage(td)

        art = _graph.variable_artefact(db, hash_t("12345678"), "file",
                                       cons.Encoding.blob)
        data = b"12345" * 100
        _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done)
        data2 = _graph.get_data(db, store, art)
        assert data == data2
Ejemplo n.º 9
0
def test_artefact_replace_large() -> None:
    """Test replacing large artefacts."""
    db = Redis()
    store = RedisStorage(db, block_size=8)
    art = _graph.variable_artefact(db, hash_t("1"), "file", cons.Encoding.blob)
    data = b"12345" * 100
    _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done)

    store.block_size = 1000000
    _graph.set_data(db, store, art.hash, data, _graph.ArtefactStatus.done)
    data2 = _graph.get_data(db, store, art)

    assert data == data2
Ejemplo n.º 10
0
def test_artefact_load_errors() -> None:
    """Test loading artefact errors."""
    db = Redis()
    store = RedisStorage(db)
    with pytest.raises(RuntimeError):
        _ = _graph.Artefact.grab(db, hash_t("bla"))

    # TODO check that warnings are logged?
    _graph.constant_artefact(db, store, b"bla bla")
    _graph.constant_artefact(db, store, b"bla bla")

    _graph.variable_artefact(db, hash_t("1"), "file", Encoding.blob)
    _graph.variable_artefact(db, hash_t("1"), "file", Encoding.blob)
Ejemplo n.º 11
0
def test_artefact_disk_json() -> None:
    """Test saving an artefact to disk and restoring it."""
    with tempfile.TemporaryDirectory() as td:
        db = Redis()
        store = DiskStorage(td)

        art = _graph.variable_artefact(db, hash_t("12345678"), "file",
                                       cons.Encoding.json)
        dat = [0, 1, 2, 3, "a string"]
        bdat = _serdes.encode(_serdes.kind(dat), dat)

        _graph.set_data(db, store, art.hash, bdat, _graph.ArtefactStatus.done)
        data2 = _graph.get_data(db, store, art)
        assert dat == data2
Ejemplo n.º 12
0
def test_get_short_hash():
    """Test short hash saving and loading."""
    m = hashlib.sha1()
    m.update("hi 👋 I am a sha 1 hash".encode())
    val = m.hexdigest()

    m = hashlib.sha1()
    m.update("hi 👋  am another sha 1 hash".encode())
    val2 = m.hexdigest()

    # set up a hash that collides with val
    val_collide = val[:6] + "b" * (len(val) - 6)
    print(val)
    print(val2)
    print(val_collide)

    db = Redis()
    sh.hash_save(db, hash_t(val))
    sh.hash_save(db, hash_t(val_collide))
    sh.hash_save(db, hash_t(val2))

    dat = sh.hash_load(db, "")
    assert len(dat) == 3

    for i in range(1, 7):
        dat = sh.hash_load(db, val[:i])
        assert len(dat) == 2

    for i in range(7, len(val)):
        dat = sh.hash_load(db, val[:i])
        assert len(dat) == 1

    dat = sh.hash_load(db, val2)
    assert len(dat) == 1

    with pytest.raises(AttributeError):
        sh.hash_load(db, val + "x")