File size: 2,281 Bytes
c626d10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import unittest
import os
from src.domain.doc import Doc
from src.domain.styles import Styles
from src.domain.container import Container
from src.domain.paragraph import Paragraph
def test_centered_tables(doc):
for table in doc.xdoc.tables:
if table.alignment != 1:
return False
return True
class Test(unittest.TestCase):
def test_centered_tables(self):
doctotest = Doc(path="test/files_to_test/tables/is_centered.docx")
tempdoc = doctotest.copy("test/files_to_test/tables/is_centered_copy.docx")
tempdoc.save_as_docx()
self.assertFalse(test_centered_tables(doctotest))
doctotest.center_tables()
doctotest.save_as_docx()
self.assertTrue(test_centered_tables(doctotest))
os.remove(doctotest.path)
tempdoc.save_as_docx("test/files_to_test/tables/is_centered.docx")
def test_centered_tables_within_text(self):
doctotest = Doc(path="test/files_to_test/tables/centered_within_text.docx")
tempdoc = doctotest.copy("test/files_to_test/tables/centered_within_text_copy.docx")
tempdoc.save_as_docx()
self.assertFalse(test_centered_tables(doctotest))
doctotest.center_tables()
doctotest.save_as_docx()
self.assertTrue(test_centered_tables(doctotest))
os.remove(doctotest.path)
tempdoc.save_as_docx("test/files_to_test/tables/centered_within_text.docx")
def test_noimage(self):
counter = 0
doctest = Doc(path="test/files_to_test/images/0_image.docx")
for p in doctest.get_paragraphs():
if p.contains_image():
counter += 1
self.assertEqual(counter, 0)
def test_containsimage(self):
counter = 0
doctest = Doc(path="test/files_to_test/images/1_image.docx")
for p in doctest.get_paragraphs():
if p.contains_image():
counter += 1
self.assertEqual(counter, 1)
def test_someimages(self):
counter = 0
doctest = Doc(path="test/files_to_test/images/2_images.docx")
for p in doctest.get_paragraphs():
if p.contains_image():
counter += 1
self.assertEqual(counter, 2)
if __name__ == '__main__':
unittest.main() |