<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from behave . formatter . base import Formatter <EOL> from behave . textutil import compute_words_maxsize , text as _text <EOL> import six <EOL> class AbstractTagsFormatter ( Formatter ) : <EOL> """<STR_LIT>""" <EOL> with_tag_inheritance = False <EOL> def __init__ ( self , stream_opener , config ) : <EOL> super ( AbstractTagsFormatter , self ) . __init__ ( stream_opener , config ) <EOL> self . tag_counts = { } <EOL> self . _uri = None <EOL> self . _feature_tags = None <EOL> self . _scenario_outline_tags = None <EOL> def uri ( self , uri ) : <EOL> self . _uri = uri <EOL> def feature ( self , feature ) : <EOL> self . _feature_tags = feature . tags <EOL> self . record_tags ( feature . tags , feature ) <EOL> def scenario ( self , scenario ) : <EOL> tags = set ( scenario . tags ) <EOL> if self . with_tag_inheritance : <EOL> tags . update ( self . _feature_tags ) <EOL> self . record_tags ( tags , scenario ) <EOL> def scenario_outline ( self , scenario_outline ) : <EOL> self . _scenario_outline_tags = scenario_outline . tags <EOL> self . record_tags ( scenario_outline . tags , scenario_outline ) <EOL> def examples ( self , examples ) : <EOL> tags = set ( examples . tags ) <EOL> if self . with_tag_inheritance : <EOL> tags . update ( self . _scenario_outline_tags ) <EOL> tags . update ( self . _feature_tags ) <EOL> self . record_tags ( tags , examples ) <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . stream = self . open ( ) <EOL> self . report_tags ( ) <EOL> self . close_stream ( ) <EOL> def record_tags ( self , tags , model_element ) : <EOL> for tag in tags : <EOL> if tag not in self . tag_counts : <EOL> self . tag_counts [ tag ] = [ ] <EOL> self . tag_counts [ tag ] . append ( model_element ) <EOL> def report_tags ( self ) : <EOL> raise NotImplementedError <EOL> class TagsFormatter ( AbstractTagsFormatter ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> description = "<STR_LIT>" <EOL> with_tag_inheritance = False <EOL> show_ordered_by_usage = False <EOL> def report_tags ( self ) : <EOL> self . report_tag_counts ( ) <EOL> if self . show_ordered_by_usage : <EOL> self . report_tag_counts_by_usage ( ) <EOL> @ staticmethod <EOL> def get_tag_count_details ( tag_count ) : <EOL> details = { } <EOL> for element in tag_count : <EOL> category = element . keyword . lower ( ) <EOL> if category not in details : <EOL> details [ category ] = <NUM_LIT:0> <EOL> details [ category ] += <NUM_LIT:1> <EOL> parts = [ ] <EOL> if len ( details ) == <NUM_LIT:1> : <EOL> parts . append ( list ( details . keys ( ) ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> for category in sorted ( details . keys ( ) ) : <EOL> text = u"<STR_LIT>" % ( category , details [ category ] ) <EOL> parts . append ( text ) <EOL> return "<STR_LIT:U+002CU+0020>" . join ( parts ) <EOL> def report_tag_counts ( self ) : <EOL> ordered_tags = sorted ( list ( self . tag_counts . keys ( ) ) ) <EOL> tag_maxsize = compute_words_maxsize ( ordered_tags ) <EOL> schema = "<STR_LIT>" + _text ( tag_maxsize ) + "<STR_LIT>" <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> for tag in ordered_tags : <EOL> tag_data = self . tag_counts [ tag ] <EOL> counts = len ( tag_data ) <EOL> details = self . get_tag_count_details ( tag_data ) <EOL> self . stream . write ( schema % ( tag , counts , details ) ) <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> def report_tag_counts_by_usage ( self ) : <EOL> compare_tag_counts_size = lambda x : len ( self . tag_counts [ x ] ) <EOL> ordered_tags = sorted ( list ( self . tag_counts . keys ( ) ) , <EOL> key = compare_tag_counts_size ) <EOL> tag_maxsize = compute_words_maxsize ( ordered_tags ) <EOL> schema = "<STR_LIT>" + _text ( tag_maxsize ) + "<STR_LIT>" <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> for tag in ordered_tags : <EOL> tag_data = self . tag_counts [ tag ] <EOL> counts = len ( tag_data ) <EOL> details = self . get_tag_count_details ( tag_data ) <EOL> self . stream . write ( schema % ( tag , counts , details ) ) <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> class TagsLocationFormatter ( AbstractTagsFormatter ) : <EOL> """<STR_LIT>""" <EOL> name = "<STR_LIT>" <EOL> description = "<STR_LIT>" <EOL> with_tag_inheritance = False <EOL> def report_tags ( self ) : <EOL> self . report_tags_by_locations ( ) <EOL> def report_tags_by_locations ( self ) : <EOL> locations = set ( ) <EOL> for tag_elements in self . tag_counts . values ( ) : <EOL> locations . update ( [ six . text_type ( x . location ) for x in tag_elements ] ) <EOL> location_column_size = compute_words_maxsize ( locations ) <EOL> schema = u"<STR_LIT>" + _text ( location_column_size ) + "<STR_LIT>" <EOL> self . stream . write ( "<STR_LIT>" ) <EOL> for tag in sorted ( self . tag_counts . keys ( ) ) : <EOL> self . stream . write ( "<STR_LIT>" % tag ) <EOL> for element in self . tag_counts [ tag ] : <EOL> info = u"<STR_LIT>" % ( element . keyword , element . name ) <EOL> self . stream . write ( schema % ( element . location , info ) ) <EOL> self . stream . write ( "<STR_LIT:\n>" ) <EOL> self . stream . write ( "<STR_LIT:\n>" ) </s>
