From 1a6134dcbd78ca20391654d73208a2f9afa37cbe Mon Sep 17 00:00:00 2001 From: Stephan Geulette Date: Tue, 2 Oct 2018 08:45:08 +0200 Subject: [PATCH 1/2] Display titles in diff of zope.schema.List using vocabulary --- CHANGES.rst | 12 +-- Products/CMFDiffTool/ListDiff.py | 44 +++++++--- Products/CMFDiffTool/testing.py | 8 ++ Products/CMFDiffTool/tests/testListDiff.py | 99 ++++++++++++++++++++-- buildout.cfg | 7 +- 5 files changed, 141 insertions(+), 29 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 82b61a7..d49b66c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,18 +4,10 @@ Changelog 3.2.2 (unreleased) ------------------ -Breaking changes: - -- *add item here* - -New features: - -- *add item here* - Bug fixes: -- *add item here* - +- Display titles in diff of zope.schema.List using vocabulary + [sgeulette] 3.2.1 (2018-09-23) ------------------ diff --git a/Products/CMFDiffTool/ListDiff.py b/Products/CMFDiffTool/ListDiff.py index edfa344..638dcd4 100644 --- a/Products/CMFDiffTool/ListDiff.py +++ b/Products/CMFDiffTool/ListDiff.py @@ -1,34 +1,58 @@ # -*- coding: utf-8 -*- from AccessControl.class_init import InitializeClass +from plone.dexterity.interfaces import IDexterityContent +from Products.CMFDiffTool.choicediff import get_field_object +from Products.CMFDiffTool.choicediff import title_or_value from Products.CMFDiffTool.FieldDiff import FieldDiff from six.moves import range -def chk_hashable(value): - try: - hash(value) - except TypeError as e: - value = repr(e) + ": " + repr(value) - return value - - class ListDiff(FieldDiff): """Text difference""" meta_type = 'List Diff' + def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None, + field_label=None, schemata=None): + FieldDiff.__init__(self, obj1, obj2, field, id1, id2, field_name, + field_label, schemata) + self._vocabulary = None + + # Tries to find a vocabulary. First we need to find an object and + # the field instance. + obj = obj1 if (obj1 is not None) else obj2 + field_name = field_name or field + if obj and field_name and IDexterityContent.providedBy(obj): + field_instance = get_field_object(obj, field_name) + if field_instance is not None: + # Binding the field to an object will construct the vocabulary + # using a factory if necessary. + try: + self._vocabulary = field_instance.value_type.bind(obj).vocabulary + except: + pass + + def chk_hashable(self, value): + if self._vocabulary is not None: + value = title_or_value(self._vocabulary, value) + try: + hash(value) + except TypeError as e: + value = repr(e) + ": " + repr(value) + return value + def _parseField(self, value, filename=None): """Parse a field value in preparation for diffing""" if type(value) is list or type(value) is tuple: values = [] for v in value: - values.append(chk_hashable(v)) + values.append(self.chk_hashable(v)) return values else: if type(value) is set: return list(value) else: - return [chk_hashable(value)] + return [self.chk_hashable(value)] class RelationListDiff(FieldDiff): diff --git a/Products/CMFDiffTool/testing.py b/Products/CMFDiffTool/testing.py index f909170..4603345 100644 --- a/Products/CMFDiffTool/testing.py +++ b/Products/CMFDiffTool/testing.py @@ -17,6 +17,7 @@ VOCABULARY_TUPLES = [ (u'first_value', u'First Title'), (u'second_value', None), + (u'third_value', u'Third Title'), ] VOCABULARY = SimpleVocabulary( @@ -82,6 +83,13 @@ def setUpPloneSite(self, portal): False Products.CMFDiffTool.testing.VOCABULARY + + Choices + False + + Products.CMFDiffTool.testing.VOCABULARY + + ''' diff --git a/Products/CMFDiffTool/tests/testListDiff.py b/Products/CMFDiffTool/tests/testListDiff.py index e8d95a9..4d71463 100644 --- a/Products/CMFDiffTool/tests/testListDiff.py +++ b/Products/CMFDiffTool/tests/testListDiff.py @@ -3,10 +3,13 @@ # CMFDiffTool tests # from os import linesep -from plone.app.testing import PLONE_INTEGRATION_TESTING +from plone.app.testing import setRoles +from plone.app.testing import TEST_USER_ID +from Products.CMFDiffTool import testing +from Products.CMFDiffTool.choicediff import title_or_value +from Products.CMFDiffTool.interfaces import IDifference from Products.CMFDiffTool.ListDiff import ListDiff -from unittest import TestCase - +from Products.CMFDiffTool.tests.BaseTestCase import BaseDXTestCase _marker = [] @@ -27,14 +30,26 @@ class D: attribute = {"a": 1, "b": 2, "c": 3} -class TestListDiff(TestCase): +class TestListDiff(BaseDXTestCase): """Test the ListDiff class""" - layer = PLONE_INTEGRATION_TESTING + def setUp(self): + self.portal = self.layer['portal'] + setRoles(self.portal, TEST_USER_ID, ['Manager']) + self.portal.invokeFactory( + testing.TEST_CONTENT_TYPE_ID, + 'obj1', + ) + self.portal.invokeFactory( + testing.TEST_CONTENT_TYPE_ID, + 'obj2', + ) + + self.obj1 = self.portal['obj1'] + self.obj2 = self.portal['obj2'] def testInterface(self): """Ensure that tool instances implement the portal_diff interface""" - from Products.CMFDiffTool.interfaces.portal_diff import IDifference self.assertTrue(IDifference.implementedBy(ListDiff)) def testInvalidValue(self): @@ -112,6 +127,76 @@ def test_inline_diff(self): diff = ListDiff(a, b, 'attribute') self.assertEqual(diff.inline_diff(), expected) + def test_inline_diff_vocabulary(self): + # unchanged, with vocabulary title + expected = u'
First Title
' + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0]], + [testing.VOCABULARY_TUPLES[0][0]], True, expected) + # unchanged, without vocabulary title + expected = u'
second_value
' + self._test_diff_list([testing.VOCABULARY_TUPLES[1][0]], + [testing.VOCABULARY_TUPLES[1][0]], True, expected) + # changed: add value, with vocabulary title + expected = u'''
+
+
First Title
+
''' + self._test_diff_list([], + [testing.VOCABULARY_TUPLES[0][0]], False, expected) + # changed: replaced unique value by another one, displaying titles + expected = u'''
+
First Title
+
+
+
+
+
Third Title
+
''' + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0]], + [testing.VOCABULARY_TUPLES[2][0]], False, expected) + # changed: replaced multiple values by others, displaying titles + expected = u'''
+
First Title
+
+
+
second_value
+
+
+
Third Title
+
''' + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], + [testing.VOCABULARY_TUPLES[1][0], testing.VOCABULARY_TUPLES[2][0]], False, expected) + # changed: replaced multiple values by others, displaying titles + expected = u'''
+
+
Third Title
+
+
First Title
+
+
second_value
+
+
''' + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], + [testing.VOCABULARY_TUPLES[2][0], testing.VOCABULARY_TUPLES[0][0]], False, expected) + # changed: removed values, displaying titles + expected = u'''
+
First Title
+
+
+
+
second_value
+
+
''' + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], + [], False, expected) + + def _test_diff_list(self, value1, value2, same, expected): + self.obj1.choices = value1 + self.obj2.choices = value2 + diff = ListDiff(self.obj1, self.obj2, 'choices') + self.assertEqual(diff.same, same) + self.assertEqual(diff.inline_diff(), expected) + def testGetLineDictDiffsSame(self): """test getLineDiffs() method with dict same value""" c = C() @@ -125,4 +210,4 @@ def testGetLineDictDiffsDifferent(self): d = D() diff = ListDiff(c, d, 'attribute') expected = [('replace', 0, 1, 0, 1)] - self.assertEqual(diff.getLineDiffs(), expected) \ No newline at end of file + self.assertEqual(diff.getLineDiffs(), expected) diff --git a/buildout.cfg b/buildout.cfg index d30eab7..08c08e8 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -1,7 +1,6 @@ [buildout] extends = - https://raw.github.com/collective/buildout.plonetest/master/test-4.3.x.cfg - plone-4.3.x.cfg + https://raw.github.com/collective/buildout.plonetest/master/test-5.x.cfg package-name = Products.CMFDiffTool package-extras = [test] test-eggs = Pillow @@ -19,6 +18,10 @@ allow-hosts = effbot.org dist.plone.org +[test] +eggs += + ipdb + [omelette] recipe = collective.recipe.omelette eggs = ${test:eggs} From 7221805aafe3f969febea65ea9bac596a587d231 Mon Sep 17 00:00:00 2001 From: Stephan Geulette Date: Tue, 2 Oct 2018 09:44:18 +0200 Subject: [PATCH 2/2] Flake8 corrections --- .gitignore | 2 ++ CHANGES.rst | 2 ++ Products/CMFDiffTool/ATCompoundDiff.py | 1 + Products/CMFDiffTool/BaseDiff.py | 13 ++++---- Products/CMFDiffTool/BinaryDiff.py | 3 +- Products/CMFDiffTool/CMFDTHtmlDiff.py | 1 + Products/CMFDiffTool/CMFDiffTool.py | 3 +- Products/CMFDiffTool/FieldDiff.py | 2 +- Products/CMFDiffTool/ListDiff.py | 32 ++++++++++--------- Products/CMFDiffTool/TextDiff.py | 6 ++-- Products/CMFDiffTool/__init__.py | 2 +- Products/CMFDiffTool/choicediff.py | 1 + Products/CMFDiffTool/dexteritydiff.py | 5 +-- Products/CMFDiffTool/namedfile.py | 6 ++-- Products/CMFDiffTool/testing.py | 8 +++-- .../CMFDiffTool/tests/testATCompoundDiff.py | 15 +++++---- Products/CMFDiffTool/tests/testChangeSet.py | 6 ++-- Products/CMFDiffTool/tests/testFieldDiff.py | 6 ++-- Products/CMFDiffTool/tests/testListDiff.py | 31 +++++++++++------- Products/CMFDiffTool/tests/testTextDiff.py | 2 -- Products/CMFDiffTool/tests/test_binarydiff.py | 12 +++---- .../CMFDiffTool/tests/test_dexteritydiff.py | 7 ++-- .../CMFDiffTool/tests/test_filelistdiff.py | 16 +++++----- buildout.cfg | 2 +- 24 files changed, 107 insertions(+), 77 deletions(-) diff --git a/.gitignore b/.gitignore index 6f0c371..eccadf0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ *.py[co] build dist +include/ +lib/ *.mo .installed.cfg bin/ diff --git a/CHANGES.rst b/CHANGES.rst index d49b66c..7bcc6bc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,8 @@ Bug fixes: - Display titles in diff of zope.schema.List using vocabulary [sgeulette] +- Flake8 corrections + [sgeulette] 3.2.1 (2018-09-23) ------------------ diff --git a/Products/CMFDiffTool/ATCompoundDiff.py b/Products/CMFDiffTool/ATCompoundDiff.py index dbfd605..bc9b9f7 100644 --- a/Products/CMFDiffTool/ATCompoundDiff.py +++ b/Products/CMFDiffTool/ATCompoundDiff.py @@ -126,4 +126,5 @@ def getFields(self, obj1, obj2): 'schemata': schemata_name}) return fields + InitializeClass(ATCompoundDiff) diff --git a/Products/CMFDiffTool/BaseDiff.py b/Products/CMFDiffTool/BaseDiff.py index e951c7a..1ab004a 100644 --- a/Products/CMFDiffTool/BaseDiff.py +++ b/Products/CMFDiffTool/BaseDiff.py @@ -4,8 +4,8 @@ Calculate differences between content objects """ -from Acquisition import aq_base from AccessControl.class_init import InitializeClass +from Acquisition import aq_base from plone.dexterity.interfaces import IDexterityContent from Products.CMFDiffTool import CMFDiffToolMessageFactory as _ from Products.CMFDiffTool.interfaces import IDifference @@ -63,7 +63,7 @@ def applyChanges(self, ob): def filenameTitle(self, filename): """Translate the filename leading text """ - msg = _(u"Filename: ${filename}", + msg = _(u'Filename: ${filename}', mapping={'filename': filename}) return translate(msg) @@ -73,8 +73,8 @@ def _getValue(ob, field, field_name, convert_to_str=True): # grab it *with* acquisition, so things like ComputedAttribute # will work if IDexterityContent.providedBy(ob) and field: - # we need a special handling for subjects because the field is stored as - # `subject` attribute but the schema name is `subjects` + # we need a special handling for subjects because the field is stored + # as `subject` attribute but the schema name is `subjects` # see plone.app.dexterity.behaviors.metadata.ICategorization and # plone.dexterity.content.DexterityContent if field == 'subjects': @@ -105,7 +105,7 @@ def _getValue(ob, field, field_name, convert_to_str=True): if isinstance(val, RelationValue): try: obj = val.to_object - except: + except Exception: obj = None new_value.append(obj) else: @@ -117,7 +117,7 @@ def _getValue(ob, field, field_name, convert_to_str=True): if isinstance(value, RelationValue): try: obj = value.to_object - except: + except Exception: obj = None value = obj @@ -131,4 +131,5 @@ def _getValue(ob, field, field_name, convert_to_str=True): return value + InitializeClass(BaseDiff) diff --git a/Products/CMFDiffTool/BinaryDiff.py b/Products/CMFDiffTool/BinaryDiff.py index c4a5e1e..288b1f3 100644 --- a/Products/CMFDiffTool/BinaryDiff.py +++ b/Products/CMFDiffTool/BinaryDiff.py @@ -51,10 +51,11 @@ def inline_diff(self): html.append( self.inlinediff_fmt % (css_class, self.filenameTitle(self.oldFilename), - self.filenameTitle(self.newFilename)) + self.filenameTitle(self.newFilename)), ) if html: return linesep.join(html) + InitializeClass(BinaryDiff) diff --git a/Products/CMFDiffTool/CMFDTHtmlDiff.py b/Products/CMFDiffTool/CMFDTHtmlDiff.py index 45dde7f..40edf65 100644 --- a/Products/CMFDiffTool/CMFDTHtmlDiff.py +++ b/Products/CMFDiffTool/CMFDTHtmlDiff.py @@ -28,4 +28,5 @@ def _parseField(self, value, filename=None): value = getattr(value, 'raw', value) return TextDiff._parseField(self, value, filename) + InitializeClass(CMFDTHtmlDiff) diff --git a/Products/CMFDiffTool/CMFDiffTool.py b/Products/CMFDiffTool/CMFDiffTool.py index 7b2f05f..ef302f8 100644 --- a/Products/CMFDiffTool/CMFDiffTool.py +++ b/Products/CMFDiffTool/CMFDiffTool.py @@ -4,8 +4,8 @@ Calculate differences between content objects """ from AccessControl import ClassSecurityInfo -from Acquisition import aq_base from AccessControl.class_init import InitializeClass +from Acquisition import aq_base from OFS.SimpleItem import SimpleItem from Products.CMFCore.permissions import ManagePortal from Products.CMFCore.utils import registerToolInterface @@ -177,5 +177,6 @@ def unregisterDiffType(klass): del CMFDiffTool._difftypes[klass.meta_type] + InitializeClass(CMFDiffTool) registerToolInterface('portal_diff', IDiffTool) diff --git a/Products/CMFDiffTool/FieldDiff.py b/Products/CMFDiffTool/FieldDiff.py index 2a7691f..2c56271 100644 --- a/Products/CMFDiffTool/FieldDiff.py +++ b/Products/CMFDiffTool/FieldDiff.py @@ -27,7 +27,7 @@ def _parseField(self, value, filename=None): else: return [ self.filenameTitle(filename), - value + value, ] def getLineDiffs(self): diff --git a/Products/CMFDiffTool/ListDiff.py b/Products/CMFDiffTool/ListDiff.py index 638dcd4..de8ce7b 100644 --- a/Products/CMFDiffTool/ListDiff.py +++ b/Products/CMFDiffTool/ListDiff.py @@ -28,8 +28,9 @@ def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None, # Binding the field to an object will construct the vocabulary # using a factory if necessary. try: - self._vocabulary = field_instance.value_type.bind(obj).vocabulary - except: + self._vocabulary = field_instance.value_type.bind(obj).\ + vocabulary + except Exception: pass def chk_hashable(self, value): @@ -38,7 +39,7 @@ def chk_hashable(self, value): try: hash(value) except TypeError as e: - value = repr(e) + ": " + repr(value) + value = repr(e) + ': ' + repr(value) return value def _parseField(self, value, filename=None): @@ -65,7 +66,8 @@ class RelationListDiff(FieldDiff): """ def _parseField(self, value, filename=None): - """Take RelationValues and just return the target UID so we can compare""" + """ Take RelationValues and just return the target UID + so we can compare """ if filename is None: # Since we only want to compare a single field, make a @@ -74,7 +76,7 @@ def _parseField(self, value, filename=None): else: return [ self.filenameTitle(filename), - ['/'.join(val.getPhysicalPath()) for val in value] + ['/'.join(val.getPhysicalPath()) for val in value], ] def inline_diff(self): @@ -89,27 +91,27 @@ def inline_diff(self): obj_title = obj.Title() obj_url = obj.absolute_url() r.append(inlinediff_fmt % - (css_class, "diff_sub", obj_url, obj_title)) + (css_class, 'diff_sub', obj_url, obj_title)) for i in range(blo, bhi): obj = self.newValue[i] obj_title = obj.Title() obj_url = obj.absolute_url() r.append(inlinediff_fmt % - (css_class, "diff_add", obj_url, obj_title)) + (css_class, 'diff_add', obj_url, obj_title)) elif tag == 'delete': for i in range(alo, ahi): obj = self.oldValue[i] obj_title = obj.Title() obj_url = obj.absolute_url() r.append(inlinediff_fmt % - (css_class, "diff_sub", obj_url, obj_title)) + (css_class, 'diff_sub', obj_url, obj_title)) elif tag == 'insert': for i in range(blo, bhi): obj = self.newValue[i] obj_title = obj.Title() obj_url = obj.absolute_url() r.append(inlinediff_fmt % - (css_class, "diff_add", obj_url, obj_title)) + (css_class, 'diff_add', obj_url, obj_title)) elif tag == 'equal': for i in range(alo, ahi): obj = self.oldValue[i] @@ -121,33 +123,33 @@ def inline_diff(self): return '\n'.join(r) def ndiff(self): - """Return a textual diff""" + """ Return a textual diff """ r = [] for tag, alo, ahi, blo, bhi in self.getLineDiffs(): if tag == 'replace': for i in range(alo, ahi): obj = self.oldValue[i] obj_url = obj.absolute_url() - r.append("- %s" % obj_url) + r.append('- %s' % obj_url) for i in range(blo, bhi): obj = self.newValue[i] obj_url = obj.absolute_url() - r.append("+ %s" % obj_url) + r.append('+ %s' % obj_url) elif tag == 'delete': for i in range(alo, ahi): obj = self.oldValue[i] obj_url = obj.absolute_url() - r.append("- %s" % obj_url) + r.append('- %s' % obj_url) elif tag == 'insert': for i in range(blo, bhi): obj = self.newValue[i] obj_url = obj.absolute_url() - r.append("+ %s" % obj_url) + r.append('+ %s' % obj_url) elif tag == 'equal': for i in range(alo, ahi): obj = self.oldValue[i] obj_url = obj.absolute_url() - r.append(" %s" % obj_url) + r.append(' %s' % obj_url) else: raise ValueError('unknown tag %r', tag) return '\n'.join(r) diff --git a/Products/CMFDiffTool/TextDiff.py b/Products/CMFDiffTool/TextDiff.py index 7494f44..56241fb 100644 --- a/Products/CMFDiffTool/TextDiff.py +++ b/Products/CMFDiffTool/TextDiff.py @@ -87,15 +87,16 @@ def inline_diff(self): if old_fname != new_fname: html.append( self.inlinediff_fmt % ('%s FilenameDiff' % css_class, - old_fname, new_fname) + old_fname, new_fname), ) if a != b: html.append( - self.inlinediff_fmt % (css_class, a, b) + self.inlinediff_fmt % (css_class, a, b), ) if html: return linesep.join(html) + InitializeClass(TextDiff) @@ -118,4 +119,5 @@ def _parseField(self, value, filename=None): return TextDiff._parseField(self, safe_unicode(value), filename) + InitializeClass(AsTextDiff) diff --git a/Products/CMFDiffTool/__init__.py b/Products/CMFDiffTool/__init__.py index 92c1e46..13937d9 100644 --- a/Products/CMFDiffTool/__init__.py +++ b/Products/CMFDiffTool/__init__.py @@ -47,5 +47,5 @@ def initialize(context): ToolInit('CMF Diff Tool', tools=tools, - icon='tool.gif' + icon='tool.gif', ).initialize(context) diff --git a/Products/CMFDiffTool/choicediff.py b/Products/CMFDiffTool/choicediff.py index 1a25410..0c69fcd 100644 --- a/Products/CMFDiffTool/choicediff.py +++ b/Products/CMFDiffTool/choicediff.py @@ -80,4 +80,5 @@ def _parseField(self, value, filename=None): return AsTextDiff._parseField(self, value, filename) + InitializeClass(ChoiceDiff) diff --git a/Products/CMFDiffTool/dexteritydiff.py b/Products/CMFDiffTool/dexteritydiff.py index c1b2ebc..e24bce4 100644 --- a/Products/CMFDiffTool/dexteritydiff.py +++ b/Products/CMFDiffTool/dexteritydiff.py @@ -122,7 +122,7 @@ def _diff_field(self, obj1, obj2, field, schema_name): id2=self.id2, field_name=field.getName(), field_label=field.title, - schemata=schema_name + schemata=schema_name, ) def _get_diff_type(self, field): @@ -176,6 +176,7 @@ def _compute_fields_order(self, obj): all_fields += [(form.fields[name].field, name) for name in form.fields] if form.groups: for group in form.groups: - all_fields += [(group.fields[name].field, name) for name in group.fields] + all_fields += [(group.fields[name].field, name) + for name in group.fields] return all_fields diff --git a/Products/CMFDiffTool/namedfile.py b/Products/CMFDiffTool/namedfile.py index 4666ef5..5ddd595 100644 --- a/Products/CMFDiffTool/namedfile.py +++ b/Products/CMFDiffTool/namedfile.py @@ -62,7 +62,7 @@ def __init__(self, obj1, obj2, field, id1=None, id2=None, field_name=None, def _parseField(self, value, filename=None): return [ '' if (value is None) - else named_file_as_str(NamedFile(data=value, filename=filename)) + else named_file_as_str(NamedFile(data=value, filename=filename)), ] def inline_diff(self): @@ -72,6 +72,7 @@ def inline_diff(self): return '' if self.same else self.inlinediff_fmt % (css_class, old, new) + InitializeClass(NamedFileBinaryDiff) @@ -131,7 +132,7 @@ def inline_diff(self): def is_same_dict(d1, d2): return is_same( - d1['data'], d1['filename'], d2['data'], d2['filename'] + d1['data'], d1['filename'], d2['data'], d2['filename'], ) return '\n'.join([ @@ -140,4 +141,5 @@ def is_same_dict(d1, d2): % (css_class, d_old['repr'], d_new['repr']) ) for (d_old, d_new) in zip(old_data, new_data)]) + InitializeClass(NamedFileListDiff) diff --git a/Products/CMFDiffTool/testing.py b/Products/CMFDiffTool/testing.py index 4603345..b183c9f 100644 --- a/Products/CMFDiffTool/testing.py +++ b/Products/CMFDiffTool/testing.py @@ -43,7 +43,7 @@ def setUpPloneSite(self, portal): sm.registerUtility( component=vocabulary_factory, provided=IVocabularyFactory, - name=u'Products.CMFDiffTool.testing.VOCABULARY' + name=u'Products.CMFDiffTool.testing.VOCABULARY', ) fti = DexterityFTI( @@ -92,10 +92,11 @@ def setUpPloneSite(self, portal): - ''' + ''', ) types_tool._setObject(TEST_CONTENT_TYPE_ID, fti) + PACKAGE_DX_FIXTURE = DXLayer() if six.PY2: @@ -115,7 +116,8 @@ def setUpZope(self, app, configurationContext): PACKAGE_AT_FIXTURE = ATLayer() CMFDiffToolATLayer = FunctionalTesting( - bases=(PACKAGE_AT_FIXTURE, ), name='Products.CMFDiffTool.AT:functional') + bases=(PACKAGE_AT_FIXTURE, ), + name='Products.CMFDiffTool.AT:functional') CMFDiffToolDXLayer = FunctionalTesting( diff --git a/Products/CMFDiffTool/tests/testATCompoundDiff.py b/Products/CMFDiffTool/tests/testATCompoundDiff.py index 5742ac5..9dd8e28 100644 --- a/Products/CMFDiffTool/tests/testATCompoundDiff.py +++ b/Products/CMFDiffTool/tests/testATCompoundDiff.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import six + if six.PY2: from .BaseTestCase import BaseATTestCase from Products.Archetypes import atapi @@ -11,14 +12,14 @@ from zope.interface import alsoProvides from zope.interface import noLongerProvides - class TestATCompoundDiff(BaseATTestCase): """Test the portal_diff tool""" def testCompoundDiff(self): first = self.folder.invokeFactory('Document', 'extended-document') first = self.folder[first] - second = self.folder.invokeFactory('Document', 'extended-document2') + second = self.folder.invokeFactory('Document', + 'extended-document2') second = self.folder[second] # Change a value first.setText('

Body1

', mimetype='text/html') @@ -68,7 +69,7 @@ def set(self, instance, value, **kwargs): noLongerProvides(instance, IHighlighted) class TestSchemaExtender(Extender): - adapts(ATDocument) + adapts(ATDocument) # noqa: D001 fields = [ HighlightedField('schemaextender_test', schemata='settings', @@ -78,13 +79,15 @@ class TestSchemaExtender(Extender): ), ] - """Ensure that tool instances implement the portal_diff interface""" + """ Ensure that tool instances implement the portal_diff + interface """ provideAdapter(TestSchemaExtender, - name=u"archetypes.schemaextender.tests") + name=u'archetypes.schemaextender.tests') first = self.folder.invokeFactory('Document', 'extended-document') first = self.folder[first] - second = self.folder.invokeFactory('Document', 'extended-document2') + second = self.folder.invokeFactory('Document', + 'extended-document2') second = self.folder[second] # Change the value alsoProvides(second, IHighlighted) diff --git a/Products/CMFDiffTool/tests/testChangeSet.py b/Products/CMFDiffTool/tests/testChangeSet.py index d5e9eb4..6b9206e 100644 --- a/Products/CMFDiffTool/tests/testChangeSet.py +++ b/Products/CMFDiffTool/tests/testChangeSet.py @@ -37,7 +37,8 @@ def setupTestObjects(self): self.folder.invokeFactory('Document', 'doc1', title='My Title') self.folder.manage_pasteObjects( self.folder.manage_copyObjects(['doc1'])) - cdd = DexterityCompoundDiff(self.folder['doc1'], self.folder['doc1'], '') + cdd = DexterityCompoundDiff(self.folder['doc1'], self.folder['doc1'], + '') self.len_diff = len(cdd._diffs) def setupTestFolders(self): @@ -220,7 +221,8 @@ def testChangeSetFolderComplex(self): # We don't have an orderable folder give up return - self.cs.computeDiff(self.folder['folder1'], self.folder['copy_of_folder1']) + self.cs.computeDiff(self.folder['folder1'], + self.folder['copy_of_folder1']) diffs = self.cs.getDiffs() self.assertEqual(len(diffs), 14) self.assertFalse(diffs[0].same) diff --git a/Products/CMFDiffTool/tests/testFieldDiff.py b/Products/CMFDiffTool/tests/testFieldDiff.py index 8400cab..e3976bb 100644 --- a/Products/CMFDiffTool/tests/testFieldDiff.py +++ b/Products/CMFDiffTool/tests/testFieldDiff.py @@ -27,10 +27,10 @@ def method(self): class U: - attribute = u"\xfcnicode value" + attribute = u'\xfcnicode value' def method(self): - return u"different method val\xfce" + return u'different method val\xfce' class TestFieldDiff(TestCase): @@ -121,7 +121,7 @@ def testDiffText(self): expected = '- value%s+ different value' % linesep fd = FieldDiff(a, b, 'attribute') self.assertEqual(fd.ndiff(), expected) - expected = u"- value%s+ \xfcnicode value" % linesep + expected = u'- value%s+ \xfcnicode value' % linesep fd = FieldDiff(a, uu, 'attribute') self.assertEqual(fd.ndiff(), expected) diff --git a/Products/CMFDiffTool/tests/testListDiff.py b/Products/CMFDiffTool/tests/testListDiff.py index 4d71463..7844ab3 100644 --- a/Products/CMFDiffTool/tests/testListDiff.py +++ b/Products/CMFDiffTool/tests/testListDiff.py @@ -6,11 +6,11 @@ from plone.app.testing import setRoles from plone.app.testing import TEST_USER_ID from Products.CMFDiffTool import testing -from Products.CMFDiffTool.choicediff import title_or_value from Products.CMFDiffTool.interfaces import IDifference from Products.CMFDiffTool.ListDiff import ListDiff from Products.CMFDiffTool.tests.BaseTestCase import BaseDXTestCase + _marker = [] @@ -23,11 +23,11 @@ class B: class C: - attribute = {"a": 1, "b": 2} + attribute = {'a': 1, 'b': 2} class D: - attribute = {"a": 1, "b": 2, "c": 3} + attribute = {'a': 1, 'b': 2, 'c': 3} class TestListDiff(BaseDXTestCase): @@ -66,7 +66,7 @@ def testInvalidValue(self): diff = ListDiff(a, b, 'attribute') self.assertEqual([('insert', 0, 0, 0, 1)], diff.getLineDiffs()) - b.attribute = "" + b.attribute = '' diff = ListDiff(a, b, 'attribute') self.assertEqual([('insert', 0, 0, 0, 1)], diff.getLineDiffs()) @@ -142,7 +142,8 @@ def test_inline_diff_vocabulary(self):
First Title
''' self._test_diff_list([], - [testing.VOCABULARY_TUPLES[0][0]], False, expected) + [testing.VOCABULARY_TUPLES[0][0]], + False, expected) # changed: replaced unique value by another one, displaying titles expected = u'''
First Title
@@ -153,7 +154,8 @@ def test_inline_diff_vocabulary(self):
Third Title
''' self._test_diff_list([testing.VOCABULARY_TUPLES[0][0]], - [testing.VOCABULARY_TUPLES[2][0]], False, expected) + [testing.VOCABULARY_TUPLES[2][0]], + False, expected) # changed: replaced multiple values by others, displaying titles expected = u'''
First Title
@@ -164,8 +166,11 @@ def test_inline_diff_vocabulary(self):
Third Title
''' - self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], - [testing.VOCABULARY_TUPLES[1][0], testing.VOCABULARY_TUPLES[2][0]], False, expected) + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], + testing.VOCABULARY_TUPLES[1][0]], + [testing.VOCABULARY_TUPLES[1][0], + testing.VOCABULARY_TUPLES[2][0]], + False, expected) # changed: replaced multiple values by others, displaying titles expected = u'''
@@ -176,8 +181,11 @@ def test_inline_diff_vocabulary(self):
second_value
''' - self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], - [testing.VOCABULARY_TUPLES[2][0], testing.VOCABULARY_TUPLES[0][0]], False, expected) + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], + testing.VOCABULARY_TUPLES[1][0]], + [testing.VOCABULARY_TUPLES[2][0], + testing.VOCABULARY_TUPLES[0][0]], + False, expected) # changed: removed values, displaying titles expected = u'''
First Title
@@ -187,7 +195,8 @@ def test_inline_diff_vocabulary(self):
second_value
''' - self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], testing.VOCABULARY_TUPLES[1][0]], + self._test_diff_list([testing.VOCABULARY_TUPLES[0][0], + testing.VOCABULARY_TUPLES[1][0]], [], False, expected) def _test_diff_list(self, value1, value2, same, expected): diff --git a/Products/CMFDiffTool/tests/testTextDiff.py b/Products/CMFDiffTool/tests/testTextDiff.py index 542d263..feb7138 100644 --- a/Products/CMFDiffTool/tests/testTextDiff.py +++ b/Products/CMFDiffTool/tests/testTextDiff.py @@ -5,8 +5,6 @@ from Products.CMFDiffTool.TextDiff import TextDiff from unittest import TestCase -import six - _marker = [] diff --git a/Products/CMFDiffTool/tests/test_binarydiff.py b/Products/CMFDiffTool/tests/test_binarydiff.py index 51bff32..b224e96 100644 --- a/Products/CMFDiffTool/tests/test_binarydiff.py +++ b/Products/CMFDiffTool/tests/test_binarydiff.py @@ -16,14 +16,14 @@ def test_should_detect_different_filename(self): self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj1', - file=NamedFile(data='contents', filename=u'blah.txt') + file=NamedFile(data='contents', filename=u'blah.txt'), ) obj1 = self.portal['obj1'] self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj2', - file=NamedFile(data='contents', filename=u'bleh.txt') + file=NamedFile(data='contents', filename=u'bleh.txt'), ) obj2 = self.portal['obj2'] @@ -36,14 +36,14 @@ def test_should_detect_different_data(self): self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj1', - file=NamedFile(data='contents', filename=u'f.txt') + file=NamedFile(data='contents', filename=u'f.txt'), ) obj1 = self.portal['obj1'] self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj2', - file=NamedFile(data='different contents', filename=u'f.txt') + file=NamedFile(data='different contents', filename=u'f.txt'), ) obj2 = self.portal['obj2'] @@ -56,14 +56,14 @@ def test_should_detect_same_data_and_filename(self): self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj1', - file=NamedFile(data='contents', filename=u'f.txt') + file=NamedFile(data='contents', filename=u'f.txt'), ) obj1 = self.portal['obj1'] self.portal.invokeFactory( testing.TEST_CONTENT_TYPE_ID, 'obj2', - file=NamedFile(data='contents', filename=u'f.txt') + file=NamedFile(data='contents', filename=u'f.txt'), ) obj2 = self.portal['obj2'] diff --git a/Products/CMFDiffTool/tests/test_dexteritydiff.py b/Products/CMFDiffTool/tests/test_dexteritydiff.py index 61a15f6..c75223b 100644 --- a/Products/CMFDiffTool/tests/test_dexteritydiff.py +++ b/Products/CMFDiffTool/tests/test_dexteritydiff.py @@ -13,7 +13,6 @@ from zope.intid.interfaces import IIntIds - class DexterityDiffTestCase(BaseDXTestCase): def setUp(self): @@ -26,7 +25,7 @@ def test_should_diff(self): 'obj1', title=u'Object 1', description=u'Desc 1', - text=u'Text 1' + text=u'Text 1', ) obj1 = self.portal['obj1'] @@ -34,7 +33,7 @@ def test_should_diff(self): testing.TEST_CONTENT_TYPE_ID, 'obj2', title=u'Object 2', - text=u'Text 2' + text=u'Text 2', ) obj2 = self.portal['obj2'] @@ -118,7 +117,7 @@ def test_should_provide_diff_for_related_fields(self): 'obj1', title=u'Object 1', description=u'Desc 1', - text=u'Text 1' + text=u'Text 1', ) obj1 = self.portal['obj1'] diff --git a/Products/CMFDiffTool/tests/test_filelistdiff.py b/Products/CMFDiffTool/tests/test_filelistdiff.py index f123a6d..0bd0a6d 100644 --- a/Products/CMFDiffTool/tests/test_filelistdiff.py +++ b/Products/CMFDiffTool/tests/test_filelistdiff.py @@ -19,42 +19,42 @@ def test_should_diff_file_lists_correctly(self): self._test_diff_files( [('data1', u'filename1')], [('data2', u'filename2')], - False + False, ) self._test_diff_files( [('data1', u'filename1'), ('datax', u'filenamex')], [('data1', u'filename1'), ('datay', u'filenamey')], - False + False, ) self._test_diff_files( [('data1', u'filename1'), ('datax', u'filenamex')], [('datax', u'filenamex'), ('data1', u'filename1')], - False + False, ) self._test_diff_files( [('data1', u'filename1')], [('data1', u'filename1'), ('datax', u'filenamex')], - False + False, ) self._test_diff_files( [('data1', u'filename1')], [('data1', u'filename1')], - True + True, ) self._test_diff_files( [('data1', u'filename1'), ('datax', u'filenamex')], [('data1', u'filename1'), ('datax', u'filenamex')], - True + True, ) self._test_diff_files( [('data1', u'filename1'), ('datax', u'filenamex')], None, - False + False, ) self._test_diff_files( [('data1', u'filename1'), ('datax', u'filenamex')], [], - False + False, ) self._test_diff_files(None, None, True) self._test_diff_files([], [], True) diff --git a/buildout.cfg b/buildout.cfg index 08c08e8..001d11e 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -29,7 +29,7 @@ eggs = ${test:eggs} [code-analysis] recipe = plone.recipe.codeanalysis [recommended] directory = ${buildout:directory}/Products -flake8-max-complexity = 20 +flake8-max-complexity = 22 # If todo markers are marked as problems, no todomarkers will be written # Don't show plone.api advertisement # Don't checko for % formatter