class Something: a: N(10) b: AN(20) other: Other others: List[Other] c: N(5) d: AN(10)
def test_AN_to_bytes_with_unicode_error_replace(): assert (AN(16, errors=UnicodeErrorHandler.REPLACE).to_bytes("동아・한신아파트") == b"\xb5\xbf\xbe\xc6?\xc7\xd1\xbd\xc5\xbe\xc6\xc6\xc4\xc6\xae ")
def test_AN_to_bytes_with_unicode_error_ignore(): assert (AN(16, errors=UnicodeErrorHandler.IGNORE).to_bytes("동아・한신아파트") == b"\xb5\xbf\xbe\xc6\xc7\xd1\xbd\xc5\xbe\xc6\xc6\xc4\xc6\xae ")
def test_AN_to_bytes_with_unicode_error_strict(): with pytest.raises(UnsupportedUnicodeError) as e: AN(30, errors=UnicodeErrorHandler.STRICT).to_bytes("동아・한신아파트") assert "codec can't encode character" in str(e.value)
def test_AN_to_bytes_with_invalid_length(): with pytest.raises(InvalidLengthError) as e: assert AN(5).to_bytes(date(2018, 9, 9)) assert 'Invalid length of value is given' in str(e.value)
def test_AN_to_bytes(length, value, expected): assert AN(length).to_bytes(value) == expected
class Other: an: AN(10) n: N(5)
class Other: n: N(5) an: AN(10)
class Something: n: N(10) an: AN(20) other: Other others: List[Other] filler: AN(100)
class One: an: AN(10) n: int