Esempio n. 1
0
    def test_combination_gl_python_types(self):

        sg_test_1 = tc.SGraph().add_vertices([
            tc.Vertex(1, {'fluffy': 1}),
            tc.Vertex(2, {
                'fluffy': 1,
                'woof': 1
            }),
            tc.Vertex(3, {})
        ])
        sarray_test_1 = tc.SArray([1, 2, 3])
        sframe_test_1 = tc.SFrame([1, 2, 3])

        obj_list = [[sg_test_1, sframe_test_1, sarray_test_1], {
            0: sg_test_1,
            1: sframe_test_1,
            2: sarray_test_1
        }]

        for obj in obj_list:
            pickler = gl_pickle.GLPickler(self.filename)
            pickler.dump(obj)
            pickler.close()
            unpickler = gl_pickle.GLUnpickler(self.filename)
            obj_ret = unpickler.load()
            unpickler.close()
            assert_sframe_equal(obj[0].get_vertices(),
                                obj_ret[0].get_vertices())
            assert_sframe_equal(obj[0].get_edges(), obj_ret[0].get_edges())
            assert_sframe_equal(obj[1], obj_ret[1])
            assert list(obj[2]) == list(obj_ret[2])
Esempio n. 2
0
    def test_pickling_sgraph_types(self):

        sg_test_1 = tc.SGraph().add_vertices([
            tc.Vertex(0, {'fluffy': 1}),
            tc.Vertex(1, {
                'fluffy': 1,
                'woof': 1
            }),
            tc.Vertex(2, {})
        ])

        sg_test_2 = tc.SGraph()
        sg_test_2 = sg_test_2.add_vertices([tc.Vertex(x) for x in [0, 1, 2]])
        sg_test_2 = sg_test_2.add_edges([
            tc.Edge(0, 1, attr={'relationship': 'dislikes'}),
            tc.Edge(1, 2, attr={'relationship': 'likes'}),
            tc.Edge(1, 0, attr={'relationship': 'likes'})
        ])

        sarray_list = [sg_test_1, sg_test_2]
        for obj in sarray_list:
            pickler = gl_pickle.GLPickler(self.filename)
            pickler.dump(obj)
            pickler.close()
            unpickler = gl_pickle.GLUnpickler(self.filename)
            obj_ret = unpickler.load()
            unpickler.close()
            assert_sframe_equal(obj.get_vertices(), obj_ret.get_vertices())
            assert_sframe_equal(obj.get_edges(), obj_ret.get_edges())