def but_it_raises_on_attempt_to_remove_slide_layout_in_use( self, slide_layout_, slide_): slide_layout_.used_by_slides = (slide_, ) slide_layouts = SlideLayouts(None, None) with pytest.raises(ValueError): slide_layouts.remove(slide_layout_)
def but_it_raises_on_slide_layout_not_in_collection( self, _iter_, slide_layout_, slide_layout_2_): _iter_.return_value = iter((slide_layout_, )) slide_layouts = SlideLayouts(None, None) with pytest.raises(ValueError) as e: slide_layouts.index(slide_layout_2_) assert str(e.value) == "layout not in this SlideLayouts collection"
def but_it_raises_on_attempt_to_remove_slide_layout_in_use( self, slide_layout_, slide_ ): slide_layout_.used_by_slides = (slide_,) slide_layouts = SlideLayouts(None, None) with pytest.raises(ValueError): slide_layouts.remove(slide_layout_)
def it_knows_the_index_of_each_of_its_slide_layouts( self, _iter_, slide_layout_, slide_layout_2_): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layouts = SlideLayouts(None, None) index = slide_layouts.index(slide_layout_2_) assert index == 1
def it_can_find_a_slide_layout_by_name(self, _iter_, slide_layout_, slide_layout_2_): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layout_2_.name = "pick me!" slide_layouts = SlideLayouts(None, None) slide_layout = slide_layouts.get_by_name("pick me!") assert slide_layout is slide_layout_2_
def but_it_raises_on_slide_layout_not_in_collection( self, _iter_, slide_layout_, slide_layout_2_ ): _iter_.return_value = iter((slide_layout_,)) slide_layouts = SlideLayouts(None, None) with pytest.raises(ValueError) as e: slide_layouts.index(slide_layout_2_) assert str(e.value) == "layout not in this SlideLayouts collection"
def it_knows_the_index_of_each_of_its_slide_layouts( self, _iter_, slide_layout_, slide_layout_2_ ): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layouts = SlideLayouts(None, None) index = slide_layouts.index(slide_layout_2_) assert index == 1
def it_can_find_a_slide_layout_by_name( self, _iter_, slide_layout_, slide_layout_2_ ): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layout_2_.name = "pick me!" slide_layouts = SlideLayouts(None, None) slide_layout = slide_layouts.get_by_name("pick me!") assert slide_layout is slide_layout_2_
def but_it_returns_the_default_value_when_no_layout_has_that_name( self, _iter_, slide_layout_, slide_layout_2_): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layout_2_.name = "not the droid you're looking for" slide_layouts = SlideLayouts(None, None) # ---default-default is None--- slide_layout = slide_layouts.get_by_name("pick me!") assert slide_layout is None # ---but default can be specified--- slide_layout = slide_layouts.get_by_name("pick me!", "default-value") assert slide_layout == "default-value"
def but_it_returns_the_default_value_when_no_layout_has_that_name( self, _iter_, slide_layout_, slide_layout_2_ ): _iter_.return_value = iter((slide_layout_, slide_layout_2_)) slide_layout_2_.name = "not the droid you're looking for" slide_layouts = SlideLayouts(None, None) # ---default-default is None--- slide_layout = slide_layouts.get_by_name("pick me!") assert slide_layout is None # ---but default can be specified--- slide_layout = slide_layouts.get_by_name("pick me!", "default-value") assert slide_layout == "default-value"
def it_can_remove_an_unused_slide_layout(self, slide_layout_, index_, slide_master_, slide_master_part_): slide_layout_.used_by_slides = () index_.return_value = 0 sldLayoutIdLst = element( "p:sldLayoutIdLst/(p:sldLayoutId{r:id=rId1},p:sldLayoutId{r:id=rId2})" ) slide_layout_.slide_master = slide_master_ slide_master_.part = slide_master_part_ slide_layouts = SlideLayouts(sldLayoutIdLst, None) slide_layouts.remove(slide_layout_) assert slide_layouts._sldLayoutIdLst.xml == xml( "p:sldLayoutIdLst/p:sldLayoutId{r:id=rId2}") slide_master_part_.drop_rel.assert_called_once_with("rId1")
def it_can_remove_an_unused_slide_layout( self, slide_layout_, index_, slide_master_, slide_master_part_ ): slide_layout_.used_by_slides = () index_.return_value = 0 sldLayoutIdLst = element( "p:sldLayoutIdLst/(p:sldLayoutId{r:id=rId1},p:sldLayoutId{r:id=rId2})" ) slide_layout_.slide_master = slide_master_ slide_master_.part = slide_master_part_ slide_layouts = SlideLayouts(sldLayoutIdLst, None) slide_layouts.remove(slide_layout_) assert slide_layouts._sldLayoutIdLst.xml == xml( "p:sldLayoutIdLst/p:sldLayoutId{r:id=rId2}" ) slide_master_part_.drop_rel.assert_called_once_with("rId1")
def it_supports_indexed_access(self, slide_layout_, part_prop_, slide_master_part_): part_prop_.return_value = slide_master_part_ slide_master_part_.related_slide_layout.return_value = slide_layout_ slide_layouts = SlideLayouts( element("p:sldLayoutIdLst/p:sldLayoutId{r:id=rId1}"), None) slide_layout = slide_layouts[0] slide_master_part_.related_slide_layout.assert_called_once_with("rId1") assert slide_layout is slide_layout_
def iter_fixture(self, part_prop_, part_): sldLayoutIdLst = element( 'p:sldLayoutIdLst/(p:sldLayoutId{r:id=a},p:sldLayoutId{r:id=b})') slide_layouts = SlideLayouts(sldLayoutIdLst, None) _slide_layouts = [ SlideLayout(element('p:sldLayout'), None), SlideLayout(element('p:sldLayout'), None), ] related_slide_layout_ = part_.related_slide_layout related_slide_layout_.side_effect = _slide_layouts calls = [call('a'), call('b')] return slide_layouts, related_slide_layout_, calls, _slide_layouts
def it_can_iterate_its_slide_layouts(self, part_prop_, slide_master_part_): sldLayoutIdLst = element( "p:sldLayoutIdLst/(p:sldLayoutId{r:id=a},p:sldLayoutId{r:id=b})") _slide_layouts = [ SlideLayout(element("p:sldLayout"), None), SlideLayout(element("p:sldLayout"), None), ] part_prop_.return_value = slide_master_part_ related_slide_layout_ = slide_master_part_.related_slide_layout related_slide_layout_.side_effect = _slide_layouts slide_layouts = SlideLayouts(sldLayoutIdLst, None) slide_layout_lst = [sl for sl in slide_layouts] assert related_slide_layout_.call_args_list == [call("a"), call("b")] assert slide_layout_lst == _slide_layouts
def len_fixture(self, request): sldLayoutIdLst_cxml, expected_value = request.param slide_layouts = SlideLayouts(element(sldLayoutIdLst_cxml), None) return slide_layouts, expected_value
def getitem_raises_fixture(self, part_prop_): return SlideLayouts( element('p:sldLayoutIdLst/p:sldLayoutId{r:id=rId1}'), None)
def getitem_fixture(self, part_, slide_layout_, part_prop_): slide_layouts = SlideLayouts( element('p:sldLayoutIdLst/p:sldLayoutId{r:id=rId1}'), None) part_.related_slide_layout.return_value = slide_layout_ return slide_layouts, part_, slide_layout_, 'rId1'
def but_it_raises_on_index_out_of_range(self, part_prop_): slide_layouts = SlideLayouts( element("p:sldLayoutIdLst/p:sldLayoutId{r:id=rId1}"), None) with pytest.raises(IndexError): slide_layouts[1]