def test_decode_graphical_basic2(): message = fake.text() encoded = Ralgo(message).encode().graphical().encode() decoded = Ralgo(encoded.decode()).decode() assert str(decoded) == message
def test_convert_bytes(): message = os.urandom(420) encoded = Ralgo(message).encode() decoded = encoded.decode() assert bytes(decoded) == message
def test_decode_graphical_fails2(): try: graphical = Ralgo("tests/graphical/files/42.jpeg").graphical() _ = Ralgo(graphical.decode()).decode() assert False except InvalidImage as e: assert e.message == "The given image has an invalid size"
def test_decode_graphical_basic1(): message = "Salut" encoded = Ralgo(message).encode().graphical().encode() decoded = Ralgo(encoded.decode()).decode() assert str(decoded) == message
def test_encode_graphical_basic2(): message = fake.text() encoded = Ralgo(message).encode() _ = encoded.graphical().encode() assert True # this test should not fail
def test_decode_basic4(): message = "slt" encoded = Ralgo(message).encode() decoded = encoded.decode() assert str(decoded) == message
def test_decode_basic3(): message = fake.text() encoded = Ralgo(message).encode() decoded = encoded.decode() assert str(decoded) == message
def test_decode_fake_bytes4(): message = "b'ezf'ez'" encoded = Ralgo(message).encode() decoded = encoded.decode() assert str(decoded) == message
def test_decode_chars3(): message = fake.text() chars = ("-", "—") encoded = Ralgo(message).encode(chars=chars) decoded = encoded.decode(chars=chars) assert str(decoded) == message
def test_decode_depth3(): message = fake.text() depth = 12 encoded = Ralgo(message).encode(depth=depth) decoded = encoded.decode(depth=depth) assert str(decoded) == message
def test_decode_graphical_fails1(): try: # noinspection PyTypeChecker graphical = Ralgo(42).graphical() _ = Ralgo(graphical.decode()).decode() assert False except InvalidArgument as e: assert (e.message == "The file must be given by path (str) or bytes (bytes)")
def test_decode_bits3(): message = fake.text() depth = 12 bits = 42 encoded = Ralgo(message).encode(depth=depth, bits=bits) decoded = encoded.decode(depth=depth, bits=bits) assert str(decoded) == message
def test_encode_graphical_bytes1(): message = "Salut" encoded = Ralgo(message).encode().graphical().encode() arr = encoded.to_bytes() img = Image.open(BytesIO(arr)) assert img.size == (17, 17)
def test_compressor_full_op1(): message = fake.text() encoded = Ralgo(message).encode() compressed = encoded.compress() decompressed = compressed.decompress() decoded = decompressed.decode() assert str(decoded) == message
def test_decode_graphical_file1(): with open("tests/graphical/files/qr.png", "rb") as f: qr = f.read() message = "tests/graphical/files/qr_encoded.png" graphical = Ralgo(message).graphical() output = Ralgo(graphical.decode()).decode() assert bytes(output) == qr
def test_decode_graphical_file2(): with open("tests/graphical/files/file.txt", "rb") as f: file = f.read() message = "tests/graphical/files/file_encoded.png" graphical = Ralgo(message).graphical() output = Ralgo(graphical.decode()).decode() assert bytes(output) == file
def test_convert_file(): with open("tests/bytes/file.txt", "rb") as f: message = f.read() encoded = Ralgo(message).encode() decoded = encoded.decode() print(type(decoded.statement), decoded.statement) print(message) assert bytes(decoded) == message
def test_graphical_full_op(): message = fake.text() encoded = Ralgo(message).encode() graphical = encoded.graphical().encode() arr = graphical.to_bytes() decoded_graphical = Ralgo(arr).graphical().decode() decoded = Ralgo(decoded_graphical).decode() assert str(decoded) == message
def test_graphical_full_op_file2(): path = f"tests/graphical/tmp/{fake.pyint()}.png" with open("tests/graphical/files/file.txt", "rb") as f: message = f.read() Ralgo(message).encode().graphical().encode().save(path) output = Ralgo(Ralgo(path).graphical().decode()).decode() assert bytes(output) == message os.remove(path)
def test_encode_graphical_save1(): message = "Salut" path = f"tests/graphical/tmp/{fake.pyint()}.png" encoded = Ralgo(message).encode().graphical().encode() encoded.save(path) img = Image.open(path) assert img.size == (17, 17) os.remove(path)
def test_encode_graphical_bytes2(): message = fake.text() encoded = Ralgo(message).encode() graphical = encoded.graphical().encode() arr = graphical.to_bytes() img = Image.open(BytesIO(arr)) assert img.size == ( math.ceil(math.sqrt(len(encoded))), math.ceil(math.sqrt(len(encoded))), )
def test_encode_chars3(): message = fake.text() chars = ("-", "—") encoded = Ralgo(message).encode(chars=chars) assert contains_only(str(encoded), chars)
def test_encode_depth2(): message = "Salut" try: _ = Ralgo(message).encode(depth=1) assert False except DepthError as e: assert "Given depth is too low" == e.message
def test_encode_bits2(): message = "Salut" try: _ = Ralgo(message).encode(depth=7, bits=1) assert False except BitsError as e: assert "Given bits is too low" == e.message
def test_decompress_basic1(): message = "57{15}17162717211{12}112416172725121112271627133125181716242116111{14}17161726111511161" decoded = Ralgo(message).decompress() assert ( str(decoded) == ".....,,,,,,,...............,.......,......,,.......,.......,,.,............,.,,....,......,.......,,.......,,.....,..,.,..,,.......,......,,.......,...,,,.,,.....,........,.......,......,,....,,.,......,.,..............,.......,......,.......,,......,.,.....,.,......," )
def test_decompress_fails(): message = "*" try: _ = Ralgo(message).decompress() assert False except DecompressParseError as e: assert "Failed on parsing given compressed text" == e.message
def test_decode_depth2(): message = ".,,,,,,,...............,.......,......,,.......,......,.,....,.........,.,,....,......,,.......,.......,,....,.........,.......,.......,.......,.......,,,.,..,........,.......,......,.......,,.......,,,.............,.......,.......,....,,.,...,,,.,,..............,.......,......,.......,,.......,,....,.........,.......,.......,.......,.......,,,.,.....,.,..,,.......,.......,.......,......,.,.....,........,.......,......,,.......,.......,,.......,......," try: _ = Ralgo(message).decode() assert False except DecodeError as e: assert "Failed to decode one layer" == e.message
def test_encode_graphical_save2(): message = fake.text() path = f"tests/graphical/tmp/{fake.pyint()}.png" encoded = Ralgo(message).encode() graphical = encoded.graphical().encode() graphical.save(path) img = Image.open(path) assert img.size == ( math.ceil(math.sqrt(len(encoded))), math.ceil(math.sqrt(len(encoded))), ) os.remove(path)
def test_decode_bits1(): message = ".......,,,,,,,,,...................,.........,.........,........,,........,.,......,...........,.........,........,..........,.....,,,.,,..................,.........,........,.........,,.........,,....,.............,.........,........,,.........,........,.,............,.,..,,.........,........,,.........,.........,,.......,..........,.........,.........,.........,.........,,,....,............,...,,....,........,,......,,.,.........,,..,....,.,........," decoded = Ralgo(message).decode(depth=7, bits=9) print(decoded, type(decoded), decoded.statement, type(decoded.statement)) assert str(decoded) == "Salut"
def test_encode_chars4(): message = fake.text() chars = ("1", "1") try: _ = Ralgo(message).encode(chars=chars) assert False except CharsError as e: assert "Given chars must not be the same" == e.message