From f8921064dc5d74f4460208b96e0fd3b2f607179e Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Sun, 31 May 2026 11:11:57 +0300 Subject: [PATCH] python-maxminddb: extend test.sh past the import smoke check 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 --- lang/python/python-maxminddb/test.sh | 56 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) mode change 100644 => 100755 lang/python/python-maxminddb/test.sh diff --git a/lang/python/python-maxminddb/test.sh b/lang/python/python-maxminddb/test.sh old mode 100644 new mode 100755 index e0a5b9990f..e6324d0f3f --- a/lang/python/python-maxminddb/test.sh +++ b/lang/python/python-maxminddb/test.sh @@ -2,12 +2,56 @@ [ "$1" = python3-maxminddb ] || exit 0 -python3 - << 'EOF' -import maxminddb -from maxminddb import open_database, InvalidDatabaseError +python3 - "$2" << 'EOF' +import sys +import tempfile -assert callable(open_database) -assert issubclass(InvalidDatabaseError, Exception) +import maxminddb +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) + +# 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