Esempio n. 1
0
def test_serialize_deserialize_pickle():
    """
    Test that serialization and the deserialization of a
    MemoryDetectionElement instance with populated detection components
    results in a different but equivalent instance.
    """
    expected_uuid = 'some-uuid'
    expected_bbox = AxisAlignedBoundingBox([0, 0], [1, 2])
    expected_ce_map = {'a': .24, 'b': 0.5, 0: .26}
    expected_ce = MemoryClassificationElement('ce-type', expected_uuid)
    expected_ce.set_classification(expected_ce_map)

    e1 = MemoryDetectionElement(expected_uuid)
    e1._bbox = expected_bbox
    e1._classification = expected_ce

    buff = pickle.dumps(e1)

    #: :type: MemoryDetectionElement
    e2 = pickle.loads(buff)
    assert e2 is not e1
    assert e2.uuid == expected_uuid

    e2_bbox, e2_ce = e2.get_detection()
    # Intentionally checking e2_bbox is not the same instance
    assert e2_bbox is not expected_bbox  # lgtm[py/comparison-using-is]
    assert e2_bbox == expected_bbox
    assert e2_ce is not expected_ce
    assert e2_ce == expected_ce
    assert e2_ce.get_classification() == expected_ce_map
Esempio n. 2
0
    def test_serialization_nonempty(self):
        e = MemoryClassificationElement('test', 0)
        e.set_classification(a=0, b=1)

        expected_map = {'a': 0, 'b': 1}
        assert e._c == expected_map
        e2 = cPickle.loads(cPickle.dumps(e))
        assert e2._c == expected_map
Esempio n. 3
0
    def test_set_classification(self):
        """
        Test setting valid classification map.
        """
        e = MemoryClassificationElement('test', 0)

        expected_map = {'a': 1, 'b': 0}
        e.set_classification(expected_map)
        assert e._c == expected_map