Commit 476afad3 authored by Jérome Perrin's avatar Jérome Perrin

CodingStyle: verify that business template re-exporting is stable

re-exporting a business template that's just installed should not be
different
parent 9dadb6dd
...@@ -28,9 +28,13 @@ ...@@ -28,9 +28,13 @@
############################################################################## ##############################################################################
import collections import collections
import difflib
import filecmp
import fnmatch
import glob import glob
import os import os
import tarfile import shutil
import tempfile
from Acquisition import aq_base from Acquisition import aq_base
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -105,29 +109,75 @@ class CodingStyleTestCase(ERP5TypeTestCase): ...@@ -105,29 +109,75 @@ class CodingStyleTestCase(ERP5TypeTestCase):
for business_template in self._getTestedBusinessTemplateValueList(): for business_template in self._getTestedBusinessTemplateValueList():
self.assertEqual(business_template.BusinessTemplate_getPythonSourceCodeMessageList(), []) self.assertEqual(business_template.BusinessTemplate_getPythonSourceCodeMessageList(), [])
# Paths for which we ignore differences when re-exporting business templates
rebuild_business_template_ignored_path = """
# portal_transforms seem to be always different TODO: really ?
erp5_core/ToolTemplateItem/portal_transforms.xml
# Empty messages are exported in message catalog, so they can be different because of
# empty messages. Reindexing during creation for example insert entries for all workflow
# states, so this change often.
*/MessageTranslationTemplateItem/*/*/translation.po
"""
def test_rebuild_business_template(self): def test_rebuild_business_template(self):
"""Try to rebuild business template to catch packaging errors. """Try to rebuild business template to catch packaging errors and make sur output is stable.
""" """
self.maxDiff = None
template_tool = self.portal.portal_templates template_tool = self.portal.portal_templates
for bt_title in self.getTestedBusinessTemplateList(): for bt_title in self.getTestedBusinessTemplateList():
bt = template_tool.getInstalledBusinessTemplate(bt_title, strict=True) bt = template_tool.getInstalledBusinessTemplate(bt_title, strict=True)
# make sure we can rebuild # make sure we can rebuild
bt.build() bt.build()
# check we don't add or remove members. # Compute the differences between the reference business template
# first, build a set of files that were on the original business template repository # from the working copy and the newly exported business template.
base_path, local_path = self.portal.portal_templates.getLastestBTOnRepos(bt_title) bt_base_path, bt_local_path = self.portal.portal_templates.getLastestBTOnRepos(bt_title)
existing_files = set([os.path.relpath(y, base_path) bt_dir = os.path.join(bt_base_path, bt_local_path)
for x in os.walk(os.path.join(base_path, local_path)) export_base_path = tempfile.mkdtemp()
for y in glob.glob(os.path.join(x[0], '*')) if os.path.isfile(y)]) self.addCleanup(shutil.rmtree, export_base_path)
export_dir = os.path.join(export_base_path, bt_local_path)
# then compare this with the files in the newly exported business template. bt.export(export_dir, local=True)
bt_file = bt.export()
bt_file.seek(0) # XXX this StringIO was already read... ignored_paths = {
new_files = set(tarfile.open(fileobj=bt_file, mode='r:gz').getnames()) p.strip() for p in self.rebuild_business_template_ignored_path.splitlines()
if p and not p.strip().startswith("#")}
diff_line_list = []
def get_differences(dcmp, base):
for name in dcmp.left_only:
yield 'removed: ' + os.path.join(base, name)
for name in dcmp.right_only:
yield 'added: ' + os.path.join(base, name)
for name in dcmp.funny_files:
yield 'funny: ' + os.path.join(base, name)
for name in dcmp.diff_files:
path = os.path.join(base, name)
if not any(fnmatch.fnmatch(path, ignored_path) for ignored_path in ignored_paths):
yield 'modified: ' + path
with open(os.path.join(bt_base_path, path)) as ff, \
open(os.path.join(export_base_path, path)) as tf:
diff_line_list.extend(
difflib.unified_diff(
ff.readlines(),
tf.readlines(),
os.path.join('git', path),
os.path.join('bt5', path),
))
diff_line_list.append('\n')
for sub_path, sub_dcmp in dcmp.subdirs.iteritems():
for diff in get_differences(sub_dcmp, os.path.join(base, sub_path)):
yield diff
diff_files = list(get_differences(filecmp.dircmp(bt_dir, export_dir), bt_local_path))
# dump a diff in log directory, to help debugging
from Products.ERP5Type.tests.runUnitTest import log_directory
if log_directory and diff_line_list:
with open(os.path.join(log_directory, '%s.diff' % self.id()), 'w') as f:
f.writelines(diff_line_list)
self.assertEqual(diff_files, [])
self.maxDiff = None
self.assertEqual(existing_files, new_files)
def test_run_upgrader(self): def test_run_upgrader(self):
# Check that pre and post upgrade do not raise problems. # Check that pre and post upgrade do not raise problems.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment