Esempio n. 1
0
    def test_caching(self):
        self.assertTrue(isinstance(self.str_obj_model, M.ProtoSpec))
        # XXX A HACK WHILE WE CHANGE INTERFACE ------------
        msg_spec = self.str_obj_model.msgs[0]
        name = msg_spec.name

        cls0 = make_msg_class(self.str_obj_model, name)
        # DEBUG
        print("Constructed Clz0 name is '%s'" % cls0.name)
        # END
        self.assertEqual(name, cls0.name)
        cls1 = make_msg_class(self.str_obj_model, name)
        self.assertEqual(name, cls1.name)

        # END HACK ----------------------------------------
        # we cache classe, so the two should be the same
        self.assertEqual(id(cls0), id(cls1))

        # chan    = Channel(BUFSIZE)
        values = self.lil_big_msg_values()
        lil_big_msg0 = cls0(values)
        lil_big_msg1 = cls0(values)
        # we don't cache instances, so these will differ
        self.assertNotEqual(id(lil_big_msg0), id(lil_big_msg1))

        field_spec = msg_spec[0]
        dotted_name = "%s.%s" % (self.proto_name, msg_spec.name)
        f0cls = make_field_class(dotted_name, field_spec)
        f1cls = make_field_class(dotted_name, field_spec)
        self.assertEqual(id(f0cls), id(f1cls))
Esempio n. 2
0
    def test_caching(self):
        """ verify that classes with the same definition are cached """
        str_obj_model = self.make_str_obj_model()
        proto_name = str_obj_model.name
        self.assertTrue(isinstance(str_obj_model, M.ProtoSpec))

        outer_msg_spec = str_obj_model.msgs[0]
        inner_msg_spec = str_obj_model.msgs[0].msgs[0]
        outer_msg_cls = make_msg_class(str_obj_model, outer_msg_spec.name)
        # NOTE change in parent
        inner_msg_cls = make_msg_class(outer_msg_spec, inner_msg_spec.name)

        # TEST INNER MESSAGE ########################################
        cls0 = make_msg_class(outer_msg_spec, inner_msg_spec.name)
        cls1 = make_msg_class(outer_msg_spec, inner_msg_spec.name)
        # we cache classes, so the two should be the same
        self.assertEqual(id(cls0), id(cls1))

        # test that msg instances created from the same value lists differ
        values = host_info_values()
        inner_msg0 = cls0(values)
        inner_msg1 = cls0(values)
        # we don't cache instances, so these will differ
        self.assertNotEqual(id(inner_msg0), id(inner_msg1))

        # verify that field classes are cached
        field_spec = inner_msg_spec[0]
        dotted_name = '%s.%s' % (proto_name, inner_msg_spec.name)
        f0cls = make_field_class(dotted_name, field_spec)
        f1cls = make_field_class(dotted_name, field_spec)
        self.assertEqual(id(f0cls), id(f1cls))           # GEEP

        # TEST OUTER MESSAGE ########################################
        cls2 = make_msg_class(str_obj_model, outer_msg_spec.name)
        cls3 = make_msg_class(str_obj_model, outer_msg_spec.name)
        # we cache classe, so the two should be the same
        self.assertEqual(id(cls2), id(cls3))

        # test that msg instances created from the same value lists differ
        ring = ring_data_values()  # a list of random hosts

        # 'values' is a list of field values.  In this case, the single
        # value is itself a list, a list of HostInfo value lists.
        values = [ring]            # a list whose only member is a list

        outer_msg0 = cls2(values)
        outer_msg1 = cls2(values)
        # we don't cache instances, so these will differ
        self.assertNotEqual(id(outer_msg0), id(outer_msg1))

        field_spec = outer_msg_spec[0]
        dotted_name = '%s.%s' % (proto_name, outer_msg_spec.name)
        f0cls = make_field_class(dotted_name, field_spec)
        f1cls = make_field_class(dotted_name, field_spec)
        self.assertEqual(id(f0cls), id(f1cls))           # GEEP
Esempio n. 3
0
    def check_field_impl_against_spec(
            self, proto_name, msg_name, field_spec, value):
        self.assertIsNotNone(field_spec)
        dotted_name = "%s.%s" % (proto_name, msg_name)
        cls = make_field_class(dotted_name, field_spec)
        if '__dict__' in dir(cls):
            print('\nGENERATED FieldImpl CLASS DICTIONARY')
            for exc in list(cls.__dict__.keys()):
                print("%-20s %s" % (exc, cls.__dict__[exc]))

        self.assertIsNotNone(cls)
        file = cls(value)
        self.assertIsNotNone(file)

        # class attributes --------------------------------
        self.assertEqual(field_spec.name, file.name)
        self.assertEqual(field_spec.field_type_ndx, file.field_type)
        self.assertEqual(field_spec.quantifier, file.quantifier)
        self.assertEqual(field_spec.field_nbr, file.field_nbr)
        self.assertIsNone(file.default)          # not an elegant test

        # instance attribute ------------------------------
        self.assertEqual(value, file.value)

        # with slots enabled, this is never seen ----------
        # because __dict__ is not in the list of valid
        # attributes for f
        if '__dict__' in dir(file):
            print('\nGENERATED FieldImpl INSTANCE DICTIONARY')
            for item in list(file.__dict__.keys()):
                print("%-20s %s" % (item, file.__dict__[item]))     # GEEP
Esempio n. 4
0
    def test_caching(self):
        self.assertTrue(isinstance(self.str_obj_model, M.ProtoSpec))
        msg_spec = self.str_obj_model.msgs[0]
        name = msg_spec.name
        cls0 = make_msg_class(self.str_obj_model, name)
        cls1 = make_msg_class(self.str_obj_model, name)
        # we cache classe, so the two should be the same
        self.assertEqual(id(cls0), id(cls1))

        # chan    = Channel(BUFSIZE)
        values = self.le_msg_values()
        le_msg0 = cls0(values)
        le_msg1 = cls0(values)
        # we don't cache instances, so these will differ
        self.assertNotEqual(id(le_msg0), id(le_msg1))

        field_spec = msg_spec[0]
        dotted_name = "%s.%s" % (self.proto_name, msg_spec.name)
        f0cls = make_field_class(dotted_name, field_spec)
        f1cls = make_field_class(dotted_name, field_spec)
        self.assertEqual(id(f0cls), id(f1cls))           # GEEP