Skip to content

Commit b2358b1

Browse files
committed
Add test to expose problem with DeclarativeColumnsMetaclass inheritence
1 parent 1775d0f commit b2358b1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/core.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.core.paginator import Paginator
77
from django.http import Http404
88
import django_tables2 as tables
9+
from django_tables2.tables import DeclarativeColumnsMetaclass
910
from haystack.query import SearchQuerySet
1011

1112

@@ -58,6 +59,38 @@ class CityTable(GeoAreaTable, AddedMixin):
5859
assert 'added' in CityTable.base_columns
5960

6061

62+
@core.test
63+
def metaclass_inheritance():
64+
class Tweaker(type):
65+
"""Adds an attribute "tweaked" to all classes"""
66+
def __new__(cls, name, bases, attrs):
67+
attrs['tweaked'] = True
68+
return super(Tweaker, cls).__new__(cls, name, bases, attrs)
69+
70+
class Meta(Tweaker, DeclarativeColumnsMetaclass):
71+
pass
72+
73+
class TweakedTable(tables.Table):
74+
__metaclass__ = Meta
75+
name = tables.Column()
76+
77+
table = TweakedTable([])
78+
assert 'name' in table.columns
79+
assert table.tweaked
80+
81+
# now flip the order
82+
class FlippedMeta(DeclarativeColumnsMetaclass, Tweaker):
83+
pass
84+
85+
class FlippedTweakedTable(tables.Table):
86+
__metaclass__ = FlippedMeta
87+
name = tables.Column()
88+
89+
table = FlippedTweakedTable([])
90+
assert 'name' in table.columns
91+
assert table.tweaked
92+
93+
6194
@core.test
6295
def attrs():
6396
class TestTable(tables.Table):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy