コード例 #1
0
ファイル: test_record.py プロジェクト: ozliver/ndeflib
    def test_decode_known_type(self):
        class MyRecord(Record):
            _type = 'urn:nfc:wkt:x'
            _decode_min_payload_length = 1
            _decode_max_payload_length = 1

            @classmethod
            def _decode_payload(cls, octets, errors):
                return MyRecord()

        known_types = {MyRecord._type: MyRecord}
        stream = BytesIO(bytearray.fromhex('1101017800'))
        record = Record._decode(stream, 'strict', known_types)[0]
        assert type(record) == MyRecord

        errstr = 'payload length can not be less than 1'
        stream = BytesIO(bytearray.fromhex('11010078'))
        with pytest.raises(ndef.DecodeError) as excinfo:
            Record._decode(stream, 'strict', known_types)
        assert str(excinfo.value) == 'test_record.MyRecord ' + errstr

        errstr = 'payload length can not be more than 1'
        stream = BytesIO(bytearray.fromhex('110102780000'))
        with pytest.raises(ndef.DecodeError) as excinfo:
            Record._decode(stream, 'strict', known_types)
        assert str(excinfo.value) == 'test_record.MyRecord ' + errstr
コード例 #2
0
ファイル: test_record.py プロジェクト: nfcpy/ndeflib
    def test_decode_known_type(self):
        class MyRecord(Record):
            _type = 'urn:nfc:wkt:x'
            _decode_min_payload_length = 1
            _decode_max_payload_length = 1

            @classmethod
            def _decode_payload(cls, octets, errors):
                return MyRecord()

        known_types = {MyRecord._type: MyRecord}
        stream = BytesIO(bytearray.fromhex('1101017800'))
        record = Record._decode(stream, 'strict', known_types)[0]
        assert type(record) == MyRecord

        errstr = 'payload length can not be less than 1'
        stream = BytesIO(bytearray.fromhex('11010078'))
        with pytest.raises(ndef.DecodeError) as excinfo:
            Record._decode(stream, 'strict', known_types)
        assert str(excinfo.value) == 'test_record.MyRecord ' + errstr

        errstr = 'payload length can not be more than 1'
        stream = BytesIO(bytearray.fromhex('110102780000'))
        with pytest.raises(ndef.DecodeError) as excinfo:
            Record._decode(stream, 'strict', known_types)
        assert str(excinfo.value) == 'test_record.MyRecord ' + errstr
コード例 #3
0
ファイル: test_record.py プロジェクト: ozliver/ndeflib
 def test_limit(self):
     octets = bytearray.fromhex('')
     record = Record._decode(BytesIO(octets), 'strict', {})[0]
     assert record is None
     octets = bytearray.fromhex('050000100000') + 0x100000 * b'\0'
     record = Record._decode(BytesIO(octets), 'strict', {})[0]
     assert len(record.data) == 0x100000
     errstr = "payload of more than 1048576 octets can not be decoded"
     octets = bytearray.fromhex('050000100001') + 0x100001 * b'\0'
     with pytest.raises(ndef.DecodeError) as excinfo:
         Record._decode(BytesIO(octets), 'strict', {})
     assert str(excinfo.value) == 'ndef.record.Record ' + errstr
コード例 #4
0
ファイル: test_record.py プロジェクト: nfcpy/ndeflib
 def test_limit(self):
     octets = bytearray.fromhex('')
     record = Record._decode(BytesIO(octets), 'strict', {})[0]
     assert record is None
     octets = bytearray.fromhex('050000100000') + 0x100000 * b'\0'
     record = Record._decode(BytesIO(octets), 'strict', {})[0]
     assert len(record.data) == 0x100000
     errstr = "payload of more than 1048576 octets can not be decoded"
     octets = bytearray.fromhex('050000100001') + 0x100001 * b'\0'
     with pytest.raises(ndef.DecodeError) as excinfo:
         Record._decode(BytesIO(octets), 'strict', {})
     assert str(excinfo.value) == 'ndef.record.Record ' + errstr
コード例 #5
0
ファイル: test_record.py プロジェクト: ozliver/ndeflib
 def test_flags(self, encoded, _mb, _me, _cf):
     stream = BytesIO(bytearray.fromhex(encoded))
     record, mb, me, cf = Record._decode(stream, 'strict', {})
     assert mb == _mb
     assert me == _me
     assert cf == _cf
コード例 #6
0
ファイル: test_record.py プロジェクト: ozliver/ndeflib
 def test_fail(self, encoded, errstr):
     with pytest.raises(ndef.DecodeError) as excinfo:
         stream = BytesIO(bytearray.fromhex(encoded))
         Record._decode(stream, 'strict', {})
     assert errstr in str(excinfo.value)
コード例 #7
0
ファイル: test_record.py プロジェクト: ozliver/ndeflib
 def test_pass(self, args, encoded):
     stream = BytesIO(bytearray.fromhex(encoded))
     record = Record._decode(stream, 'strict', {})[0]
     assert record == Record(*args)
コード例 #8
0
ファイル: test_record.py プロジェクト: nfcpy/ndeflib
 def test_flags(self, encoded, _mb, _me, _cf):
     stream = BytesIO(bytearray.fromhex(encoded))
     record, mb, me, cf = Record._decode(stream, 'strict', {})
     assert mb == _mb
     assert me == _me
     assert cf == _cf
コード例 #9
0
ファイル: test_record.py プロジェクト: nfcpy/ndeflib
 def test_fail(self, encoded, errstr):
     with pytest.raises(ndef.DecodeError) as excinfo:
         stream = BytesIO(bytearray.fromhex(encoded))
         Record._decode(stream, 'strict', {})
     assert errstr in str(excinfo.value)
コード例 #10
0
ファイル: test_record.py プロジェクト: nfcpy/ndeflib
 def test_pass(self, args, encoded):
     stream = BytesIO(bytearray.fromhex(encoded))
     record = Record._decode(stream, 'strict', {})[0]
     assert record == Record(*args)