Skip to content

Commit

Permalink
Creating combinatory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Sep 3, 2024
1 parent 41039bd commit 1c9e66c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/test_cli/test_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def test_corpus_dump_not_found(self):
)

@nottest
def make_test(self, tests, context):
def make_test(self, tests, context):
with self.app.app_context():
with self.runner.isolated_filesystem() as f:
cur_dir = str(f)
Expand Down
9 changes: 0 additions & 9 deletions tests/test_models/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,6 @@ def test_similar_lemma_double_change(self):
)
self.assertCountEqual(cr4.changed, ["lemma", "POS"])

def test_filter_allowed_lemma(self):
""" Ensure only similar features are fixed """
self.load_fixtures()
with self.assertRaises(WordToken.ValidityError):
token, change_record = WordToken.update(
user_id=1,
token_id=1, corpus_id=1,
lemma="#", morph="smn", POS="u")

# faire pareil mais avec les filtres de cochés


Expand Down
48 changes: 48 additions & 0 deletions tests/test_models/test_regex_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from .test_record import SimilarityFixtures
from app.models import ChangeRecord, WordToken, Corpus, ControlLists, ControlListsUser, CorpusUser, Column
from .base import TestModels
import copy
from itertools import combinations


class TestFilters(TestModels):

def load_fixtures(self):
for fixture in SimilarityFixtures:
self.db.session.add(copy.deepcopy(fixture))
self.db.session.commit()

def test_filter_allowed_lemma(self):
""" Ensure that when no filters are registered, everything works as intended """
self.load_fixtures()
with self.assertRaises(WordToken.ValidityError):
token, change_record = WordToken.update(
user_id=1,
token_id=1, corpus_id=1,
lemma="#", morph="smn", POS="u")

def test_combinatory_regex(self):
self.load_fixtures()
tests = [
("celui", None),
("#", "filter_punct"),
("...", "filter_punct"),
("7", "filter_numeral"),
("75", "filter_numeral")
]
situations = ["filter_punct", "filter_numeral"]
cl = ControlLists.query.get(1)
token = WordToken.query.get(1)
corpus = Corpus.query.get(1)
for i in range(len(situations)+1):
for combi in combinations(situations, i):
for filtre in situations:
setattr(cl, filtre, False)
for filtre in combi:
setattr(cl, filtre, True)
self.db.session.add(cl)
self.db.session.commit()
self.db.session.refresh(token)
self.db.session.refresh(corpus)
for category, filtre in tests:
print(WordToken.is_valid(lemma=category, POS=token.POS, morph=token.morph, corpus=corpus)["lemma"])

0 comments on commit 1c9e66c

Please sign in to comment.