def test_by_suffix(m):
    wrapped = a.by_suffix({"test": m, "train": m})

    for k, vs in m.items():
        assert wrapped.get(a.attach_s(k, "test", prefix=False)) == vs
        assert wrapped.get(a.attach_s(k, "train", prefix=False)) == vs
        assert wrapped.get(a.attach_s(k, "random", prefix=False)) is None
Beispiel #2
0
def test_prefixed_reader(prefix, m):
    """Test that prefixes work."""
    prefixed = {a.attach_s(k, prefix, prefix=True): v for k, v in m.items()}
    mem = rs.MemoryReader(prefixed)

    # the bare store, when queried with keys with the prefix attached, returns
    # the right stuff.
    assert mem.read_all(prefixed.keys()) == prefixed

    reader = mem.with_prefix(prefix)
    # If instead you generate a new reader using with_prefix, you don't need to
    # pass prefixed keys in to read_all; they'll get automatically attached.
    assert reader.read_all(m.keys()) == prefixed

    # read implementation works too.
    for k, v in m.items():
        assert reader.read(k) == v
Beispiel #3
0
 def report(self, step: int, k: t.MetricKey, v: t.Metric) -> None:
     newk = a.attach_s(k, self._suffix, prefix=False)
     self._base.report(step, newk, v)
Beispiel #4
0
 def read(self, k: t.MetricKey) -> List[t.Metric]:
     return self._base.read(a.attach_s(k, self._suffix, prefix=False))