<s> from __future__ import absolute_import <EOL> from behave . tag_matcher import * <EOL> from mock import Mock <EOL> from unittest import TestCase <EOL> import warnings <EOL> class Traits4ActiveTagMatcher ( object ) : <EOL> TagMatcher = ActiveTagMatcher <EOL> value_provider = { <EOL> "<STR_LIT:foo>" : "<STR_LIT>" , <EOL> "<STR_LIT:bar>" : "<STR_LIT>" , <EOL> } <EOL> category1_enabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category1_disabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category1_disabled_tag2 = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category1_similar_tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category2_enabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> category2_disabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> category2_similar_tag = TagMatcher . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> unknown_category_tag = TagMatcher . make_category_tag ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> category1_not_enabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> category1_not_enabled_tag2 = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> category1_not_disabled_tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> category1_negated_similar_tag1 = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> active_tags1 = [ <EOL> category1_enabled_tag , category1_disabled_tag , category1_similar_tag , <EOL> category1_not_enabled_tag , category1_not_enabled_tag2 , <EOL> ] <EOL> active_tags2 = [ <EOL> category2_enabled_tag , category2_disabled_tag , category2_similar_tag , <EOL> ] <EOL> active_tags = active_tags1 + active_tags2 <EOL> class TestActiveTagMatcher1 ( TestCase ) : <EOL> TagMatcher = ActiveTagMatcher <EOL> traits = Traits4ActiveTagMatcher <EOL> @ classmethod <EOL> def make_tag_matcher ( cls ) : <EOL> tag_matcher = cls . TagMatcher ( cls . traits . value_provider ) <EOL> return tag_matcher <EOL> def setUp ( self ) : <EOL> self . tag_matcher = self . make_tag_matcher ( ) <EOL> def test_select_active_tags__basics ( self ) : <EOL> active_tag = "<STR_LIT>" <EOL> tags = [ "<STR_LIT:foo>" , active_tag , "<STR_LIT:bar>" ] <EOL> selected = list ( self . tag_matcher . select_active_tags ( tags ) ) <EOL> self . assertEqual ( len ( selected ) , <NUM_LIT:1> ) <EOL> selected_tag , selected_match = selected [ <NUM_LIT:0> ] <EOL> self . assertEqual ( selected_tag , active_tag ) <EOL> def test_select_active_tags__matches_tag_parts ( self ) : <EOL> tags = [ "<STR_LIT>" ] <EOL> selected = list ( self . tag_matcher . select_active_tags ( tags ) ) <EOL> self . assertEqual ( len ( selected ) , <NUM_LIT:1> ) <EOL> selected_tag , selected_match = selected [ <NUM_LIT:0> ] <EOL> self . assertEqual ( selected_match . group ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertEqual ( selected_match . group ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> self . assertEqual ( selected_match . group ( "<STR_LIT:value>" ) , "<STR_LIT>" ) <EOL> def test_select_active_tags__finds_tag_with_any_valid_tag_prefix ( self ) : <EOL> TagMatcher = self . TagMatcher <EOL> for tag_prefix in TagMatcher . tag_prefixes : <EOL> tag = TagMatcher . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" , tag_prefix ) <EOL> tags = [ tag ] <EOL> selected = self . tag_matcher . select_active_tags ( tags ) <EOL> selected = list ( selected ) <EOL> self . assertEqual ( len ( selected ) , <NUM_LIT:1> ) <EOL> selected_tag0 = selected [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( selected_tag0 , tag ) <EOL> self . assertTrue ( selected_tag0 . startswith ( tag_prefix ) ) <EOL> def test_select_active_tags__ignores_invalid_active_tags ( self ) : <EOL> invalid_active_tags = [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] <EOL> for invalid_tag , case in invalid_active_tags : <EOL> tags = [ invalid_tag ] <EOL> selected = self . tag_matcher . select_active_tags ( tags ) <EOL> selected = list ( selected ) <EOL> self . assertEqual ( len ( selected ) , <NUM_LIT:0> , case ) <EOL> def test_select_active_tags__with_two_tags ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( "<STR_LIT>" , <EOL> [ traits . category1_enabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , <EOL> [ traits . category1_enabled_tag , "<STR_LIT:foo>" ] ) , <EOL> ( "<STR_LIT>" , <EOL> [ traits . category1_disabled_tag , "<STR_LIT:foo>" ] ) , <EOL> ( "<STR_LIT>" , <EOL> [ traits . category1_not_enabled_tag , "<STR_LIT:foo>" ] ) , <EOL> ] <EOL> for case , tags in test_patterns : <EOL> selected = self . tag_matcher . select_active_tags ( tags ) <EOL> selected = list ( selected ) <EOL> self . assertTrue ( len ( selected ) >= <NUM_LIT:1> , case ) <EOL> def test_should_exclude_with__returns_false_with_enabled_tag ( self ) : <EOL> traits = self . traits <EOL> tags1 = [ traits . category1_enabled_tag ] <EOL> tags2 = [ traits . category2_enabled_tag ] <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags1 ) ) <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags2 ) ) <EOL> def test_should_exclude_with__returns_false_with_disabled_tag_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_enabled_tag , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag , traits . category1_enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_enabled_tag , traits . category1_disabled_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> enabled = True <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( not enabled , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag ( self ) : <EOL> traits = self . traits <EOL> tags = [ traits . category1_disabled_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_disabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_disabled_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_tag ( self ) : <EOL> traits = self . traits <EOL> tags = [ traits . category1_similar_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_similar_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_false_without_category_tag ( self ) : <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_false_with_unknown_category_tag ( self ) : <EOL> """<STR_LIT>""" <EOL> traits = self . traits <EOL> tags = [ traits . unknown_category_tag ] <EOL> self . assertEqual ( "<STR_LIT>" , traits . unknown_category_tag ) <EOL> self . assertEqual ( None , self . tag_matcher . value_provider . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__combinations_of_2_categories ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_enabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , False , <EOL> [ traits . category1_enabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_not_enabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_not_enabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_not_disabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , False , <EOL> [ traits . category1_not_disabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . unknown_category_tag ] ) , <EOL> ( "<STR_LIT>" , False , <EOL> [ traits . category1_enabled_tag , traits . unknown_category_tag ] ) , <EOL> ] <EOL> for case , expected , tags in test_patterns : <EOL> actual_result = self . tag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( expected , actual_result , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_run_with__negates_result_of_should_exclude_with ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> result1 = self . tag_matcher . should_run_with ( tags ) <EOL> result2 = self . tag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( result1 , not result2 , "<STR_LIT>" % ( case , tags ) ) <EOL> self . assertEqual ( not result1 , result2 , "<STR_LIT>" % ( case , tags ) ) <EOL> class TestPredicateTagMatcher ( TestCase ) : <EOL> def test_exclude_with__mechanics ( self ) : <EOL> predicate_function_blueprint = lambda tags : False <EOL> predicate_function = Mock ( predicate_function_blueprint ) <EOL> predicate_function . return_value = True <EOL> tag_matcher = PredicateTagMatcher ( predicate_function ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher . should_exclude_with ( tags ) ) <EOL> predicate_function . assert_called_once_with ( tags ) <EOL> self . assertEqual ( True , predicate_function ( tags ) ) <EOL> def test_should_exclude_with__returns_true_when_predicate_is_true ( self ) : <EOL> predicate_always_true = lambda tags : True <EOL> tag_matcher1 = PredicateTagMatcher ( predicate_always_true ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher1 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( True , predicate_always_true ( tags ) ) <EOL> def test_should_exclude_with__returns_true_when_predicate_is_true2 ( self ) : <EOL> def predicate_contains_foo ( tags ) : <EOL> return any ( x == "<STR_LIT:foo>" for x in tags ) <EOL> tag_matcher2 = PredicateTagMatcher ( predicate_contains_foo ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher2 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( True , predicate_contains_foo ( tags ) ) <EOL> def test_should_exclude_with__returns_false_when_predicate_is_false ( self ) : <EOL> predicate_always_false = lambda tags : False <EOL> tag_matcher1 = PredicateTagMatcher ( predicate_always_false ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( False , tag_matcher1 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( False , predicate_always_false ( tags ) ) <EOL> class TestPredicateTagMatcher ( TestCase ) : <EOL> def test_exclude_with__mechanics ( self ) : <EOL> predicate_function_blueprint = lambda tags : False <EOL> predicate_function = Mock ( predicate_function_blueprint ) <EOL> predicate_function . return_value = True <EOL> tag_matcher = PredicateTagMatcher ( predicate_function ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher . should_exclude_with ( tags ) ) <EOL> predicate_function . assert_called_once_with ( tags ) <EOL> self . assertEqual ( True , predicate_function ( tags ) ) <EOL> def test_should_exclude_with__returns_true_when_predicate_is_true ( self ) : <EOL> predicate_always_true = lambda tags : True <EOL> tag_matcher1 = PredicateTagMatcher ( predicate_always_true ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher1 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( True , predicate_always_true ( tags ) ) <EOL> def test_should_exclude_with__returns_true_when_predicate_is_true2 ( self ) : <EOL> def predicate_contains_foo ( tags ) : <EOL> return any ( x == "<STR_LIT:foo>" for x in tags ) <EOL> tag_matcher2 = PredicateTagMatcher ( predicate_contains_foo ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( True , tag_matcher2 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( True , predicate_contains_foo ( tags ) ) <EOL> def test_should_exclude_with__returns_false_when_predicate_is_false ( self ) : <EOL> predicate_always_false = lambda tags : False <EOL> tag_matcher1 = PredicateTagMatcher ( predicate_always_false ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] <EOL> self . assertEqual ( False , tag_matcher1 . should_exclude_with ( tags ) ) <EOL> self . assertEqual ( False , predicate_always_false ( tags ) ) <EOL> class TestCompositeTagMatcher ( TestCase ) : <EOL> @ staticmethod <EOL> def count_tag_matcher_with_result ( tag_matchers , tags , result_value ) : <EOL> count = <NUM_LIT:0> <EOL> for tag_matcher in tag_matchers : <EOL> current_result = tag_matcher . should_exclude_with ( tags ) <EOL> if current_result == result_value : <EOL> count += <NUM_LIT:1> <EOL> return count <EOL> def setUp ( self ) : <EOL> predicate_false = lambda tags : False <EOL> predicate_contains_foo = lambda tags : any ( x == "<STR_LIT:foo>" for x in tags ) <EOL> self . tag_matcher_false = PredicateTagMatcher ( predicate_false ) <EOL> self . tag_matcher_foo = PredicateTagMatcher ( predicate_contains_foo ) <EOL> tag_matchers = [ <EOL> self . tag_matcher_foo , <EOL> self . tag_matcher_false <EOL> ] <EOL> self . ctag_matcher = CompositeTagMatcher ( tag_matchers ) <EOL> def test_should_exclude_with__returns_true_when_any_tag_matcher_returns_true ( self ) : <EOL> test_patterns = [ <EOL> ( "<STR_LIT>" , [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) , <EOL> ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:foo>" , "<STR_LIT:bar>" ] ) , <EOL> ] <EOL> for case , tags in test_patterns : <EOL> actual_result = self . ctag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( True , actual_result , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> actual_true_count = self . count_tag_matcher_with_result ( <EOL> self . ctag_matcher . tag_matchers , tags , True ) <EOL> self . assertEqual ( <NUM_LIT:1> , actual_true_count ) <EOL> def test_should_exclude_with__returns_false_when_no_tag_matcher_return_true ( self ) : <EOL> test_patterns = [ <EOL> ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:bar>" ] ) , <EOL> ( "<STR_LIT>" , [ "<STR_LIT>" , "<STR_LIT:bar>" ] ) , <EOL> ] <EOL> for case , tags in test_patterns : <EOL> actual_result = self . ctag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( False , actual_result , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> actual_true_count = self . count_tag_matcher_with_result ( <EOL> self . ctag_matcher . tag_matchers , tags , True ) <EOL> self . assertEqual ( <NUM_LIT:0> , actual_true_count ) <EOL> class TestOnlyWithCategoryTagMatcher ( TestCase ) : <EOL> TagMatcher = OnlyWithCategoryTagMatcher <EOL> def setUp ( self ) : <EOL> category = "<STR_LIT>" <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , DeprecationWarning ) <EOL> self . tag_matcher = OnlyWithCategoryTagMatcher ( category , "<STR_LIT>" ) <EOL> self . enabled_tag = self . TagMatcher . make_category_tag ( category , "<STR_LIT>" ) <EOL> self . similar_tag = self . TagMatcher . make_category_tag ( category , "<STR_LIT>" ) <EOL> self . other_tag = self . TagMatcher . make_category_tag ( category , "<STR_LIT>" ) <EOL> self . category = category <EOL> def test_should_exclude_with__returns_false_with_enabled_tag ( self ) : <EOL> tags = [ self . enabled_tag ] <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_false_with_enabled_tag_and_more ( self ) : <EOL> test_patterns = [ <EOL> ( [ self . enabled_tag , self . other_tag ] , "<STR_LIT>" ) , <EOL> ( [ self . other_tag , self . enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . enabled_tag , self . other_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag ( self ) : <EOL> tags = [ self . other_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag_and_more ( self ) : <EOL> test_patterns = [ <EOL> ( [ self . other_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . other_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . other_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_tag ( self ) : <EOL> tags = [ self . similar_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_and_more ( self ) : <EOL> test_patterns = [ <EOL> ( [ self . similar_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . similar_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_false_without_category_tag ( self ) : <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_run_with__negates_result_of_should_exclude_with ( self ) : <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ( [ self . enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ self . enabled_tag , self . other_tag ] , "<STR_LIT>" ) , <EOL> ( [ self . enabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ self . other_tag ] , "<STR_LIT>" ) , <EOL> ( [ self . other_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ self . similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , self . similar_tag ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> result1 = self . tag_matcher . should_run_with ( tags ) <EOL> result2 = self . tag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( result1 , not result2 , "<STR_LIT>" % ( case , tags ) ) <EOL> self . assertEqual ( not result1 , result2 , "<STR_LIT>" % ( case , tags ) ) <EOL> def test_make_category_tag__returns_category_tag_prefix_without_value ( self ) : <EOL> category = "<STR_LIT>" <EOL> tag1 = OnlyWithCategoryTagMatcher . make_category_tag ( category ) <EOL> tag2 = OnlyWithCategoryTagMatcher . make_category_tag ( category , None ) <EOL> tag3 = OnlyWithCategoryTagMatcher . make_category_tag ( category , value = None ) <EOL> self . assertEqual ( "<STR_LIT>" , tag1 ) <EOL> self . assertEqual ( "<STR_LIT>" , tag2 ) <EOL> self . assertEqual ( "<STR_LIT>" , tag3 ) <EOL> self . assertTrue ( tag1 . startswith ( OnlyWithCategoryTagMatcher . tag_prefix ) ) <EOL> def test_make_category_tag__returns_category_tag_with_value ( self ) : <EOL> category = "<STR_LIT>" <EOL> tag1 = OnlyWithCategoryTagMatcher . make_category_tag ( category , "<STR_LIT>" ) <EOL> tag2 = OnlyWithCategoryTagMatcher . make_category_tag ( category , "<STR_LIT>" ) <EOL> self . assertEqual ( "<STR_LIT>" , tag1 ) <EOL> self . assertEqual ( "<STR_LIT>" , tag2 ) <EOL> def test_make_category_tag__returns_category_tag_with_tag_prefix ( self ) : <EOL> my_tag_prefix = "<STR_LIT>" <EOL> category = "<STR_LIT>" <EOL> TagMatcher = OnlyWithCategoryTagMatcher <EOL> tag0 = TagMatcher . make_category_tag ( category , tag_prefix = my_tag_prefix ) <EOL> tag1 = TagMatcher . make_category_tag ( category , "<STR_LIT>" , my_tag_prefix ) <EOL> tag2 = TagMatcher . make_category_tag ( category , "<STR_LIT>" , tag_prefix = my_tag_prefix ) <EOL> self . assertEqual ( "<STR_LIT>" , tag0 ) <EOL> self . assertEqual ( "<STR_LIT>" , tag1 ) <EOL> self . assertEqual ( "<STR_LIT>" , tag2 ) <EOL> self . assertTrue ( tag1 . startswith ( my_tag_prefix ) ) <EOL> def test_ctor__with_tag_prefix ( self ) : <EOL> tag_prefix = "<STR_LIT>" <EOL> tag_matcher = OnlyWithCategoryTagMatcher ( "<STR_LIT>" , "<STR_LIT>" , tag_prefix ) <EOL> tags = [ "<STR_LIT:foo>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:bar>" ] <EOL> actual_tags = tag_matcher . select_category_tags ( tags ) <EOL> self . assertEqual ( [ "<STR_LIT>" ] , actual_tags ) <EOL> class Traits4OnlyWithAnyCategoryTagMatcher ( object ) : <EOL> """<STR_LIT>""" <EOL> TagMatcher0 = OnlyWithCategoryTagMatcher <EOL> TagMatcher = OnlyWithAnyCategoryTagMatcher <EOL> category1_enabled_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category1_similar_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category1_disabled_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:foo>" , "<STR_LIT>" ) <EOL> category2_enabled_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> category2_similar_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> category2_disabled_tag = TagMatcher0 . make_category_tag ( "<STR_LIT:bar>" , "<STR_LIT>" ) <EOL> unknown_category_tag = TagMatcher0 . make_category_tag ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> class TestOnlyWithAnyCategoryTagMatcher ( TestCase ) : <EOL> TagMatcher = OnlyWithAnyCategoryTagMatcher <EOL> traits = Traits4OnlyWithAnyCategoryTagMatcher <EOL> def setUp ( self ) : <EOL> value_provider = { <EOL> "<STR_LIT:foo>" : "<STR_LIT>" , <EOL> "<STR_LIT:bar>" : "<STR_LIT>" , <EOL> } <EOL> with warnings . catch_warnings ( ) : <EOL> warnings . simplefilter ( "<STR_LIT:ignore>" , DeprecationWarning ) <EOL> self . tag_matcher = self . TagMatcher ( value_provider ) <EOL> def test_should_exclude_with__returns_false_with_enabled_tag ( self ) : <EOL> traits = self . traits <EOL> tags1 = [ traits . category1_enabled_tag ] <EOL> tags2 = [ traits . category2_enabled_tag ] <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags1 ) ) <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags2 ) ) <EOL> def test_should_exclude_with__returns_false_with_enabled_tag_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_enabled_tag , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag , traits . category1_enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_enabled_tag , traits . category1_disabled_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag ( self ) : <EOL> traits = self . traits <EOL> tags = [ traits . category1_disabled_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_other_tag_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_disabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_disabled_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_tag ( self ) : <EOL> traits = self . traits <EOL> tags = [ traits . category1_similar_tag ] <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__returns_true_with_similar_and_more ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ traits . category1_similar_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( True , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_false_without_category_tag ( self ) : <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_exclude_with__returns_false_with_unknown_category_tag ( self ) : <EOL> """<STR_LIT>""" <EOL> traits = self . traits <EOL> tags = [ traits . unknown_category_tag ] <EOL> self . assertEqual ( "<STR_LIT>" , traits . unknown_category_tag ) <EOL> self . assertEqual ( None , self . tag_matcher . value_provider . get ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( False , self . tag_matcher . should_exclude_with ( tags ) ) <EOL> def test_should_exclude_with__combinations_of_2_categories ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_enabled_tag , traits . category2_disabled_tag ] ) , <EOL> ( "<STR_LIT>" , False , <EOL> [ traits . category1_enabled_tag , traits . category2_enabled_tag ] ) , <EOL> ( "<STR_LIT>" , True , <EOL> [ traits . category1_disabled_tag , traits . unknown_category_tag ] ) , <EOL> ( "<STR_LIT>" , False , <EOL> [ traits . category1_enabled_tag , traits . unknown_category_tag ] ) , <EOL> ] <EOL> for case , expected , tags in test_patterns : <EOL> actual_result = self . tag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( expected , actual_result , <EOL> "<STR_LIT>" % ( case , tags ) ) <EOL> def test_should_run_with__negates_result_of_should_exclude_with ( self ) : <EOL> traits = self . traits <EOL> test_patterns = [ <EOL> ( [ ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , "<STR_LIT:bar>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag , traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_enabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_disabled_tag , "<STR_LIT:foo>" ] , "<STR_LIT>" ) , <EOL> ( [ traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ( [ "<STR_LIT:foo>" , traits . category1_similar_tag ] , "<STR_LIT>" ) , <EOL> ] <EOL> for tags , case in test_patterns : <EOL> result1 = self . tag_matcher . should_run_with ( tags ) <EOL> result2 = self . tag_matcher . should_exclude_with ( tags ) <EOL> self . assertEqual ( result1 , not result2 , "<STR_LIT>" % ( case , tags ) ) <EOL> self . assertEqual ( not result1 , result2 , "<STR_LIT>" % ( case , tags ) ) </s>
