<s> """<STR_LIT>""" <EOL> from __future__ import ( <EOL> absolute_import , division , print_function , unicode_literals <EOL> ) <EOL> import pytest <EOL> from docx . enum . style import WD_STYLE_TYPE <EOL> from docx . styles . style import ( <EOL> BaseStyle , _CharacterStyle , _ParagraphStyle , _NumberingStyle , <EOL> StyleFactory , _TableStyle <EOL> ) <EOL> from docx . text . font import Font <EOL> from docx . text . parfmt import ParagraphFormat <EOL> from . . unitutil . cxml import element , xml <EOL> from . . unitutil . mock import call , class_mock , function_mock , instance_mock <EOL> class DescribeStyleFactory ( object ) : <EOL> def it_constructs_the_right_type_of_style ( self , factory_fixture ) : <EOL> style_elm , StyleCls_ , style_ = factory_fixture <EOL> style = StyleFactory ( style_elm ) <EOL> StyleCls_ . assert_called_once_with ( style_elm ) <EOL> assert style is style_ <EOL> @ pytest . fixture ( params = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def factory_fixture ( <EOL> self , request , paragraph_style_ , _ParagraphStyle_ , <EOL> character_style_ , _CharacterStyle_ , table_style_ , _TableStyle_ , <EOL> numbering_style_ , _NumberingStyle_ ) : <EOL> type_attr_val = request . param <EOL> StyleCls_ , style_mock = { <EOL> '<STR_LIT>' : ( _ParagraphStyle_ , paragraph_style_ ) , <EOL> '<STR_LIT>' : ( _CharacterStyle_ , character_style_ ) , <EOL> '<STR_LIT>' : ( _TableStyle_ , table_style_ ) , <EOL> '<STR_LIT>' : ( _NumberingStyle_ , numbering_style_ ) , <EOL> } [ request . param ] <EOL> style_cxml = '<STR_LIT>' % type_attr_val <EOL> style_elm = element ( style_cxml ) <EOL> return style_elm , StyleCls_ , style_mock <EOL> @ pytest . fixture <EOL> def _ParagraphStyle_ ( self , request , paragraph_style_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = paragraph_style_ <EOL> ) <EOL> @ pytest . fixture <EOL> def paragraph_style_ ( self , request ) : <EOL> return instance_mock ( request , _ParagraphStyle ) <EOL> @ pytest . fixture <EOL> def _CharacterStyle_ ( self , request , character_style_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = character_style_ <EOL> ) <EOL> @ pytest . fixture <EOL> def character_style_ ( self , request ) : <EOL> return instance_mock ( request , _CharacterStyle ) <EOL> @ pytest . fixture <EOL> def _TableStyle_ ( self , request , table_style_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = table_style_ <EOL> ) <EOL> @ pytest . fixture <EOL> def table_style_ ( self , request ) : <EOL> return instance_mock ( request , _TableStyle ) <EOL> @ pytest . fixture <EOL> def _NumberingStyle_ ( self , request , numbering_style_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = numbering_style_ <EOL> ) <EOL> @ pytest . fixture <EOL> def numbering_style_ ( self , request ) : <EOL> return instance_mock ( request , _NumberingStyle ) <EOL> class DescribeBaseStyle ( object ) : <EOL> def it_knows_its_style_id ( self , id_get_fixture ) : <EOL> style , expected_value = id_get_fixture <EOL> assert style . style_id == expected_value <EOL> def it_can_change_its_style_id ( self , id_set_fixture ) : <EOL> style , new_value , expected_xml = id_set_fixture <EOL> style . style_id = new_value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_its_type ( self , type_get_fixture ) : <EOL> style , expected_value = type_get_fixture <EOL> assert style . type == expected_value <EOL> def it_knows_its_name ( self , name_get_fixture ) : <EOL> style , expected_value = name_get_fixture <EOL> assert style . name == expected_value <EOL> def it_can_change_its_name ( self , name_set_fixture ) : <EOL> style , new_value , expected_xml = name_set_fixture <EOL> style . name = new_value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_whether_its_a_builtin_style ( self , builtin_get_fixture ) : <EOL> style , expected_value = builtin_get_fixture <EOL> assert style . builtin is expected_value <EOL> def it_knows_whether_its_hidden ( self , hidden_get_fixture ) : <EOL> style , expected_value = hidden_get_fixture <EOL> assert style . hidden == expected_value <EOL> def it_can_change_whether_its_hidden ( self , hidden_set_fixture ) : <EOL> style , value , expected_xml = hidden_set_fixture <EOL> style . hidden = value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_its_sort_order ( self , priority_get_fixture ) : <EOL> style , expected_value = priority_get_fixture <EOL> assert style . priority == expected_value <EOL> def it_can_change_its_sort_order ( self , priority_set_fixture ) : <EOL> style , value , expected_xml = priority_set_fixture <EOL> style . priority = value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_whether_its_unhide_when_used ( self , unhide_get_fixture ) : <EOL> style , expected_value = unhide_get_fixture <EOL> assert style . unhide_when_used == expected_value <EOL> def it_can_change_its_unhide_when_used_value ( self , unhide_set_fixture ) : <EOL> style , value , expected_xml = unhide_set_fixture <EOL> style . unhide_when_used = value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_its_quick_style_setting ( self , quick_get_fixture ) : <EOL> style , expected_value = quick_get_fixture <EOL> assert style . quick_style == expected_value <EOL> def it_can_change_its_quick_style_setting ( self , quick_set_fixture ) : <EOL> style , new_value , expected_xml = quick_set_fixture <EOL> style . quick_style = new_value <EOL> assert style . _element . xml == expected_xml <EOL> def it_knows_whether_its_locked ( self , locked_get_fixture ) : <EOL> style , expected_value = locked_get_fixture <EOL> assert style . locked == expected_value <EOL> def it_can_change_whether_its_locked ( self , locked_set_fixture ) : <EOL> style , value , expected_xml = locked_set_fixture <EOL> style . locked = value <EOL> assert style . _element . xml == expected_xml <EOL> def it_can_delete_itself_from_the_document ( self , delete_fixture ) : <EOL> style , styles , expected_xml = delete_fixture <EOL> style . delete ( ) <EOL> assert styles . xml == expected_xml <EOL> assert style . _element is None <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] ) <EOL> def builtin_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture <EOL> def delete_fixture ( self ) : <EOL> styles = element ( '<STR_LIT>' ) <EOL> style = BaseStyle ( styles [ <NUM_LIT:0> ] ) <EOL> expected_xml = xml ( '<STR_LIT>' ) <EOL> return style , styles , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ] ) <EOL> def hidden_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ] ) <EOL> def hidden_set_fixture ( self , request ) : <EOL> style_cxml , value , expected_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_cxml ) <EOL> return style , value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def id_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ] ) <EOL> def id_set_fixture ( self , request ) : <EOL> style_cxml , new_value , expected_style_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_style_cxml ) <EOL> return style , new_value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ] ) <EOL> def locked_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ] ) <EOL> def locked_set_fixture ( self , request ) : <EOL> style_cxml , value , expected_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_cxml ) <EOL> return style , value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def name_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , '<STR_LIT>' ) , <EOL> ] ) <EOL> def name_set_fixture ( self , request ) : <EOL> style_cxml , new_value , expected_style_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_style_cxml ) <EOL> return style , new_value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , None ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ] ) <EOL> def priority_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , <NUM_LIT> , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) , <EOL> ] ) <EOL> def priority_set_fixture ( self , request ) : <EOL> style_cxml , value , expected_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_cxml ) <EOL> return style , value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ] ) <EOL> def quick_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , '<STR_LIT>' ) , <EOL> ] ) <EOL> def quick_set_fixture ( self , request ) : <EOL> style_cxml , new_value , expected_style_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_style_cxml ) <EOL> return style , new_value , expected_xml <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , WD_STYLE_TYPE . PARAGRAPH ) , <EOL> ( '<STR_LIT>' , WD_STYLE_TYPE . PARAGRAPH ) , <EOL> ( '<STR_LIT>' , WD_STYLE_TYPE . CHARACTER ) , <EOL> ( '<STR_LIT>' , WD_STYLE_TYPE . LIST ) , <EOL> ] ) <EOL> def type_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ] ) <EOL> def unhide_get_fixture ( self , request ) : <EOL> style_cxml , expected_value = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> return style , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , True , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , True , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , False , <EOL> '<STR_LIT>' ) , <EOL> ] ) <EOL> def unhide_set_fixture ( self , request ) : <EOL> style_cxml , value , expected_cxml = request . param <EOL> style = BaseStyle ( element ( style_cxml ) ) <EOL> expected_xml = xml ( expected_cxml ) <EOL> return style , value , expected_xml <EOL> class Describe_CharacterStyle ( object ) : <EOL> def it_knows_which_style_it_is_based_on ( self , base_get_fixture ) : <EOL> style , StyleFactory_ , StyleFactory_calls , base_style_ = ( <EOL> base_get_fixture <EOL> ) <EOL> base_style = style . base_style <EOL> assert StyleFactory_ . call_args_list == StyleFactory_calls <EOL> assert base_style == base_style_ <EOL> def it_can_change_its_base_style ( self , base_set_fixture ) : <EOL> style , value , expected_xml = base_set_fixture <EOL> style . base_style = value <EOL> assert style . _element . xml == expected_xml <EOL> def it_provides_access_to_its_font ( self , font_fixture ) : <EOL> style , Font_ , font_ = font_fixture <EOL> font = style . font <EOL> Font_ . assert_called_once_with ( style . _element ) <EOL> assert font is font_ <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , <EOL> <NUM_LIT:1> , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , <EOL> <NUM_LIT:1> , - <NUM_LIT:1> ) , <EOL> ( '<STR_LIT>' , <EOL> <NUM_LIT:0> , - <NUM_LIT:1> ) , <EOL> ] ) <EOL> def base_get_fixture ( self , request , StyleFactory_ ) : <EOL> styles_cxml , style_idx , base_style_idx = request . param <EOL> styles = element ( styles_cxml ) <EOL> style = _CharacterStyle ( styles [ style_idx ] ) <EOL> if base_style_idx >= <NUM_LIT:0> : <EOL> base_style = styles [ base_style_idx ] <EOL> StyleFactory_calls = [ call ( base_style ) ] <EOL> expected_value = StyleFactory_ . return_value <EOL> else : <EOL> StyleFactory_calls = [ ] <EOL> expected_value = None <EOL> return style , StyleFactory_ , StyleFactory_calls , expected_value <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , None , <EOL> '<STR_LIT>' ) , <EOL> ] ) <EOL> def base_set_fixture ( self , request , style_ ) : <EOL> style_cxml , base_style_id , expected_style_cxml = request . param <EOL> style = _CharacterStyle ( element ( style_cxml ) ) <EOL> style_ . style_id = base_style_id <EOL> base_style = style_ if base_style_id is not None else None <EOL> expected_xml = xml ( expected_style_cxml ) <EOL> return style , base_style , expected_xml <EOL> @ pytest . fixture <EOL> def font_fixture ( self , Font_ , font_ ) : <EOL> style = _CharacterStyle ( element ( '<STR_LIT>' ) ) <EOL> return style , Font_ , font_ <EOL> @ pytest . fixture <EOL> def Font_ ( self , request , font_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , return_value = font_ <EOL> ) <EOL> @ pytest . fixture <EOL> def font_ ( self , request ) : <EOL> return instance_mock ( request , Font ) <EOL> @ pytest . fixture <EOL> def style_ ( self , request ) : <EOL> return instance_mock ( request , BaseStyle ) <EOL> @ pytest . fixture <EOL> def StyleFactory_ ( self , request ) : <EOL> return function_mock ( request , '<STR_LIT>' ) <EOL> class Describe_ParagraphStyle ( object ) : <EOL> def it_knows_its_next_paragraph_style ( self , next_get_fixture ) : <EOL> style , expected_value = next_get_fixture <EOL> assert style . next_paragraph_style == expected_value <EOL> def it_can_change_its_next_paragraph_style ( self , next_set_fixture ) : <EOL> style , next_style , expected_xml = next_set_fixture <EOL> style . next_paragraph_style = next_style <EOL> assert style . element . xml == expected_xml <EOL> def it_provides_access_to_its_paragraph_format ( self , parfmt_fixture ) : <EOL> style , ParagraphFormat_ , paragraph_format_ = parfmt_fixture <EOL> paragraph_format = style . paragraph_format <EOL> ParagraphFormat_ . assert_called_once_with ( style . _element ) <EOL> assert paragraph_format is paragraph_format_ <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def next_get_fixture ( self , request ) : <EOL> style_name , next_style_name = request . param <EOL> styles = element ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> style_names = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> style_elm = styles [ style_names . index ( style_name ) ] <EOL> next_style_elm = styles [ style_names . index ( next_style_name ) ] <EOL> style = _ParagraphStyle ( style_elm ) <EOL> if style_name == '<STR_LIT>' : <EOL> next_style = _ParagraphStyle ( next_style_elm ) <EOL> else : <EOL> next_style = style <EOL> return style , next_style <EOL> @ pytest . fixture ( params = [ <EOL> ( '<STR_LIT:H>' , '<STR_LIT:B>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:H>' , None , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:H>' , '<STR_LIT:H>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def next_set_fixture ( self , request ) : <EOL> style_name , next_style_name , style_cxml = request . param <EOL> styles = element ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> style_elms = { '<STR_LIT:H>' : styles [ <NUM_LIT:0> ] , '<STR_LIT:B>' : styles [ <NUM_LIT:1> ] } <EOL> style = _ParagraphStyle ( style_elms [ style_name ] ) <EOL> next_style = ( <EOL> None if next_style_name is None else <EOL> _ParagraphStyle ( style_elms [ next_style_name ] ) <EOL> ) <EOL> expected_xml = xml ( style_cxml ) <EOL> return style , next_style , expected_xml <EOL> @ pytest . fixture <EOL> def parfmt_fixture ( self , ParagraphFormat_ , paragraph_format_ ) : <EOL> style = _ParagraphStyle ( element ( '<STR_LIT>' ) ) <EOL> return style , ParagraphFormat_ , paragraph_format_ <EOL> @ pytest . fixture <EOL> def ParagraphFormat_ ( self , request , paragraph_format_ ) : <EOL> return class_mock ( <EOL> request , '<STR_LIT>' , <EOL> return_value = paragraph_format_ <EOL> ) <EOL> @ pytest . fixture <EOL> def paragraph_format_ ( self , request ) : <EOL> return instance_mock ( request , ParagraphFormat ) </s>
