Esempio n. 1
0
    def round_trip_msg_spec_via_str(self, match, protocol):
        """
        Convert a MsgSpec object model to canonical string form,
        parse that to make a clone, and verify that the two are
        equal.
        """

        # should be unicode
        canonical_spec = match.__repr__()
        # DEBUG
        print("Type of m: ", type(match))
        print("CANONICAL SPEC:\n" + canonical_spec)
        # END

        node_reg = R.NodeReg()
        proto_reg = R.ProtoReg(protocol, node_reg)
        ppp = StringMsgSpecParser(StringIO(canonical_spec))

        # XXX FAILS: protoSpec has ill-formed protocol line
        cloned_spec = ppp.parse()

        self.assertIsNotNone(cloned_spec)
        # DEBUG =======================
        print('CLONED SPEC:\n' + cloned_spec.__repr__())
        # END =========================
        # crude tests of __eq__ AKA ==
        self.assertFalse(match is None)
        self.assertTrue(match == match)

        # one way of saying it ------------------
        self.assertTrue(match.__eq__(cloned_spec))
        self.assertTrue(cloned_spec.__eq__(match))
        # this is the same test -----------------
        self.assertTrue(match == cloned_spec)
        self.assertTrue(cloned_spec == match)                # FOO
Esempio n. 2
0
    def test_multi_enum(self):
        protocol = 'org.xlattice.fieldz.test.multiEnum'

        data = StringIO(MULTI_ENUM_MSG_SPEC)
        ppp = StringMsgSpecParser(data)   # data should be file-like
        str_obj_model = ppp.parse()             # object model from string serialization
        self.assertIsNotNone(str_obj_model)
        self.assertTrue(isinstance(str_obj_model, M.MsgSpec))

        # self.assertEqual( 'org.xlattice.zoggery', sOM.protocol )
        self.assertEqual('multiEnum', str_obj_model.name)

        enums = str_obj_model.enums
        self.assertIsNotNone(enums)
        self.assertEqual(2, len(enums))

        foo_enum = enums[0]
        bar_enum = enums[1]
        self.assertEqual('Foo', foo_enum.name)
        self.assertEqual('Bar', bar_enum.name)

        self.assertEqual(2, len(foo_enum))
        self.assertEqual(3, len(bar_enum))

        a_pair = foo_enum[0]
        self.assertEqual('aVal', a_pair.symbol)
        self.assertEqual(1, a_pair.value)

        b_pair = foo_enum[1]
        self.assertEqual('b_val', b_pair.symbol)
        self.assertEqual(2, b_pair.value)

        c_pair = bar_enum[0]
        self.assertEqual('cVal', c_pair.symbol)
        self.assertEqual(3, c_pair.value)

        d_pair = bar_enum[1]
        self.assertEqual('dVal', d_pair.symbol)
        self.assertEqual(4, d_pair.value)

        e_pair = bar_enum[2]
        self.assertEqual('exc', e_pair.symbol)
        self.assertEqual(5, e_pair.value)

        self.round_trip_msg_spec_via_str(
            str_obj_model, protocol)             # GEEP
Esempio n. 3
0
    def test_parse_and_write_msg_spec(self):
        data = StringIO(LOG_ENTRY_MSG_SPEC)
        ppp = StringMsgSpecParser(data)   # data should be file-like
        str_obj_model = ppp.parse()             # object model from string serialization
        self.assertIsNotNone(str_obj_model)
        self.assertTrue(isinstance(str_obj_model, M.MsgSpec))

        self.assertEqual('logEntry', str_obj_model.name)

        # XXX THIS SHOULD BE A LOOP, with no magic numbers
        self.assertEqual(str_obj_model.f_name(0), 'timestamp')
        self.assertEqual(str_obj_model.field_type_name(0), 'fuint32')
        self.assertEqual(str_obj_model.f_name(1), 'nodeID')
        self.assertEqual(str_obj_model.field_type_name(1), 'fbytes20')
        self.assertEqual(str_obj_model.f_name(2), 'key')
        self.assertEqual(str_obj_model.field_type_name(2), 'fbytes20')
        self.assertEqual(str_obj_model.f_name(3), 'length')
        self.assertEqual(str_obj_model.field_type_name(3), 'vuint32')
        self.assertEqual(str_obj_model.f_name(4), 'by')
        self.assertEqual(str_obj_model.field_type_name(4), 'lstring')
        self.assertEqual(str_obj_model.f_name(5), 'path')
        self.assertEqual(
            str_obj_model.field_type_name(5),
            'lstring')          # BAR