Skip to content

Commit

Permalink
reduce expected deprecation warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cmacdonald committed Sep 5, 2024
1 parent 7a3f159 commit 09d11d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
9 changes: 8 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
import shutil
import pyterrier as pt
import pytest

class BaseTestCase(unittest.TestCase):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -37,5 +38,11 @@ def tearDown(self):
except:
pass



def ensure_deprecated(func):
def wrapper(*args):
with pytest.deprecated_call():
return func(*args)
return wrapper

parallel_test = unittest.skipIf(os.environ.get("PARALLEL_TESTING") is None, "Parallel test disabled, enable with PARALLEL_TESTING=1")
13 changes: 11 additions & 2 deletions tests/test_br.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pyterrier as pt
import os
import unittest
from .base import BaseTestCase
from .base import BaseTestCase, ensure_deprecated
import warnings

def parse_res_file(filename):
Expand Down Expand Up @@ -261,7 +261,11 @@ def test_terrier_retrieve_alias(self):
indexloc = self.here + "/fixtures/index/data.properties"
# docid 50 == docno 51
input_set = pd.DataFrame([["q1", "light", 50]], columns=["qid", "query", "docid"])
for name, retr in [ ("TerrierRetrieve", pt.TerrierRetrieve(indexloc)), ("BatchRetrieve", pt.BatchRetrieve(indexloc)) ]:

@ensure_deprecated
def do_test(name, retr):
# delay instantiation to here
retr = retr(indexloc)
self.subTest(name)
# this test the implementation of __call__() redirecting to transform()
for result in [retr.transform(input_set), retr(input_set)]:
Expand All @@ -276,6 +280,11 @@ def test_terrier_retrieve_alias(self):
self.assertEqual("51", row["docno"])
self.assertEqual(pt.model.FIRST_RANK, row["rank"])
self.assertTrue(row["score"] > 0)

for name, retr in [ ("TerrierRetrieve", pt.TerrierRetrieve), ("BatchRetrieve", pt.BatchRetrieve) ]:
do_test(name, retr)




if __name__ == "__main__":
Expand Down
7 changes: 3 additions & 4 deletions tests/test_dfindex.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import pyterrier as pt

import unittest
import tempfile
import shutil
import os
from .base import TempDirTestCase, ensure_deprecated

from .base import TempDirTestCase

class TestDFIndexer(TempDirTestCase):


@ensure_deprecated
def _create_index(self, type, dfText, dfMeta):
print("Writing index type "+str(type)+" to " + self.test_dir)
pd_indexer = pt.DFIndexer(self.test_dir, type=type)
Expand Down Expand Up @@ -112,6 +110,7 @@ def test_checkjavaDocIteratr(self):
self.assertIsNotNone(jIter1.next())
self.assertFalse(jIter1.hasNext())

@ensure_deprecated
def test_badinvocation(self):
import pandas as pd
df_docids = pd.DataFrame([['d1', 'this is a doc']], columns=['body', 'doc_id'])
Expand Down
16 changes: 11 additions & 5 deletions tests/test_fbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import unittest
import os
import pyterrier as pt
from .base import BaseTestCase
from .base import BaseTestCase, ensure_deprecated
import warnings

class TestFeaturesBatchRetrieve(BaseTestCase):
Expand Down Expand Up @@ -116,10 +116,9 @@ def test_fbr(self):
JIR = pt.java.autoclass('org.terrier.querying.IndexRef')
indexref = JIR.of(self.here + "/fixtures/index/data.properties")

for name, retr in [
("FeaturesRetriever", pt.terrier.FeaturesRetriever(indexref, ["WMODEL:PL2"], wmodel="DPH")),
("FeaturesBatchRetrieve", pt.FeaturesBatchRetrieve(indexref, ["WMODEL:PL2"], wmodel="DPH"))
]:

def do_test(name, retr):
retr = retr(indexref, ["WMODEL:PL2"], wmodel="DPH")
self.subTest(name)
input = pd.DataFrame([["1", "Stability"]], columns=['qid', 'query'])
result = retr.transform(input)
Expand All @@ -137,6 +136,13 @@ def test_fbr(self):
retrBasic = pt.terrier.Retriever(indexref)
if "matching" in retrBasic.controls:
self.assertNotEqual(retrBasic.controls["matching"], "FatFeaturedScoringMatching,org.terrier.matching.daat.FatFull")

@ensure_deprecated
def do_test_deprecated(name, retr):
do_test(name, retr)

do_test("FeaturesRetriever", pt.terrier.FeaturesRetriever)
do_test_deprecated("FeaturesBatchRetrieve", pt.FeaturesBatchRetrieve)

def test_fbr_query_toks(self):
indexloc = self.here + "/fixtures/index/data.properties"
Expand Down

0 comments on commit 09d11d6

Please sign in to comment.