<s> import unittest <EOL> from searchtests . test_matcher import _TestSearchTest <EOL> class TestTestSorter ( _TestSearchTest , unittest . TestCase ) : <EOL> def test_exact_match_is_better_than_partial ( self ) : <EOL> values = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . _matches_in_order ( '<STR_LIT>' , values ) <EOL> def _matches_in_order ( self , match_text , matches ) : <EOL> matches = [ self . _match ( match_text , name = name ) for name in matches ] <EOL> for i in range ( <NUM_LIT:1> , len ( matches ) ) : <EOL> self . _assert_is_greater ( matches [ i ] , matches [ i - <NUM_LIT:1> ] ) <EOL> def test_all_matches_is_better_than_some ( self ) : <EOL> self . _matches_in_order ( <EOL> '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:bar>' ] ) <EOL> def test_more_matches_is_better_than_some_in_name ( self ) : <EOL> all_matches_in_docs = self . _match ( '<STR_LIT>' , doc = '<STR_LIT>' ) <EOL> some_match_in_name = self . _match ( '<STR_LIT>' , name = '<STR_LIT:foo>' ) <EOL> self . _assert_is_greater ( some_match_in_name , all_matches_in_docs ) <EOL> def test_more_matches_is_better_than_some_in_tags ( self ) : <EOL> some_match_in_tag = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT:bar>' ] ) <EOL> all_matches_in_tags = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT:foo>' , '<STR_LIT:bar>' ] ) <EOL> self . _assert_is_greater ( some_match_in_tag , all_matches_in_tags ) <EOL> def test_same_pattern_matches_do_not_raise_priority ( self ) : <EOL> all_matches_in_name = self . _match ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> some_match_in_doc = self . _match ( <EOL> '<STR_LIT>' , doc = '<STR_LIT>' ) <EOL> self . _assert_is_greater ( some_match_in_doc , all_matches_in_name ) <EOL> def test_name_is_better_than_doc ( self ) : <EOL> name_match = self . _match ( '<STR_LIT:name>' , name = '<STR_LIT:name>' ) <EOL> doc_match = self . _match ( '<STR_LIT>' , doc = '<STR_LIT>' ) <EOL> self . _assert_is_greater ( doc_match , name_match ) <EOL> def test_name_is_better_than_tag ( self ) : <EOL> name_match = self . _match ( '<STR_LIT:name>' , name = '<STR_LIT:name>' ) <EOL> tag_match = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT>' ] ) <EOL> self . _assert_is_greater ( tag_match , name_match ) <EOL> def test_tag_is_better_than_doc ( self ) : <EOL> tag_match = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT>' ] ) <EOL> doc_match = self . _match ( '<STR_LIT>' , doc = '<STR_LIT>' ) <EOL> self . _assert_is_greater ( doc_match , tag_match ) <EOL> def test_tags_order ( self ) : <EOL> tag1_match = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT>' ] ) <EOL> tag2_match = self . _match ( '<STR_LIT>' , tags = [ '<STR_LIT>' ] ) <EOL> self . _assert_is_greater ( tag2_match , tag1_match ) <EOL> def _assert_is_greater ( self , greater , smaller ) : <EOL> self . assertTrue ( <EOL> greater > smaller , msg = '<STR_LIT>' % ( greater , smaller ) ) <EOL> self . assertFalse ( smaller > greater ) <EOL> self . assertFalse ( greater == smaller ) </s>
