Esempio n. 1
0
def test_process():
    data = read("tests/process.json")
    msg = dumps(loads(data))
    orig = json.loads(data)
    out = json.loads(msg)
    assert orig == out

    schemata.validate_process(loads(data))
Esempio n. 2
0
def test_message():
    data = read("tests/message.json")
    msg = dumps(loads(data))
    orig = json.loads(data)
    out = json.loads(msg)
    assert orig == out

    schemata.validate_message(loads(data))
Esempio n. 3
0
def test_validation2():
    data = read("tests/invalid.json")
    msg = loads(data, validate=False)
    errors = msg.problems()
    assert len(errors) > 0
    msg = dumps(loads(data))
    orig = json.loads(data)
    out = json.loads(msg)
    assert orig == out
Esempio n. 4
0
def test_measurement():
    data = read("tests/measurement.json")
    msg = dumps(loads(data))

    orig = json.loads(data)
    out = json.loads(msg)
    assert orig == out

    print json.dumps(out, indent=2)
    schemata.validate_measurement(loads(data))
Esempio n. 5
0
def test_convience_api():
    device = Device(deviceID="2098390", supplier="Contact")
    msg = loads(device.message("AB910T", hint="Axis is broken"))
    assert msg.device.deviceID == "2098390"
    assert msg.messages[0].code == "AB910T"

    schemata.validate_message(msg)
Esempio n. 6
0
def test_load_minimal():
    msg = loads(MINIMAL)
    assert msg.device.deviceID == "2ca5158b-8350-4592-bff9-755194497d4e"
    assert len(msg.messages) == 1

    tz_plus2 = dateutil.tz.tzoffset("+02:00", 2 * 60 * 60)

    m = Message(ts=datetime.datetime(2002, 5, 30, 9, 30, 10, 123000, tz_plus2),
                code="190ABT")
    assert msg.messages[0] == m
    schemata.validate_message(msg)
Esempio n. 7
0
def test_load_multiple():
    msg = loads(MULTIPLE)
    assert msg.device.deviceID == "2ca5158b-8350-4592-bff9-755194497d4e"
    assert msg.device.metaData["swVersion"] == "2.0.3.13"

    assert len(msg.messages) == 2

    assert msg.messages[0].origin == "sensor-id-992.2393.22"
    assert msg.messages[0].type == "DEVICE"
    assert msg.messages[0].severity == "HIGH"
    assert msg.messages[0].hint == "Check the control board"
    assert msg.messages[0].metaData["firmware"] == "20130304_22.020"

    schemata.validate_message(msg)
Esempio n. 8
0
def process_inbound_message(msg, classifier):
    inbound_msg = util.loads(msg, validate=True)

    data = stats.load_from_ppmp_msg(inbound_msg)

    result = classifier.predict([data])[0]

    meas = Measurement(ts=inbound_msg.measurements[0].ts,
                       result='NOK' if result == 'bad' else 'OK')

    meas.series.offsets.append(0)

    for dim, val in zip(stats.CHARACTERISTICS, data):
        meas.series.add_dimension(dim)
        meas.series[dim].append(val)

    outbound_msg = MeasurementPayload(device=inbound_msg.device,
                                      measurements=[meas])

    return util.dumps(outbound_msg, indent=2)
Esempio n. 9
0
def test_parse_measurement():
    meas_msg = loads(MEAS1)
    assert meas_msg.device.deviceID == "a4927dad-58d4-4580-b460-79cefd56775b"
    assert meas_msg.part.partID == "P918298"
    assert len(meas_msg.measurements) == 2
    samples = list(meas_msg.measurements[0].samples())
    assert len(samples) == 3
    tz_plus2 = dateutil.tz.tzoffset("+02:00", 2 * 60 * 60)
    assert samples[0] == {
        "ts": datetime.datetime(2002, 5, 30, 9, 30, 10, 123000, tz_plus2),
        "temperature": 45.4231,
    }, samples[0]
    assert samples[1] == {
        "ts": datetime.datetime(2002, 5, 30, 9, 30, 10, 146000, tz_plus2),
        "temperature": 46.4222,
    }, samples[1]
    m2 = meas_msg.measurements[1]
    assert m2.limits.pressure.upperError == 422

    schemata.validate_measurement(meas_msg)
Esempio n. 10
0
def roundtrip(obj):
    clone = loads(dumps(obj))
    assert obj == clone
Esempio n. 11
0
def test_convenience_api():
    d = Device("12345", maker="Bosch")
    msg = loads(d.measurement(temperature=36.7))
    assert msg.device.deviceID == d.deviceID
    assert msg.device.metaData["maker"] == "Bosch"
    assert msg.measurements[0].series.temperature == [36.7]
Esempio n. 12
0
def on_message(client, userdata, msg):
    msg = loads(msg.payload)
    print(msg)
Esempio n. 13
0
 def __init__(self, json):
     self.ppmp = loads(json, validate=True)
Esempio n. 14
0
def test_validation1():
    with raises(ValidationError):
        data = read("tests/invalid.json")
        loads(data, validate=True)