<commit_before># -*- coding: UTF-8 -*-
# Copyright (C) 2009 Itaapy, ArsAperta, Pierlis, Talend

# Import from the Standard Library
from unittest import TestCase, main

# Import from lpod
from lpod.document import odf_new_document_from_template
from lpod.document import odf_new_document_from_type, odf_get_document


class NewDocumentFromTemplateTestCase(TestCase):

    def test_bad_template(self):
        self.assertRaises(ValueError, odf_new_document_from_template,
                          '../templates/notexisting')

    def test_text_template(self):
        uri = '../templates/text.ott'
        self.assert_(odf_new_document_from_template(uri))


    def test_spreadsheet_template(self):
        uri = '../templates/spreadsheet.ots'
        self.assert_(odf_new_document_from_template(uri))


    def test_presentation_template(self):
        uri = '../templates/presentation.otp'
        self.assert_(odf_new_document_from_template(uri))


    def test_drawing_template(self):
        uri = '../templates/drawing.otg'
        self.assert_(odf_new_document_from_template(uri))



class NewdocumentFromTypeTestCase(TestCase):

    def test_bad_type(self):
        self.assertRaises(ValueError, odf_new_document_from_type,
                          'foobar')


    def test_text_type(self):
        self.assert_(odf_new_document_from_type('text'))


    def test_spreadsheet_type(self):
        self.assert_(odf_new_document_from_type('spreadsheet'))


    def test_presentation_type(self):
        self.assert_(odf_new_document_from_type('presentation'))


    def test_drawing_type(self):
        self.assert_(odf_new_document_from_type('drawing'))



class GetDocumentTestCase(TestCase):

    def test_filesystem(self):
        path = 'samples/example.odt'
        self.assert_(odf_get_document(path))


    def test_odf_xml(self):
        path = 'samples/example.xml'
        self.assert_(odf_get_document(path))


    def test_http(self):
        uri = 'http://ftp.lpod-project.org/example.odt'
        self.assert_(odf_get_document(uri))


    def test_ftp(self):
        uri = 'ftp://ftp.lpod-project.org/example.odt'
        self.assert_(odf_get_document(uri))



class DocumentTestCase(TestCase):

    def setUp(self):
        self.document = odf_get_document('samples/example.odt')


    def tearDown(self):
        del self.document


    def test_get_body(self):
        document = self.document
        body = document.get_body()
        self.assertEqual(body.get_name(), 'office:text')


    def test_clone(self):
        document = self.document
        document.get_xmlpart('content')
        self.assertNotEqual(document._odf_document__xmlparts, {})
        clone = document.clone()
        self.assertNotEqual(clone._odf_document__xmlparts, {})
        parts = clone._odf_document__xmlparts
        self.assertEqual(len(parts), 1)
        self.assertEqual(parts.keys(), ['content'])
        container = clone.container
        self.assertEqual(container.uri, None)


class TestStyle(TestCase):

    def setUp(self):
        self.document = odf_get_document('samples/example.odt')


    def tearDown(self):
        del self.document


    def test_get_style_list(self):
        document = self.document
        styles = document.get_style_list()
        self.assertEqual(len(styles), 18)


    def test_get_style_list_family(self):
        document = self.document
        styles = document.get_style_list(family='paragraph')
        self.assertEqual(len(styles), 11)


    def test_get_style_automatic(self):
        document = self.document
        style = document.get_style('paragraph', u'P1')
        self.assertNotEqual(style, None)


    def test_get_style_named(self):
        document = self.document
        style = document.get_style('paragraph', u'Heading_20_1')
        self.assertNotEqual(style, None)



if __name__ == '__main__':
    main()<commit_msg>python: test_document: Add family tests for get_style_list.<commit_after># -*- coding: UTF-8 -*-
# Copyright (C) 2009 Itaapy, ArsAperta, Pierlis, Talend

# Import from the Standard Library
from unittest import TestCase, main

# Import from lpod
from lpod.document import odf_new_document_from_template
from lpod.document import odf_new_document_from_type, odf_get_document


class NewDocumentFromTemplateTestCase(TestCase):

    def test_bad_template(self):
        self.assertRaises(ValueError, odf_new_document_from_template,
                          '../templates/notexisting')

    def test_text_template(self):
        uri = '../templates/text.ott'
        self.assert_(odf_new_document_from_template(uri))


    def test_spreadsheet_template(self):
        uri = '../templates/spreadsheet.ots'
        self.assert_(odf_new_document_from_template(uri))


    def test_presentation_template(self):
        uri = '../templates/presentation.otp'
        self.assert_(odf_new_document_from_template(uri))


    def test_drawing_template(self):
        uri = '../templates/drawing.otg'
        self.assert_(odf_new_document_from_template(uri))



class NewdocumentFromTypeTestCase(TestCase):

    def test_bad_type(self):
        self.assertRaises(ValueError, odf_new_document_from_type,
                          'foobar')


    def test_text_type(self):
        self.assert_(odf_new_document_from_type('text'))


    def test_spreadsheet_type(self):
        self.assert_(odf_new_document_from_type('spreadsheet'))


    def test_presentation_type(self):
        self.assert_(odf_new_document_from_type('presentation'))


    def test_drawing_type(self):
        self.assert_(odf_new_document_from_type('drawing'))



class GetDocumentTestCase(TestCase):

    def test_filesystem(self):
        path = 'samples/example.odt'
        self.assert_(odf_get_document(path))


    def test_odf_xml(self):
        path = 'samples/example.xml'
        self.assert_(odf_get_document(path))


    def test_http(self):
        uri = 'http://ftp.lpod-project.org/example.odt'
        self.assert_(odf_get_document(uri))


    def test_ftp(self):
        uri = 'ftp://ftp.lpod-project.org/example.odt'
        self.assert_(odf_get_document(uri))



class DocumentTestCase(TestCase):

    def setUp(self):
        self.document = odf_get_document('samples/example.odt')


    def tearDown(self):
        del self.document


    def test_get_body(self):
        document = self.document
        body = document.get_body()
        self.assertEqual(body.get_name(), 'office:text')


    def test_clone(self):
        document = self.document
        document.get_xmlpart('content')
        self.assertNotEqual(document._odf_document__xmlparts, {})
        clone = document.clone()
        self.assertNotEqual(clone._odf_document__xmlparts, {})
        parts = clone._odf_document__xmlparts
        self.assertEqual(len(parts), 1)
        self.assertEqual(parts.keys(), ['content'])
        container = clone.container
        self.assertEqual(container.uri, None)



class TestStyle(TestCase):

    def setUp(self):
        self.document = odf_get_document('../templates/lpod_styles.odt')


    def tearDown(self):
        del self.document


    def test_get_style_list(self):
        document = self.document
        styles = document.get_style_list()
        self.assertEqual(len(styles), 57)


    def test_get_style_list_family_paragraph(self):
        document = self.document
        styles = document.get_style_list(family='paragraph')
        self.assertEqual(len(styles), 33)


    def test_get_style_list_family_text(self):
        document = self.document
        styles = document.get_style_list(family='text')
        self.assertEqual(len(styles), 4)


    def test_get_style_list_family_graphic(self):
        document = self.document
        styles = document.get_style_list(family='graphic')
        self.assertEqual(len(styles), 1)


    def test_get_style_list_family_page_layout(self):
        document = self.document
        styles = document.get_style_list(family='page-layout')
        self.assertEqual(len(styles), 2)


    def test_get_style_list_family_master_page(self):
        document = self.document
        styles = document.get_style_list(family='master-page')
        self.assertEqual(len(styles), 2)


    def test_get_style_automatic(self):
        document = self.document
        style = document.get_style('paragraph', u'P1')
        self.assertNotEqual(style, None)


    def test_get_style_named(self):
        document = self.document
        style = document.get_style('paragraph', u'Heading_20_1')
        self.assertNotEqual(style, None)



if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.10462683096954196, 'fraction_numerical': 0.00372006510113927, 'mean_word_length': 3.17621359223301, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1436254', 'n_tokens_mistral': 2734, 'n_tokens_neox': 2570, 'n_words': 407}