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

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

# Import from the XML Library
from lxml.etree import _Element

# Import from lpod
from lpod.document import odf_get_document
from lpod.utils import _make_xpath_query, _check_arguments
from lpod.utils import DateTime, Duration, Boolean
from lpod.xmlpart import odf_create_element


class GenerateXPathTestCase(TestCase):

    def test_element(self):
        query = _make_xpath_query('text:p')
        self.assertEqual(query, '//text:p')


    def test_attribute(self):
        query = _make_xpath_query('text:p', style='Standard')
        self.assertEqual(query, '//text:p[@text:style-name="Standard"]')


    def test_two_attributes(self):
        query = _make_xpath_query('text:h', style='Standard', level=1)
        expected = ('//text:h[@text:outline-level="1"]'
                    '[@text:style-name="Standard"]')
        self.assertEqual(query, expected)


    def test_position(self):
        query = _make_xpath_query('text:h', position=2)
        self.assertEqual(query, '//text:h[2]')


    def test_attribute_position(self):
        query = _make_xpath_query('text:p', style='Standard', position=2)
        self.assertEqual(query, '//text:p[@text:style-name="Standard"][2]')


    def test_two_attributes_position(self):
        query = _make_xpath_query('text:h', style='Standard', level=1,
                                  position=2)
        expected = ('//text:h[@text:outline-level="1"]'
                    '[@text:style-name="Standard"][2]')
        self.assertEqual(query, expected)



class CheckArgumentsTestCase(TestCase):

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


    def tearDown(self):
        del self.document


    def test_bad_context(self):
        document = self.document
        self.assertRaises(TypeError, _check_arguments, context=document)


    def test_bad_element(self):
        self.assertRaises(TypeError, _check_arguments, element=_Element)


    def test_str_xmlposition(self):
        self.assertRaises(ValueError, _check_arguments, xmlposition='after')


    def test_big_xmlposition(self):
        self.assertRaises(ValueError, _check_arguments, xmlposition=999)


    def test_str_position(self):
        self.assertRaises(TypeError, _check_arguments, position='1')


    def test_position_zero(self):
        self.assertRaises(ValueError, _check_arguments, position=0)


    def test_str_level(self):
        self.assertRaises(TypeError, _check_arguments, level='1')


    def test_level_zero(self):
        self.assertRaises(ValueError, _check_arguments, level=0)


    def test_bad_text(self):
        self.assertRaises(TypeError, _check_arguments, text='Hello')


    def test_bad_style(self):
        data = ('<style:master-page '
                'style:name="Standard" '
                'style:page-layout-name="Mpm1"/>')
        element = odf_create_element(data)
        self.assertRaises(TypeError, _check_arguments, style=element)


    def test_bad_family(self):
        self.assertRaises(ValueError, _check_arguments, family='heading')


    def test_bad_cell_type(self):
        self.assertRaises(ValueError, _check_arguments, cell_type='integer')


    def test_missing_currency(self):
        self.assertRaises(ValueError, _check_arguments, cell_type='currency')


    def test_bad_author(self):
        self.assertRaises(TypeError, _check_arguments, author='Plato')

<commit_msg>python: test: Fix a bug with cell_type / value_type<commit_after># -*- coding: UTF-8 -*-
# Copyright (C) 2009 Itaapy, ArsAperta, <NAME>

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

# Import from the XML Library
from lxml.etree import _Element

# Import from lpod
from lpod.document import odf_get_document
from lpod.utils import _make_xpath_query, _check_arguments
from lpod.utils import DateTime, Duration, Boolean
from lpod.xmlpart import odf_create_element


class GenerateXPathTestCase(TestCase):

    def test_element(self):
        query = _make_xpath_query('text:p')
        self.assertEqual(query, '//text:p')


    def test_attribute(self):
        query = _make_xpath_query('text:p', style='Standard')
        self.assertEqual(query, '//text:p[@text:style-name="Standard"]')


    def test_two_attributes(self):
        query = _make_xpath_query('text:h', style='Standard', level=1)
        expected = ('//text:h[@text:outline-level="1"]'
                    '[@text:style-name="Standard"]')
        self.assertEqual(query, expected)


    def test_position(self):
        query = _make_xpath_query('text:h', position=2)
        self.assertEqual(query, '//text:h[2]')


    def test_attribute_position(self):
        query = _make_xpath_query('text:p', style='Standard', position=2)
        self.assertEqual(query, '//text:p[@text:style-name="Standard"][2]')


    def test_two_attributes_position(self):
        query = _make_xpath_query('text:h', style='Standard', level=1,
                                  position=2)
        expected = ('//text:h[@text:outline-level="1"]'
                    '[@text:style-name="Standard"][2]')
        self.assertEqual(query, expected)



class CheckArgumentsTestCase(TestCase):

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


    def tearDown(self):
        del self.document


    def test_bad_context(self):
        document = self.document
        self.assertRaises(TypeError, _check_arguments, context=document)


    def test_bad_element(self):
        self.assertRaises(TypeError, _check_arguments, element=_Element)


    def test_str_xmlposition(self):
        self.assertRaises(ValueError, _check_arguments, xmlposition='after')


    def test_big_xmlposition(self):
        self.assertRaises(ValueError, _check_arguments, xmlposition=999)


    def test_str_position(self):
        self.assertRaises(TypeError, _check_arguments, position='1')


    def test_position_zero(self):
        self.assertRaises(ValueError, _check_arguments, position=0)


    def test_str_level(self):
        self.assertRaises(TypeError, _check_arguments, level='1')


    def test_level_zero(self):
        self.assertRaises(ValueError, _check_arguments, level=0)


    def test_bad_text(self):
        self.assertRaises(TypeError, _check_arguments, text='Hello')


    def test_bad_style(self):
        data = ('<style:master-page '
                'style:name="Standard" '
                'style:page-layout-name="Mpm1"/>')
        element = odf_create_element(data)
        self.assertRaises(TypeError, _check_arguments, style=element)


    def test_bad_family(self):
        self.assertRaises(ValueError, _check_arguments, family='heading')


    def test_bad_cell_type(self):
        self.assertRaises(ValueError, _check_arguments, value_type='integer')


    def test_missing_currency(self):
        self.assertRaises(ValueError, _check_arguments, value_type='currency')


    def test_bad_author(self):
        self.assertRaises(TypeError, _check_arguments, author='Plato')


{'fraction_non_alphanumeric': 0.11696391538780589, 'fraction_numerical': 0.006359740080188027, 'mean_word_length': 3.593015873015873, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3188110', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2171, 'n_words': 400}