Simple test

Ensure your device works with this simple test.

examples/binascii_simpletest.py
 1# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4from adafruit_binascii import hexlify, unhexlify, a2b_base64, b2a_base64
 5
 6print("-- Binary<->Hex Conversions --")
 7# Binary data.
 8data = b"CircuitPython is Awesome!"
 9print("Original Binary Data: ", data)
10
11# Get the hexadecimal representation of the binary data
12hex_data = hexlify(data)
13print("Hex Data: ", hex_data)
14# Verify data
15assert (
16    hex_data == b"43697263756974507974686f6e20697320417765736f6d6521",
17), "hexlified data does not match expected data."
18# Get the binary data represented by hex_data
19bin_data = unhexlify(hex_data)
20print("Binary Data: ", bin_data)
21# Verify data
22assert bin_data == data, "unhexlified binary data does not match original binary data."
23
24print("-- Base64 ASCII <-> Binary Conversions --")
25data = b"Blinka"
26print("Original Binary Data: ", data)
27# Convert binary data to a line of ASCII characters in base64 coding.
28b64_ascii_data = b2a_base64(data)
29print("Base64 ASCII Data: ", b64_ascii_data)
30assert b64_ascii_data == b"Qmxpbmth\n", "Expected base64 coding does not match."
31
32# Convert a block of base64 data back to binary data.
33bin_data = a2b_base64(b"Qmxpbmth\n")
34print("Converted b64 ASCII->Binary Data: ", bin_data)
35assert bin_data == data, "Expected binary data does not match."