<s> import unittest <EOL> import string <EOL> import sys <EOL> import os <EOL> import tempfile <EOL> import zipfile <EOL> import shutil <EOL> import copy <EOL> from pynhost import ruleparser <EOL> from pynhost import matching <EOL> class TestRuleMatching ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> pass <EOL> def test_overflow1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT:hello>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_overflow2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_basic1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_basic2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_basic3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT:hello>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' ] ) <EOL> def test_basic4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_basic5 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_basic6 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_basic7 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_basic8 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_basic9 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_list1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT:hello>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' ] ) <EOL> def test_list2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_list3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_list4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_list5 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_list6 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_list7 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_list8 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_num0 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:4>' ] ) <EOL> def test_num1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT:4>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:4>' ] ) <EOL> def test_num2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_num3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT:e>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_num4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_num5 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_num6 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_num10 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_num7 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_num8 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_num9 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:2>' ] ) <EOL> def test_any1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_any2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_any3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertTrue ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_any4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_any5 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_any6 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_any7 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_any8 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_any9 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_any10 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_any11 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . remaining_words ) , [ '<STR_LIT>' ] ) <EOL> def test_homophone1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_homophone2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_homophone3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_homophone_not_in_list1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_homophone_not_in_list2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_mix1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_mix2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> def test_mix3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_mix4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_mix5 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertEqual ( list ( matching . get_rule_match ( rule , words ) . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_end1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' ] ) <EOL> def test_end2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertIsNone ( rule_match ) <EOL> def test_wildcard1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT:hello>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' ] ) <EOL> def test_wildcard2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_repetition1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_repetition2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_repetition3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT:hello>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_repetition4 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT:test>' ] ) <EOL> def test_num_range1 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_num_range2 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> rule_match = matching . get_rule_match ( rule , words ) <EOL> self . assertEqual ( list ( rule_match . matched_words ) , [ '<STR_LIT>' ] ) <EOL> def test_num_range3 ( self ) : <EOL> rule = ruleparser . Rule ( '<STR_LIT>' ) <EOL> words = '<STR_LIT>' . split ( ) <EOL> self . assertIsNone ( matching . get_rule_match ( rule , words ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
