<commit_before># This test can be run stand-alone with something like:
# > PYTHONPATH=. python2 openerp/tests/test_view_validation.py

from lxml import etree
from StringIO import StringIO
import unittest2

import openerp
from openerp.tools.view_validation import *

invalid_form = etree.parse(StringIO('''\
<form>     
    <label></label>
    <group>
        <div>
            <page></page>
            <label colspan="True"></label>
            <field></field>
        </div>
    </group>
    <notebook>
        <page>
            <group col="Two">
            <div>
                <label></label>
                <field colspan="Five"> </field>
                </div>
            </group>
        </page>
    </notebook>
</form>
''')).getroot()

valid_form = etree.parse(StringIO('''\
<form string="">
    <notebook>
        <label for=""></label>
        <page>
            <field name=""></field>
            <label string=""></label>
            <field name=""></field>
        </page>
        <page>
            <group colspan="5" col="2">
                <label for=""></label>
                <label string="" colspan="5"></label>
            </group>
        </page>
    </notebook>
</form>
''')).getroot()

invalid_graph = etree.parse(StringIO('''\
<graph>
      <group>
        <div>
          <field></field>
          <field></field>
        </div>
      </group>
</graph>
''')).getroot()

valid_graph = etree.parse(StringIO('''\
<graph string="">
    <field name=""></field>
    <field name=""></field>
</graph>
''')).getroot()

invalid_tree = etree.parse(StringIO('''\
<tree>
  <group>
    <div>
      <field></field>
      <field></field>
    </div>
  </group>
</tree>
''')).getroot()

valid_tree= etree.parse(StringIO('''\
<tree string="">
    <button></button>
    <label string=""></label>
    <field name=""></field>
    <field name=""></field>
    <field name=""></field>
    <button></button>
</tree>
''')).getroot()


class test_view_validation(unittest2.TestCase):
    """ Test the view validation code (but not the views themselves). """

    def test_page_validation(self):
        assert not valid_page_in_book(invalid_form)
        assert valid_page_in_book(valid_form)
        
    def test_all_field_validation(self):
        assert not  valid_att_in_field(invalid_form)
        assert  valid_att_in_field(valid_form)

    def test_all_label_validation(self):
        assert not  valid_att_in_label(invalid_form)
        assert  valid_att_in_label(valid_form)
        
    def test_form_string_validation(self):
        assert not valid_att_in_form(invalid_form)
        assert valid_att_in_form(valid_form)

    def test_graph_field_validation(self):
        assert not valid_field_in_graph(invalid_graph)
        assert valid_field_in_graph(valid_graph)

    def test_graph_string_validation(self):
        assert not valid_field_in_graph(invalid_graph)
        assert valid_field_in_graph(valid_graph)
    
    def test_tree_field_validation(self):
        assert not valid_field_in_tree(invalid_tree)
        assert valid_field_in_tree(valid_tree)

    def test_tree_string_validation(self):
        assert not valid_field_in_tree(invalid_tree)
        assert valid_field_in_tree(valid_tree)
        
    def test_colspan_datatype_validation(self):
        assert not valid_type_in_colspan(invalid_form)
        assert valid_type_in_colspan(valid_form)
    
    def test_col_datatype_validation(self):
        assert not valid_type_in_col(invalid_form)
        assert valid_type_in_col(valid_form)
        
    def test_form_view(self):
        assert not valid_view(invalid_form)
        assert valid_view(valid_form)
    <commit_msg>[IMP] xml validation: white spaces.<commit_after># This test can be run stand-alone with something like:
# > PYTHONPATH=. python2 openerp/tests/test_view_validation.py

from lxml import etree
from StringIO import StringIO
import unittest2

import openerp
from openerp.tools.view_validation import *

invalid_form = etree.parse(StringIO('''\
<form>
    <label></label>
    <group>
        <div>
            <page></page>
            <label colspan="True"></label>
            <field></field>
        </div>
    </group>
    <notebook>
        <page>
            <group col="Two">
            <div>
                <label></label>
                <field colspan="Five"> </field>
                </div>
            </group>
        </page>
    </notebook>
</form>
''')).getroot()

valid_form = etree.parse(StringIO('''\
<form string="">
    <notebook>
        <label for=""></label>
        <page>
            <field name=""></field>
            <label string=""></label>
            <field name=""></field>
        </page>
        <page>
            <group colspan="5" col="2">
                <label for=""></label>
                <label string="" colspan="5"></label>
            </group>
        </page>
    </notebook>
</form>
''')).getroot()

invalid_graph = etree.parse(StringIO('''\
<graph>
      <group>
        <div>
          <field></field>
          <field></field>
        </div>
      </group>
</graph>
''')).getroot()

valid_graph = etree.parse(StringIO('''\
<graph string="">
    <field name=""></field>
    <field name=""></field>
</graph>
''')).getroot()

invalid_tree = etree.parse(StringIO('''\
<tree>
  <group>
    <div>
      <field></field>
      <field></field>
    </div>
  </group>
</tree>
''')).getroot()

valid_tree= etree.parse(StringIO('''\
<tree string="">
    <button></button>
    <label string=""></label>
    <field name=""></field>
    <field name=""></field>
    <field name=""></field>
    <button></button>
</tree>
''')).getroot()


class test_view_validation(unittest2.TestCase):
    """ Test the view validation code (but not the views themselves). """

    def test_page_validation(self):
        assert not valid_page_in_book(invalid_form)
        assert valid_page_in_book(valid_form)

    def test_all_field_validation(self):
        assert not  valid_att_in_field(invalid_form)
        assert  valid_att_in_field(valid_form)

    def test_all_label_validation(self):
        assert not  valid_att_in_label(invalid_form)
        assert  valid_att_in_label(valid_form)

    def test_form_string_validation(self):
        assert not valid_att_in_form(invalid_form)
        assert valid_att_in_form(valid_form)

    def test_graph_field_validation(self):
        assert not valid_field_in_graph(invalid_graph)
        assert valid_field_in_graph(valid_graph)

    def test_graph_string_validation(self):
        assert not valid_field_in_graph(invalid_graph)
        assert valid_field_in_graph(valid_graph)

    def test_tree_field_validation(self):
        assert not valid_field_in_tree(invalid_tree)
        assert valid_field_in_tree(valid_tree)

    def test_tree_string_validation(self):
        assert not valid_field_in_tree(invalid_tree)
        assert valid_field_in_tree(valid_tree)

    def test_colspan_datatype_validation(self):
        assert not valid_type_in_colspan(invalid_form)
        assert valid_type_in_colspan(valid_form)

    def test_col_datatype_validation(self):
        assert not valid_type_in_col(invalid_form)
        assert valid_type_in_col(valid_form)

    def test_form_view(self):
        assert not valid_view(invalid_form)
        assert valid_view(valid_form)

{'fraction_non_alphanumeric': 0.13318747436072748, 'fraction_numerical': 0.0016409134418159442, 'mean_word_length': 2.6772247360482653, 'pattern_counts': {'":': 0, '<': 179, '<?xml version=': 0, '>': 181, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '1350987', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2298, 'n_words': 446}