From 7870d26e6951d07cda37ecdc2a7d0b6b98635248 Mon Sep 17 00:00:00 2001 From: Thanos Tsiamis Date: Fri, 14 Nov 2025 20:34:49 +0200 Subject: [PATCH] feat: Add Git hooks for pre-commit and pre-push testing --- .githooks/pre-commit | 18 ++++++++++++++++++ .githooks/pre-push | 17 +++++++++++++++++ tests/test_algorithms.py | 17 +++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100755 .githooks/pre-commit create mode 100755 .githooks/pre-push diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..8412a6d --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,18 @@ +#!/bin/sh +echo "🔍 Running tests before commit..." + +# activate venv if needed +if [ -f ".venv/bin/activate" ]; then + . .venv/bin/activate +fi + +pytest tests +STATUS=$? + +if [ $STATUS -ne 0 ]; then + echo "❌ Tests failed. Commit aborted." + exit 1 +fi + +echo "✔️ Tests passed. Proceeding with commit." +exit 0 \ No newline at end of file diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 0000000..7e3b3ab --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,17 @@ +#!/bin/sh +echo "🚀 Running tests before push..." + +if [ -f ".venv/bin/activate" ]; then + . .venv/bin/activate +fi + +pytest +STATUS=$? + +if [ $STATUS -ne 0 ]; then + echo "❌ Tests failed. Push aborted." + exit 1 +fi + +echo "✔️ Tests passed. Proceeding with push." +exit 0 \ No newline at end of file diff --git a/tests/test_algorithms.py b/tests/test_algorithms.py index 697cf4e..550e811 100644 --- a/tests/test_algorithms.py +++ b/tests/test_algorithms.py @@ -1,3 +1,4 @@ +import nltk import pytest from tests import df1, df2 @@ -23,7 +24,23 @@ def test_coma(): # Assume the Schema and instance should provide different results assert matches_coma_matcher_schema != matches_coma_matcher_instances +def _has_nltk_data(): + # Check only what this test actually needs + needed = [ + "tokenizers/punkt_tab/english/", # tokenizer + "corpora/wordnet", # wordnet + "corpora/omw-1.4", # multilingual wordnet + "corpora/stopwords", # stopwords + ] + for res in needed: + try: + nltk.data.find(res) + except LookupError: + return False + return True + +@pytest.mark.skipif(not _has_nltk_data(), reason="Required NLTK data not installed") def test_cupid(): # Test the CUPID matcher cu_matcher = Cupid()