def test_table_cell_border_top(self): style = Style("table-cell", border_top="0.002cm") self.assertIn( style.serialize(), ( ("<style:style " 'style:family="table-cell"><style:table-cell-properties ' 'fo:border-bottom="none" fo:border-left="none" ' 'fo:border-right="none" fo:border-top="0.002cm"/>' "</style:style>"), ("<style:style " 'style:family="table-cell"><style:table-cell-properties ' 'fo:border-top="0.002cm" fo:border-right="none" ' 'fo:border-bottom="none" fo:border-left="none"/>' "</style:style>"), ("<style:style " 'style:family="table-cell"><style:table-cell-properties ' 'fo:border-top="0.002cm" fo:border-left="none" ' 'fo:border-right="none" fo:border-bottom="none"/>' "</style:style>"), ), )
def test_insert_style(self): styles = self.styles.clone style = Style('paragraph', name='style1', area='text', **{ 'fo:color': '#0000ff', 'fo:background-color': '#ff0000' }) context = styles.get_element('//office:styles') context.append(style) get1 = styles.get_style('paragraph', 'style1') self.assertIn( get1.serialize(), (('<style:style style:name="style1" ' 'style:family="paragraph">' '<style:text-properties fo:background-color="#ff0000" ' 'fo:color="#0000ff"/>' '</style:style>'), '<style:style style:family="paragraph" ' 'style:name="style1">' '<style:text-properties ' 'fo:background-color="#ff0000" ' 'fo:color="#0000ff"/>' '</style:style>'))
def test_create_style_list(self): style = Style('list') expected = ('<text:list-style/>') self.assertEqual(style.serialize(), expected)
def test_create_style_section(self): style = Style('section') expected = ('<style:style style:family="section"/>') self.assertEqual(style.serialize(), expected)
def test_create_style_list(self): style = Style("list") expected = "<text:list-style/>" self.assertEqual(style.serialize(), expected)
class LevelStyleTestCase(TestCase): def setUp(self): self.style = Style('list') def test_get_level_style(self): level_style = self.style.get_level_style(1) self.assertTrue(level_style is None) def test_set_level_style(self): self.style.set_level_style(1, num_format='1') level_style = self.style.get_level_style(1) self.assertTrue(level_style is not None) def test_set_level_style_number_missing_format(self): self.assertRaises(ValueError, self.style.set_level_style, 1) def test_set_level_style_number(self): level_style = self.style.set_level_style(1, num_format='1') self.assertTrue(isinstance(level_style, Style)) expected = ('<text:list-level-style-number ' 'text:level="1" fo:num-format="1"/>') self.assertEqual(level_style.serialize(), expected) def test_set_level_style_bullet(self): level_style = self.style.set_level_style(2, bullet_char='·') self.assertTrue(isinstance(level_style, Style)) expected = ('<text:list-level-style-bullet ' 'text:level="2" text:bullet-char="·"/>') self.assertEqual(level_style.serialize(), expected) def test_set_level_style_image(self): level_style = self.style.set_level_style(3, url='bullet.png') self.assertTrue(isinstance(level_style, Style)) expected = ('<text:list-level-style-image ' 'text:level="3" xlink:href="bullet.png"/>') self.assertEqual(level_style.serialize(), expected) def test_set_level_style_full(self): level_style = self.style.set_level_style(3, num_format='1', prefix=" ", suffix=".", display_levels=3, start_value=2, style='MyList') expected = ('<text:list-level-style-number ' 'text:level="3" fo:num-format="1" ' 'style:num-prefix=" " style:num-suffix="." ' 'text:display-levels="3" text:start-value="2" ' 'text:style-name="MyList"/>') self.assertEqual(level_style.serialize(), expected) def test_set_level_style_clone(self): level_1 = self.style.set_level_style(1, num_format='1') level_2 = self.style.set_level_style(2, display_levels=2, clone=level_1) expected = ('<text:list-level-style-number ' 'text:level="2" fo:num-format="1" ' 'text:display-levels="2"/>') self.assertEqual(level_2.serialize(), expected)
def setUp(self): self.style = Style('paragraph')
def test_create_style_parent(self): style = Style('paragraph', parent_style="Heading 1") expected = ('<style:style style:family="paragraph" ' 'style:parent-style-name="Heading 1"/>') self.assertEqual(style.serialize(), expected)
def test_create_style_master_page(self): style = Style('master-page') expected = ('<style:master-page/>') self.assertEqual(style.serialize(), expected)
def setUp(self): self.style = Style("list")
def setUp(self): self.style = Style("paragraph")
def test_create_style_master_page(self): style = Style("master-page") expected = "<style:master-page/>" self.assertEqual(style.serialize(), expected)
def test_create_style_page_layout(self): style = Style("page-layout") expected = "<style:page-layout/>" self.assertEqual(style.serialize(), expected)
def test_create_style_outline(self): style = Style("outline") expected = "<text:outline-style/>" self.assertEqual(style.serialize(), expected)
def test_create_style_outline(self): style = Style('outline') expected = ('<text:outline-style/>') self.assertEqual(style.serialize(), expected)
def test_create_style_page_layout(self): style = Style('page-layout') expected = ('<style:page-layout/>') self.assertEqual(style.serialize(), expected)
def test_insert_automatic_style(self): doc = self.doc style = Style('paragraph') doc.insert_style(style, automatic=True) self.assertNotEqual(style.name, None)
def test_create_style_display_name(self): style = Style('paragraph', display_name="Heading 1") expected = ('<style:style style:family="paragraph" ' 'style:display-name="Heading 1"/>') self.assertEqual(style.serialize(), expected)
def test_create_style_text(self): style = Style('text') expected = ('<style:style style:family="text"/>') self.assertEqual(style.serialize(), expected)
def test_create_style_properties(self): style = Style('paragraph', **{'fo:margin-top': "0cm"}) expected = ('<style:style style:family="paragraph">' '<style:paragraph-properties fo:margin-top="0cm"/>' '</style:style>') self.assertEqual(style.serialize(), expected)
def test_create_style_graphic(self): style = Style('graphic') expected = ('<style:style style:family="graphic"/>') self.assertEqual(style.serialize(), expected)
def test_bad_family(self): style = Style('master-page') self.assertRaises(TypeError, style.set_background)
def test_create_style_table_cell(self): style = Style('table-cell') expected = ('<style:style style:family="table-cell"/>') self.assertEqual(style.serialize(), expected)
def setUp(self): self.style = Style('list')
def test_create_style_table_row(self): style = Style("table-row") expected = '<style:style style:family="table-row"/>' self.assertEqual(style.serialize(), expected)