changeset c47bd36bed30 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=c47bd36bed30
description:
        Validate xml files definition on tests

        Update tryton.rnc format and use grouped attribute on message.xml

        issue8556
        review272001002
diffstat:

 trytond/ir/calendar_.xml     |   2 +-
 trytond/ir/message.xml       |   2 +-
 trytond/res/message.xml      |   2 +-
 trytond/tests/test_tryton.py |  21 ++++++++++++++++++++-
 trytond/tryton.rnc           |   3 ++-
 trytond/tryton.rng           |  18 ++++++++++++++----
 6 files changed, 39 insertions(+), 9 deletions(-)

diffs (136 lines):

diff -r b41f177074f5 -r c47bd36bed30 trytond/ir/calendar_.xml
--- a/trytond/ir/calendar_.xml  Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/ir/calendar_.xml  Fri Aug 09 16:31:29 2019 +0200
@@ -2,7 +2,7 @@
 <!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
 this repository contains the full copyright notices and license terms. -->
 <tryton>
-    <data group="1">
+    <data grouped="1">
         <record model="ir.calendar.month" id="January">
             <field name="index" eval="1"/>
             <field name="name">January</field>
diff -r b41f177074f5 -r c47bd36bed30 trytond/ir/message.xml
--- a/trytond/ir/message.xml    Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/ir/message.xml    Fri Aug 09 16:31:29 2019 +0200
@@ -29,7 +29,7 @@
         </record>
         <menuitem name="Messages" parent="menu_localization" 
action="act_message_form" id="menu_message_form" sequence="10"/>
     </data>
-    <data group="1">
+    <data grouped="1">
         <record model="ir.message" id="msg_id_positive">
             <field name="text">ID must be positive.</field>
         </record>
diff -r b41f177074f5 -r c47bd36bed30 trytond/res/message.xml
--- a/trytond/res/message.xml   Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/res/message.xml   Fri Aug 09 16:31:29 2019 +0200
@@ -2,7 +2,7 @@
 <!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
 this repository contains the full copyright notices and license terms. -->
 <tryton>
-    <data group="1">
+    <data grouped="1">
         <record model="ir.message" id="msg_password_length">
             <field name="text">The password is too short.</field>
         </record>
diff -r b41f177074f5 -r c47bd36bed30 trytond/tests/test_tryton.py
--- a/trytond/tests/test_tryton.py      Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/tests/test_tryton.py      Fri Aug 09 16:31:29 2019 +0200
@@ -9,6 +9,7 @@
 import sys
 import time
 import unittest
+from configparser import ConfigParser
 from functools import reduce
 from functools import wraps
 from itertools import chain
@@ -24,7 +25,7 @@
 from trytond import backend
 from trytond.model import Workflow, ModelSQL, ModelSingleton, ModelView, fields
 from trytond.model.fields import get_eval_fields, Function
-from trytond.tools import is_instance_method
+from trytond.tools import is_instance_method, file_open
 from trytond.transaction import Transaction
 from trytond.cache import Cache
 from trytond.config import config, parse_uri
@@ -633,6 +634,24 @@
                         'keys': set(states) - keys,
                         })
 
+    @with_transaction()
+    def test_xml_files(self):
+        "Test validity of the xml files of the module"
+        config = ConfigParser()
+        with file_open('%s/tryton.cfg' % self.module,
+                subdir='modules', mode='r', encoding='utf-8') as fp:
+            config.read_file(fp)
+        if not config.has_option('tryton', 'xml'):
+            return
+        with file_open('tryton.rng', subdir='', mode='rb') as fp:
+            rng = etree.parse(fp)
+        validator = etree.RelaxNG(etree=rng)
+        for xml_file in filter(None, config.get('tryton', 'xml').splitlines()):
+            with file_open('%s/%s' % (self.module, xml_file),
+                    subdir='modules', mode='rb') as fp:
+                tree = etree.parse(fp)
+            validator.assertValid(tree)
+
 
 def db_exist(name=DB_NAME):
     Database = backend.get('Database')
diff -r b41f177074f5 -r c47bd36bed30 trytond/tryton.rnc
--- a/trytond/tryton.rnc        Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/tryton.rnc        Fri Aug 09 16:31:29 2019 +0200
@@ -7,7 +7,7 @@
   [ a:defaultValue = "0" ] attribute noupdate { "0" | "1" }?
 attlist.data &=
   [ a:defaultValue = "0" ] attribute grouped { "0" | "1" }?
-attlist.data &= attribute depends { text }
+attlist.data &= attribute depends { text }?
 record = element record { attlist.record, field* }
 attlist.record &= attribute model { text }
 attlist.record &= attribute id { text }
@@ -20,6 +20,7 @@
 attlist.field &= attribute eval { text }?
 attlist.field &= attribute pyson { "0" | "1" }?
 attlist.field &= attribute type { "xml" }?
+attlist.field &= attribute depends { text }?
 menuitem = element menuitem { attlist.menuitem, empty }
 attlist.menuitem &= attribute id { text }
 attlist.menuitem &= attribute name { text }?
diff -r b41f177074f5 -r c47bd36bed30 trytond/tryton.rng
--- a/trytond/tryton.rng        Thu Aug 08 08:59:37 2019 +0200
+++ b/trytond/tryton.rng        Fri Aug 09 16:31:29 2019 +0200
@@ -48,10 +48,12 @@
     </optional>
   </define>
   <define name="attlist.data" combine="interleave">
-    <attribute>
-      <name ns="">depends</name>
-      <text/>
-    </attribute>
+    <optional>
+      <attribute>
+        <name ns="">depends</name>
+        <text/>
+      </attribute>
+    </optional>
   </define>
   <define name="record">
     <element>
@@ -141,6 +143,14 @@
       </attribute>
     </optional>
   </define>
+  <define name="attlist.field" combine="interleave">
+    <optional>
+      <attribute>
+        <name ns="">depends</name>
+        <text/>
+      </attribute>
+    </optional>
+  </define>
   <define name="menuitem">
     <element>
       <name ns="">menuitem</name>

Reply via email to