From a338fa6478f0945d4846573dc0818adead78b346 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Fri, 9 Aug 2019 16:31:29 +0200 Subject: [PATCH] Validate xml files definition on tests Update tryton.rnc format and use grouped attribute on message.xml issue8556 review272001002 --- 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(-) diff --git a/trytond/ir/calendar_.xml b/trytond/ir/calendar_.xml index 91b7cc5294..ff8345632e 100644 --- a/trytond/ir/calendar_.xml +++ b/trytond/ir/calendar_.xml @@ -2,7 +2,7 @@ - + January diff --git a/trytond/ir/message.xml b/trytond/ir/message.xml index 923d308239..ae5b44cb2d 100644 --- a/trytond/ir/message.xml +++ b/trytond/ir/message.xml @@ -29,7 +29,7 @@ this repository contains the full copyright notices and license terms. --> - + ID must be positive. diff --git a/trytond/res/message.xml b/trytond/res/message.xml index 300e88dc92..253beeaa72 100644 --- a/trytond/res/message.xml +++ b/trytond/res/message.xml @@ -2,7 +2,7 @@ - + The password is too short. diff --git a/trytond/tests/test_tryton.py b/trytond/tests/test_tryton.py index 00579edb3d..884889b5b7 100644 --- a/trytond/tests/test_tryton.py +++ b/trytond/tests/test_tryton.py @@ -9,6 +9,7 @@ import subprocess 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.pool import Pool, isregisteredby 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 @@ class ModuleTestCase(unittest.TestCase): '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 --git a/trytond/tryton.rnc b/trytond/tryton.rnc index fe87698000..c8d0e2766b 100644 --- a/trytond/tryton.rnc +++ b/trytond/tryton.rnc @@ -7,7 +7,7 @@ attlist.data &= [ 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 ref { text }? 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 --git a/trytond/tryton.rng b/trytond/tryton.rng index ea4c9c5901..8ee0abd185 100644 --- a/trytond/tryton.rng +++ b/trytond/tryton.rng @@ -48,10 +48,12 @@ - - depends - - + + + depends + + + @@ -141,6 +143,14 @@ + + + + depends + + + + menuitem