Ensure that objects in the Pool has __slots__

issue10719
review375361002
This commit is contained in:
Cédric Krier
2021-09-23 23:12:35 +02:00
parent 51f63441ca
commit 4840a0f46d
5 changed files with 23 additions and 5 deletions
+1
View File
@@ -1,3 +1,4 @@
* Ensure with a test that objects in the Pool have __slots__
* Use bigdecimal tag for XML-RPC
* Use tuple in Dict value instead of list
* Do not set record name on title of report get_email
+1
View File
@@ -32,6 +32,7 @@ FONT = os.path.join(os.path.dirname(__file__), 'fonts', 'karla.ttf')
class ImageMixin:
__slots__ = ()
image = fields.Binary(
"Image", file_id=file_id, store_prefix=store_prefix)
image_id = fields.Char("Image ID", readonly=True)
+1 -1
View File
@@ -8,7 +8,7 @@ from trytond.pool import Pool
def avatar_mixin(size=64, default=None):
class AvatarMixin:
__slots__ = ()
avatars = fields.One2Many(
'ir.avatar', 'resource', lazy_gettext('ir.msg_avatars'), size=1)
avatar = fields.Function(
+4 -4
View File
@@ -6,19 +6,19 @@ from trytond.report import Report
class TestMixin:
pass
__slots__ = ()
class TestSecondMixin:
pass
__slots__ = ()
class NotMixin:
pass
__slots__ = ()
class ReportMixin:
pass
__slots__ = ()
class DeactivableModelView(DeactivableMixin, ModelView):
+16
View File
@@ -744,6 +744,22 @@ class ModuleTestCase(unittest.TestCase):
msg="ModelSingleton must appear before ModelSQL in the parent "
"classes of '%s'." % mname)
@with_transaction()
def test_pool_slots(self):
"Test pool object has __slots__"
for type_ in ['model', 'wizard', 'report']:
for name, cls in Pool().iterobject(type_):
if not isregisteredby(cls, self.module):
continue
if getattr(cls, '__no_slots__', None):
continue
for kls in cls.__mro__:
if kls is object:
continue
self.assertTrue(hasattr(kls, '__slots__'),
msg="The %s of %s '%s' has no __slots__"
% (kls, type_, name))
@with_transaction()
def test_buttons_registered(self):
'Test all buttons are registered in ir.model.button'