Exemplo n.º 1
0
class TestObjects(unittest.TestCase):
    def setUp(self):
        self.tx = TagMapper(known_tags)

    def _oso(self, ob):
        ser = self.tx.dumps(ob)
        try:
            o2 = self.tx.loads(ser)
            assert ob == o2, '%r != %r from %s' % (ob, o2,
                                                   base64.b16encode(ser))
        except Exception as e:
            sys.stderr.write(
                'failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(
                    len(ser), hexstr(ser), ob, ser, e))
            raise

    def test_basic(self):
        self._oso(SomeType(1, 2))

    def test_unk_fail(self):
        ok = False
        try:
            self.tx.dumps(UnknownType())
        except:
            ok = True
        assert ok

    def test_tag_passthrough(self):
        self.tx.raise_on_unknown_tag = False
        self._oso(Tag(1234, 'aoeu'))

    def test_unk_tag_fail(self):
        ok = False
        self.tx.raise_on_unknown_tag = True
        try:
            self._oso(Tag(1234, 'aoeu'))
        except UnknownTagException as ute:
            ok = True
        ok = False
Exemplo n.º 2
0
class TestObjects():
    def __init__(self):
        self.tx = TagMapper(known_tags)

    def _oso(self, ob):
        ser = self.tx.dumps(ob)
        try:
            o2 = self.tx.loads(ser)
            assert ob == o2, '%r != %r from %s' % (ob, o2, ubinascii.hexlify(ser))
        except Exception as e:
            print('failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(len(ser), hexstr(ser), ob, ser, e))
            raise

    def test_basic(self):
        self._oso(SomeType(1,2))

    def test_unk_fail(self):
        ok = False
        try:
            self.tx.dumps(UnknownType())
        except:
            ok = True
        assert ok

    def test_tag_passthrough(self):
        self.tx.raise_on_unknown_tag = False
        self._oso(Tag(1234, 'aoeu'))

    def test_unk_tag_fail(self):
        ok = False
        self.tx.raise_on_unknown_tag = True
        try:
            self._oso(Tag(1234, 'aoeu'))
        except UnknownTagException as ute:
            ok = True
        assert ok
Exemplo n.º 3
0
class TestObjects(unittest.TestCase):
    def setUp(self):
        self.tx = TagMapper(known_tags)

    def _oso(self, ob):
        ser = self.tx.dumps(ob)
        try:
            o2 = self.tx.loads(ser)
            assert ob == o2, '%r != %r from %s' % (ob, o2, base64.b16encode(ser))
        except Exception as e:
            sys.stderr.write('failure on buf len={0} {1!r} ob={2!r} {3!r}; {4}\n'.format(len(ser), hexstr(ser), ob, ser, e))
            raise

    def test_basic(self):
        self._oso(SomeType(1,2))

    def test_unk_fail(self):
        ok = False
        try:
            self.tx.dumps(UnknownType())
        except:
            ok = True
        assert ok

    def test_tag_passthrough(self):
        self.tx.raise_on_unknown_tag = False
        self._oso(Tag(1234, 'aoeu'))

    def test_unk_tag_fail(self):
        ok = False
        self.tx.raise_on_unknown_tag = True
        try:
            self._oso(Tag(1234, 'aoeu'))
        except UnknownTagException as ute:
            ok = True
        ok = False
Exemplo n.º 4
0
 def __init__(self):
     self.tx = TagMapper(known_tags)
Exemplo n.º 5
0
 def setUp(self):
     self.tx = TagMapper(known_tags)
Exemplo n.º 6
0
 def setUp(self):
     self.tx = TagMapper(known_tags)