from base64 import b64decode from dataclasses import dataclass from textwrap import dedent import pytest from .identicon import Identicon @dataclass class ReferenceIcon: fingerprint: bytes icon: str REFERENCE_ICONS = [ ReferenceIcon( bytearray.fromhex(''.join('b7:a3:e2:ce:09:06:ad:39:c8:1d:ad:b5:95:48:8f:99'.split(':'))), dedent('''\ +-----------------+ | | | | | . | | .o * . | | ...E +S . | |...++ o . . | |..+oo. o | | o o.. . . | | o=.. | +-----------------+''' ) ), ReferenceIcon( b64decode('sX58LC41tVlsctG1+H5PrkbMDfG374yghEg96KlnFZA=='), dedent('''\ +-----------------+ | . .o| | E + o| | .. o = | | o.o o B o| | o S. . X +o| | o +.+o.o =..| | +.o.=.+. .+| | .o .+ + ..=+| | .o .o .oo=| +-----------------+''' ) ), ReferenceIcon( bytearray.fromhex(''.join('9b:cf:42:fd:25:ff:ce:83:e9:e0:f1:d4:10:c3:ae:a8'.split(':'))), dedent('''\ +-----------------+ | | | . | | + | | . o | | S. o | | .oo o + | | .o. = =o. | | oo. *o.o | | E .o..o o=| +-----------------+''' ) ), ReferenceIcon( b64decode('5/WozN6loc0G8DxxrJhV8+aG/6Dvz1/gTBVipWU9nb0='), dedent('''\ +-----------------+ | o.==| | + =o=| | o + +| | . o o oE | | SB.+.+o | | oo*..*o. | | .ooo* .| | o *.=.o.| | .*.*ooo*| +-----------------+''' ) ) ] @pytest.mark.parametrize('reference', REFERENCE_ICONS) def test_identicon(reference): icon = Identicon(reference.fingerprint) icon.calculate() assert str(icon) == reference.icon