Ticket #12568: subfieldbase_fix_and_test.diff

File subfieldbase_fix_and_test.diff, 1.3 KB (added by Lars van de Kerkhof, 14 years ago)

This time the test is also added

  • modeltests/field_subclassing/tests.py

     
     1import inspect
    12from django.test import TestCase
    23
    3 from models import DataModel
     4from models import DataModel, MyModel
    45
    56
    67class CustomField(TestCase):
     
    1920        d = DataModel.objects.get(pk=d.pk)
    2021        self.assertTrue(isinstance(d.data, list))
    2122        self.assertEqual(d.data, [1, 2, 3])
     23   
     24    def test_subfieldbase_plays_nice_with_module_inspect(self):
     25        """
     26        Custom fields should play nice with python standard module inspect.
     27       
     28        http://users.rcn.com/python/download/Descriptor.htm#properties
     29        """
     30        # even when looking for totally different properties, SubfieldBase it's
     31        # non property like behaviour makes inspect crash.
     32        strings = inspect.getmembers(MyModel, lambda x: type(x) is str)
     33        known_strings = [('__doc__', 'MyModel(id, name, data)'),
     34            ('__module__', 'modeltests.field_subclassing.models')]
     35       
     36        self.assertEqual(strings, known_strings)
     37
     38        # should also not raise an exception
     39        inspect.getmembers(MyModel)
Back to Top