python-maxminddb: extend test.sh past the import smoke check
authorAlexandru Ardelean <redacted>
Sun, 31 May 2026 08:11:57 +0000 (11:11 +0300)
committerAlexandru Ardelean <redacted>
Mon, 1 Jun 2026 05:10:59 +0000 (08:10 +0300)
Previous test.sh only confirmed the import smoke check. Add a $2
version check, assert MODE_* constants are distinct ints, and exercise
the loader's error paths (missing file, non-MMDB temp file).

Signed-off-by: Alexandru Ardelean <redacted>
lang/python/python-maxminddb/test.sh [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index e0a5b99..e6324d0
@@ -2,12 +2,56 @@
 
 [ "$1" = python3-maxminddb ] || exit 0
 
-python3 - << 'EOF'
+python3 - "$2" << 'EOF'
+import sys
+import tempfile
+
 import maxminddb
-from maxminddb import open_database, InvalidDatabaseError
+from maxminddb import (
+    MODE_AUTO,
+    MODE_FD,
+    MODE_FILE,
+    MODE_MEMORY,
+    MODE_MMAP,
+    MODE_MMAP_EXT,
+    InvalidDatabaseError,
+    open_database,
+)
+
+expected = sys.argv[1]
+if maxminddb.__version__ != expected:
+    print(f"version mismatch: got {maxminddb.__version__}, expected {expected}")
+    sys.exit(1)
+
+# All MODE_* constants documented in the README must be distinct ints; this
+# proves the public import surface still re-exports the loader modes that
+# open_database accepts.
+modes = {MODE_AUTO, MODE_FD, MODE_FILE, MODE_MEMORY, MODE_MMAP, MODE_MMAP_EXT}
+assert len(modes) == 6, f"MODE_* constants are not distinct: {modes}"
+assert all(isinstance(m, int) for m in modes)
+
+# open_database on a path that does not exist must raise FileNotFoundError;
+# this proves the loader actually reaches the filesystem.
+try:
+    open_database("/nonexistent.mmdb")
+except FileNotFoundError:
+    pass
+else:
+    print("open_database accepted a missing path")
+    sys.exit(1)
 
-assert callable(open_database)
-assert issubclass(InvalidDatabaseError, Exception)
+# A non-MMDB file must raise InvalidDatabaseError; this exercises the metadata
+# parser and confirms the public exception type is re-exported.
+with tempfile.NamedTemporaryFile(suffix=".mmdb") as f:
+    f.write(b"not a maxmind db")
+    f.flush()
+    try:
+        open_database(f.name)
+    except InvalidDatabaseError:
+        pass
+    else:
+        print("open_database accepted a non-MMDB file")
+        sys.exit(1)
 
 print("python3-maxminddb OK")
-EOF
\ No newline at end of file
+EOF
git clone https://git.99rst.org/PROJECT