[PATCH 2 of 4 yams] [tests, flake8] Manual correction to make flake8 happy

Simon Chabot simon.chabot at logilab.fr
Fri Jan 17 18:32:20 CET 2020


# HG changeset patch
# User Simon Chabot <simon.chabot at logilab.fr>
# Date 1579280682 -3600
#      Fri Jan 17 18:04:42 2020 +0100
# Node ID e9da0ace7bdcf88da9de6f80e161701ffe843bea
# Parent  c60dbc99fb4b879816587cf3ab29b6778384ae8d
# Available At https://hg.logilab.org/review/yams
#              hg pull https://hg.logilab.org/review/yams -r e9da0ace7bdc
[tests, flake8] Manual correction to make flake8 happy

diff --git a/test/data/schema/State.py b/test/data/schema/State.py
--- a/test/data/schema/State.py
+++ b/test/data/schema/State.py
@@ -15,7 +15,7 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with yams. If not, see <http://www.gnu.org/licenses/>.
-from yams.buildobjs import (EntityType, RelationType, RelationDefinition,
+from yams.buildobjs import (EntityType, RelationType,
                             SubjectRelation, Int, String, Boolean)
 from yams.constraints import SizeConstraint, UniqueConstraint
 
diff --git a/test/unittest_constraints.py b/test/unittest_constraints.py
--- a/test/unittest_constraints.py
+++ b/test/unittest_constraints.py
@@ -20,8 +20,18 @@ from logilab.common.testlib import mock_
 
 import unittest
 
-from yams.constraints import *
-# after import *
+from yams.constraints import (
+    Attribute,
+    BoundaryConstraint,
+    FormatConstraint,
+    IntervalBoundConstraint,
+    NOW,
+    RegexpConstraint,
+    SizeConstraint,
+    StaticVocabularyConstraint,
+    TODAY,
+    UniqueConstraint,
+)
 from datetime import datetime, date, timedelta
 
 
diff --git a/test/unittest_reader.py b/test/unittest_reader.py
--- a/test/unittest_reader.py
+++ b/test/unittest_reader.py
@@ -53,28 +53,105 @@ class SchemaLoaderTC(TestCase):
     def test_load_schema(self):
         self.assertIsInstance(self.schema, Schema)
         self.assertEqual(self.schema.name, 'NoName')
-        self.assertListEqual(sorted(self.schema.entities()),
-                             ['Affaire', 'BigInt', 'Boolean', 'Bytes', 'Company',
-                              'Date', 'Datetest', 'Datetime', 'Decimal',
-                              'Division', 'EPermission', 'Eetype', 'Employee', 'Float', 'Int', 'Interval',
-                              'Note', 'Password', 'Person', 'Salaried', 'Societe', 'State', 'String',
-                              'Subcompany', 'Subdivision', 'TZDatetime', 'TZTime', 'Time', 'pkginfo'])
-        self.assertListEqual(sorted(self.schema.relations()),
-                             ['ad1', 'ad2', 'ad3', 'adel', 'ass', 'author', 'author_email',
-                              'concerne', 'copyright', 'cp',
-                              'd1', 'd2', 'date', 'datenaiss', 'debian_handler', 'description', 'division_of', 'dt1', 'dt2',
-                              'eid', 'evaluee', 'fax', 'final',
-                              'initial_state', 'inline_rel',
-                              'license', 'long_desc',
-                              'mailinglist', 'meta', 'modname',
-                              'name', 'next_state', 'nom', 'obj_wildcard',
-                              'para', 'prenom', 'promo',
-                              'ref', 'require_permission', 'rncs',
-                              'salary', 'sexe', 'short_desc', 'state_of', 'subcompany_of',
-                              'subdivision_of', 'subj_wildcard', 'sujet', 'sym_rel',
-                              't1', 't2', 'tel', 'test', 'titre', 'travaille', 'type',
-                              'version',
-                              'ville', 'web', 'works_for'])
+        self.assertListEqual(
+            sorted(self.schema.entities()),
+            [
+                'Affaire',
+                'BigInt',
+                'Boolean',
+                'Bytes',
+                'Company',
+                'Date',
+                'Datetest',
+                'Datetime',
+                'Decimal',
+                'Division',
+                'EPermission',
+                'Eetype',
+                'Employee',
+                'Float',
+                'Int',
+                'Interval',
+                'Note',
+                'Password',
+                'Person',
+                'Salaried',
+                'Societe',
+                'State',
+                'String',
+                'Subcompany',
+                'Subdivision',
+                'TZDatetime',
+                'TZTime',
+                'Time',
+                'pkginfo',
+            ],
+        )
+        self.assertListEqual(
+            sorted(self.schema.relations()),
+            [
+                'ad1',
+                'ad2',
+                'ad3',
+                'adel',
+                'ass',
+                'author',
+                'author_email',
+                'concerne',
+                'copyright',
+                'cp',
+                'd1',
+                'd2',
+                'date',
+                'datenaiss',
+                'debian_handler',
+                'description',
+                'division_of',
+                'dt1',
+                'dt2',
+                'eid',
+                'evaluee',
+                'fax',
+                'final',
+                'initial_state',
+                'inline_rel',
+                'license',
+                'long_desc',
+                'mailinglist',
+                'meta',
+                'modname',
+                'name',
+                'next_state',
+                'nom',
+                'obj_wildcard',
+                'para',
+                'prenom',
+                'promo',
+                'ref',
+                'require_permission',
+                'rncs',
+                'salary',
+                'sexe',
+                'short_desc',
+                'state_of',
+                'subcompany_of',
+                'subdivision_of',
+                'subj_wildcard',
+                'sujet',
+                'sym_rel',
+                't1',
+                't2',
+                'tel',
+                'test',
+                'titre',
+                'travaille',
+                'type',
+                'version',
+                'ville',
+                'web',
+                'works_for',
+            ],
+        )
 
     def test_eschema(self):
         eschema = self.schema.eschema('Societe')
@@ -185,7 +262,9 @@ class SchemaLoaderTC(TestCase):
         rschema = self.schema.rschema('initial_state')
         self.assertEqual(rschema.symmetric, False)
         self.assertEqual(
-            rschema.description, 'indicate which state should be used by default when an entity using states is created')
+            rschema.description,
+            'indicate which state should be used by default when an entity using states is created'
+        )
         self.assertEqual(rschema.final, False)
         self.assertListEqual(sorted(rschema.subjects()), ['Eetype'])
         self.assertListEqual(sorted(rschema.objects()), ['State'])
@@ -194,8 +273,10 @@ class SchemaLoaderTC(TestCase):
         self.assertEqual(rschema.symmetric, False)
         self.assertEqual(rschema.description, '')
         self.assertEqual(rschema.final, True)
-        self.assertListEqual(sorted(rschema.subjects()), [
-                             'Company', 'Division', 'EPermission', 'Eetype', 'State', 'Subcompany', 'Subdivision'])
+        self.assertListEqual(
+            sorted(rschema.subjects()),
+            ['Company', 'Division', 'EPermission', 'Eetype', 'State', 'Subcompany', 'Subdivision'],
+        )
         self.assertListEqual(sorted(rschema.objects()), ['String'])
 
     def test_cardinality(self):
@@ -287,13 +368,13 @@ class SchemaLoaderTC(TestCase):
                           'update': ('managers', 'owners',)})
 
 # def test_nonregr_using_tuple_as_relation_target(self):
-##         rschema = schema.rschema('see_also')
-##         self.assertEqual(rschema.symmetric, False)
-##         self.assertEqual(rschema.description, '')
-##         self.assertEqual(rschema.final, False)
-##         self.assertListEqual(sorted(rschema.subjects()), ['Employee'])
-##         self.assertListEqual(sorted(rschema.objects()), ['Company', 'Division'])
-##
+#          rschema = schema.rschema('see_also')
+#          self.assertEqual(rschema.symmetric, False)
+#          self.assertEqual(rschema.description, '')
+#          self.assertEqual(rschema.final, False)
+#          self.assertListEqual(sorted(rschema.subjects()), ['Employee'])
+#          self.assertListEqual(sorted(rschema.objects()), ['Company', 'Division'])
+#
 
 
 class SchemaLoaderModnamesTC(SchemaLoaderTC):
@@ -471,8 +552,13 @@ class SchemaLoaderTC2(TestCase):
 
         with self.assertRaises(BadSchemaDefinition) as cm:
             build_schema_from_namespace(locals().items())
-        self.assertEqual("conflicting values {'add': ()}/{'read': ()} for property __permissions__ of relation 'foo'",
-                         str(cm.exception))
+        self.assertEqual(
+            (
+                "conflicting values {'add': ()}/{'read': ()} "
+                "for property __permissions__ of relation 'foo'"
+            ),
+            str(cm.exception),
+        )
 
     def test_schema(self):
         class Anentity(EntityType):
@@ -488,15 +574,15 @@ class SchemaLoaderTC2(TestCase):
 
         schema = build_schema_from_namespace(locals().items())
         self.assertEqual('<builtin>', schema['Anentity'].package)
-        rel = schema['rel']
+        relation = schema['rel']
         self.assertEqual(True, rel.symmetric)
         self.assertEqual(True, rel.inlined)
         self.assertEqual('<builtin>', rel.package)
-        rdef1 = rel.rdef('Anentity', 'Anentity')
+        rdef1 = relation.rdef('Anentity', 'Anentity')
         self.assertEqual('subject', rdef1.composite)
         self.assertEqual('1*', rdef1.cardinality)
         self.assertEqual('<builtin>', rdef1.package)
-        rdef2 = rel.rdef('Anotherentity', 'Anentity')
+        rdef2 = relation.rdef('Anotherentity', 'Anentity')
         self.assertEqual('subject', rdef2.composite)
         self.assertEqual('1*', rdef2.cardinality)
         self.assertEqual('<builtin>', rdef2.package)
@@ -646,7 +732,7 @@ class ComputedSchemaTC(TestCase):
             object = 'Mafieu'
 
         with self.assertRaises(BadSchemaDefinition) as cm:
-            schema = build_schema_from_namespace(vars().items())
+            build_schema_from_namespace(vars().items())
         self.assertEqual('Cannot add relation definition "est_paye_par" '
                          'because an homonymous computed relation already '
                          'exists with rule "S travaille O"',
@@ -668,7 +754,7 @@ class ComputedSchemaTC(TestCase):
             inlined = True
 
         with self.assertRaises(BadSchemaDefinition) as cm:
-            schema = build_schema_from_namespace(vars().items())
+            build_schema_from_namespace(vars().items())
         self.assertEqual("Computed relation has no inlined attribute",
                          str(cm.exception))
 
@@ -690,7 +776,7 @@ class ComputedSchemaTC(TestCase):
             rule = ('S travaille O')
 
         with self.assertRaises(BadSchemaDefinition) as cm:
-            schema = build_schema_from_namespace(vars().items())
+            build_schema_from_namespace(vars().items())
         self.assertEqual(
             'Cannot set add/delete permissions on computed relation est_paye_par',
             str(cm.exception))
@@ -747,7 +833,7 @@ class ComputedSchemaTC(TestCase):
             formula = 'Any Z WHERE X oattr Z'
 
         with self.assertRaises(BadSchemaDefinition) as cm:
-            schema = build_schema_from_namespace(vars().items())
+            build_schema_from_namespace(vars().items())
         self.assertEqual(
             'Cannot set add/update permissions on computed attribute Entity.attr[Int]',
             str(cm.exception))
diff --git a/test/unittest_schema.py b/test/unittest_schema.py
--- a/test/unittest_schema.py
+++ b/test/unittest_schema.py
@@ -34,7 +34,6 @@ from yams.constraints import (BASE_CHECK
                               StaticVocabularyConstraint, IntervalBoundConstraint,
                               FormatConstraint)
 from yams.reader import SchemaLoader
-from yams.buildobjs import register_base_types
 
 
 # build a dummy schema ########################################################
@@ -133,8 +132,8 @@ ATTRIBUTE_BAD_VALUES = (
     # the date and time are not checked for now
     # ('Person', [('nom', u' >10 mais < 20 '),
     # ('datenaiss', '979-06-12')]),
-    ##    ('Note', [('date', '2229-01-31 minuit')]),
-    ##    ('Affaire', [('starton', 'midi')]),
+    #     ('Note', [('date', '2229-01-31 minuit')]),
+    #     ('Affaire', [('starton', 'midi')]),
 
     ('Note', [('type', ['bof', 'peux mieux faire']),
               ('type', 'bof, je suis pas unicode, alors...'),
@@ -182,10 +181,10 @@ class EntitySchemaTC(BaseSchemaTC):
         self.assertFalse(eperson == enote)
         self.assertTrue(enote != eperson)
         self.assertTrue(eperson != enote)
-        l = [eperson, enote, eaffaire, esociete]
-        l.sort()
-        self.assertListEqual(l, [eaffaire, enote, eperson, esociete])
-        self.assertListEqual(l, ['Affaire', 'Note', 'Person', 'Societe'])
+        entities = [eperson, enote, eaffaire, esociete]
+        entities.sort()
+        self.assertListEqual(entities, [eaffaire, enote, eperson, esociete])
+        self.assertListEqual(entities, ['Affaire', 'Note', 'Person', 'Societe'])
 
     def test_hash(self):
         d = {}
@@ -243,7 +242,7 @@ class EntitySchemaTC(BaseSchemaTC):
         self.assertEqual(estring.final, True)
         self.assertEqual(eint.final, True)
         self.assertEqual(eperson.subjrels['nom'].final, True)
-        #self.assertEqual(eperson.is_final('concerne'), False)
+        # self.assertEqual(eperson.is_final('concerne'), False)
         self.assertEqual(eperson.subjrels['concerne'].final, False)
 
     def test_is_metadata(self):
@@ -260,8 +259,12 @@ class EntitySchemaTC(BaseSchemaTC):
 
     def test_vocabulary(self):
         # self.assertEqual(eperson.vocabulary('promo')
-        self.assertEqual(eperson.rdef('promo').constraint_by_interface(IVocabularyConstraint).vocabulary(),
-                         ('bon', 'pasbon'))
+        self.assertEqual(
+            eperson.rdef('promo').constraint_by_interface(
+                IVocabularyConstraint
+            ).vocabulary(),
+            ('bon', 'pasbon')
+        )
         # self.assertRaises(AssertionError,
         #                   eperson.vocabulary, 'nom')
 
@@ -355,9 +358,14 @@ class RelationSchemaTC(BaseSchemaTC):
         self.assertRaisesMsg(BadSchemaDefinition,
                              'type String can\'t be used as subject in a relation',
                              rconcerne.update, estring, enote, {})
-# self.assertRaisesMsg(BadSchemaDefinition,
-##                              "can't have a final relation pointing to multiple entity types (nom: ['String', 'Int'])" ,
-# rnom.update, enote, eint)
+# self.assertRaisesMsg(
+#    BadSchemaDefinition,
+#    (
+#       "can't have a final relation pointing to multiple entity types "
+#       "(nom: ['String', 'Int'])"
+#    ),
+#    rnom.update, enote, eint
+# )
         msgref = ("ambiguous relation: 'Person.nom' is final (String) "
                   "but not 'Note.nom' (Affaire)")
         self.assertRaisesMsg(BadSchemaDefinition, msgref,
@@ -374,7 +382,7 @@ class RelationSchemaTC(BaseSchemaTC):
         assoc_types = []
         for _from, _to in rconcerne.associations():
             assoc_types.append((_from, _to))
-            #assoc_types.append( (_from.type, [s.type for s in _to]) )
+            # assoc_types.append( (_from.type, [s.type for s in _to]) )
         assoc_types.sort()
         self.assertEqual(assoc_types, expected)
 
@@ -409,11 +417,12 @@ class SchemaTC(BaseSchemaTC):
                              schema.add_entity_type, EntityType('Person'))
 
     def test_raise_relation_def(self):
-        self.assertRaisesMsg(BadSchemaDefinition, "using unknown type 'Afire' in relation evaluee",
-                             schema.add_relation_def, RelationDefinition('Afire', 'evaluee', 'Note'))
-# XXX what is this ?
-# self.assertRaisesMsg(BadSchemaDefinition, 'the "symmetric" property should appear on every definition of relation evaluee' ,
-# schema.add_relation_def, RelationDefinition('Affaire', 'evaluee', 'Note', symmetric=True))
+        self.assertRaisesMsg(
+            BadSchemaDefinition,
+            "using unknown type 'Afire' in relation evaluee",
+            schema.add_relation_def,
+            RelationDefinition('Afire', 'evaluee', 'Note')
+        )
 
     def test_schema_relations(self):
         all_relations = ['TEST', 'concerne', 'travaille', 'evaluee',
diff --git a/test/unittest_schema2dot.py b/test/unittest_schema2dot.py
--- a/test/unittest_schema2dot.py
+++ b/test/unittest_schema2dot.py
@@ -43,7 +43,7 @@ splines=true
 "Person" -> "Societe" [arrowhead="normal", arrowtail="none", color="#aa0000", decorate="false", fontcolor="#aa0000", headlabel="0..n", label="travaille", style="filled", taillabel="0..n"];
 "Salaried" -> "Societe" [arrowhead="normal", arrowtail="none", color="#00aa00", decorate="false", fontcolor="#00aa00", headlabel="0..n", label="travaille", style="filled", taillabel="0..n"];
 }
-'''
+''' # noqa
 
 
 class DotTC(TestCase):
diff --git a/test/unittest_serialize.py b/test/unittest_serialize.py
--- a/test/unittest_serialize.py
+++ b/test/unittest_serialize.py
@@ -1,6 +1,6 @@
 from logilab.common import testlib
 
-from yams.buildobjs import register_base_types, String, EntityType, RelationType, RelationDefinition
+from yams.buildobjs import register_base_types, EntityType, RelationType, RelationDefinition
 from yams import schema, serialize
 
 
diff --git a/test/unittest_specialization.py b/test/unittest_specialization.py
--- a/test/unittest_specialization.py
+++ b/test/unittest_specialization.py
@@ -115,8 +115,18 @@ class SpecializationTC(TestCase):
     def test_relations_infered(self):
         entities = [str(e) for e in self.schema.entities() if not e.final]
         relations = sorted([r for r in self.schema.relations() if not r.final])
-        self.assertListEqual(sorted(entities), ['Company', 'Division', 'Person',
-                                                'Student', 'SubCompany', 'SubDivision', 'SubSubDivision'])
+        self.assertListEqual(
+            sorted(entities),
+            [
+                'Company',
+                'Division',
+                'Person',
+                'Student',
+                'SubCompany',
+                'SubDivision',
+                'SubSubDivision'
+            ]
+        )
         self.assertListEqual(relations, ['division_of', 'knows', 'works_for'])
         expected = {('Person', 'Person'): False,
                     ('Person', 'Student'): True,



More information about the cubicweb-devel mailing list