Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
Expand All @@ -49,6 +51,8 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "multibase-spec"]
path = multibase-spec
url = https://github.com/multiformats/multibase
1 change: 1 addition & 0 deletions multibase-spec
Submodule multibase-spec added at d7406c
46 changes: 46 additions & 0 deletions tests/test_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import csv
from pathlib import Path

from multibase.multibase import ENCODINGS


def test_spec_encodings():
spec_path = Path(__file__).parent.parent / "multibase-spec" / "multibase.csv"
if not spec_path.exists():
# Fallback if the submodule is not checked out locally
return

spec_encodings = {}
with open(spec_path, encoding="utf-8") as f:
reader = csv.reader(f)
next(reader) # skip header
for row in reader:
if not row:
continue
row = [col.strip() for col in row]
if len(row) >= 5:
unicode_str, character, encoding_name, description, status = row[:5]
if encoding_name == "none":
continue
spec_encodings[encoding_name] = {
"character": character,
"status": status,
}

supported_names = set()
for enc in ENCODINGS:
if enc.encoding == "identity":
continue

assert enc.encoding in spec_encodings, f"Encoding '{enc.encoding}' not in spec"
spec_char = spec_encodings[enc.encoding]["character"]

assert enc.code.decode("utf-8") == spec_char, (
f"Prefix mismatch for '{enc.encoding}': expected '{spec_char}', got '{enc.code.decode('utf-8')}'"
)

supported_names.add(enc.encoding)

for name, data in spec_encodings.items():
if data["status"] == "final":
assert name in supported_names, f"Missing final encoding from spec: '{name}'"
Loading