Exemple #1
0
def test_parse_event_returns_leftover():
    t = random.random()
    v = random.random()
    e0 = event.Event("foobar", v, t)
    (_, s) = parser.parse_event("event 6|foobar %s %s;foobar" %
                                (repr(t), repr(v)))
    eq_("foobar", s)
Exemple #2
0
def test_serialize_unserialize_is_identity():
    e = event.Event("foobar", random.random(), random.randint(0, 86400))
    (k, v) = marshall.serialize_event(e, epoch=1970)
    e1 = marshall.unserialize_event("foobar", k, v, epoch=1970)
    eq_(e.name(), e1.name())
    eq_(e.unixtimestamp(), e1.unixtimestamp())
    eq_(e.timestamp(), e1.timestamp())
    eq_(e.value(), e1.value())
Exemple #3
0
def test_parse_event_legacy():
    t = random.randint(0, 10)
    v = random.random()
    e0 = event.Event("foobar", v, t)
    e1 = parser.parse_event_legacy("foobar: %s %s" % (repr(v), t))
    eq_(e0.name(), e1.name())
    eq_(e0.value(), e1.value())
    eq_(e0.unixtimestamp(), e1.unixtimestamp())
Exemple #4
0
def test_render_event_to_json():
    t = random.randint(0, 10)
    v = random.random()
    e = event.Event("foobar", v, t)
    eq_({
        "name": e.name(),
        "value": e.value(),
        "timestamp": e.unixtimestamp()
    }, pp.render_storable_to_json(e))
Exemple #5
0
def parse_event_legacy(s):
    (name, value) = s.split(": ", 2)
    if (" " in value):
        (lval, tval) = value.split(" ", 2)
        tval = long(tval, 10)
    else:
        lval = value
        tval = long(time.time())
    return (event.Event(name[:255], float(lval), tval))
Exemple #6
0
def test_parse_event():
    t = random.random()
    v = random.random()
    e0 = event.Event("foobar", v, t)
    (e1, s) = parser.parse_event("event 6|foobar %s %s;" % (repr(v), repr(t)))
    eq_(e0.name(), e1.name())
    eq_(e0.value(), e1.value())
    eq_(e0.unixtimestamp(), e1.unixtimestamp())
    eq_("", s)
Exemple #7
0
def parse_event(s):
    s = parse_string(s, "event ")
    (l, s) = parse_int(s)
    s = parse_string(s, "|")
    (n, s) = parse_take(s, l)
    s = parse_string(s, " ")
    (v, s) = parse_double(s)
    s = parse_string(s, " ")
    (t, s) = parse_double(s)
    if (s[0] == ";"):
        return (event.Event(n, v, t), s[1:])
    else:
        raise (ValueError("; was expected"))
Exemple #8
0
def test_render_storables():
    t = random.randint(0, 10)
    v = random.random()
    es = 10 * (event.Event("foobar", v, t), ) + 5 * (data.Data(
        "foobaz", [v], t), )
    eq_("".join(map(pp.render_storable, es)), pp.render_storables(es))
Exemple #9
0
def test_render_events():
    t = random.randint(0, 10)
    v = random.random()
    es = 10 * (event.Event("foobar", v, t), )
    eq_("".join(map(pp.render_event, es)), pp.render_events(es))
Exemple #10
0
def test_render_event():
    t = random.randint(0, 10)
    v = random.random()
    e = event.Event("foobar", v, t)
    eq_("event 6|foobar %s %s.0;" % (repr(v), e.unixtimestamp()),
        pp.render_event(e))
Exemple #11
0
def unserialize_event(name, k, v, epoch):
    timetuple = list(unserialize_key(k, epoch=epoch))
    timestamp = funcs.timetuple_timestamp(timetuple)
    return (event.Event(name, v, timestamp))