From b8bad9d8a2198c4ca0ef70edfb39279fec411c4e Mon Sep 17 00:00:00 2001 From: sumanjeet0012 Date: Sun, 12 Jul 2026 12:31:46 +0530 Subject: [PATCH] test: add spec compliance validation against multibase.csv --- .github/workflows/tox.yml | 4 ++++ .gitmodules | 3 +++ multibase-spec | 1 + tests/test_spec.py | 46 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 .gitmodules create mode 160000 multibase-spec create mode 100644 tests/test_spec.py diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 3b4a189..621c8ab 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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 }} @@ -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: diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..56de731 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "multibase-spec"] + path = multibase-spec + url = https://github.com/multiformats/multibase diff --git a/multibase-spec b/multibase-spec new file mode 160000 index 0000000..d7406cd --- /dev/null +++ b/multibase-spec @@ -0,0 +1 @@ +Subproject commit d7406cdea189b82a0b3937f5737b440f5fa92f92 diff --git a/tests/test_spec.py b/tests/test_spec.py new file mode 100644 index 0000000..ec96994 --- /dev/null +++ b/tests/test_spec.py @@ -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}'"