plint

French poetry validator (local mirror of https://gitlab.com/a3nm/plint)
git clone https://a3nm.net/git/plint/
Log | Files | Refs | README

test_counts.py (632B)


      1 import unittest
      2 
      3 import plint.pattern
      4 from plint import verse, template
      5 
      6 
      7 class Counts(unittest.TestCase):
      8 
      9     def runCount(self, text, limit=12, hemistiches=None):
     10         v = verse.Verse(text, template.Template(), plint.pattern.Pattern(str(limit), hemistiches=hemistiches))
     11         v.parse()
     12         return v.possible
     13 
     14     def getWeight(self, align):
     15         return sum([x.weight or 0 for x in align])
     16 
     17     def achievesPossibility(self, aligns, target):
     18         for align in aligns:
     19             if self.getWeight(align) == target:
     20                 return True
     21         return False
     22 
     23 
     24 if __name__ == "__main__":
     25     unittest.main()