'Tests for label_for_field'

def test_label_for_field(self):

    self.assertEqual(label_for_field(u'title', Article), u'title')
    self.assertEqual(label_for_field(u'title2', Article), u'another    name')
    self.assertEqual(label_for_field(u'title2', Article, return_attr=True), (u'another    name', None))
    self.assertEqual(label_for_field(u'__unicode__', Article), u'article')
    self.assertEqual(label_for_field(u'__str__', Article), str(u'article'))
    self.assertRaises(AttributeError, (lambda : label_for_field(u'unknown', Article)))
    def test_callable(obj):
        return u'nothing'
    self.assertEqual(label_for_field(test_callable, Article), u'Test    callable')
    self.assertEqual(label_for_field(test_callable, Article, return_attr=True), (u'Test    callable', test_callable))
    self.assertEqual(label_for_field(u'test_from_model', Article), u'Test    from    model')
    self.assertEqual(label_for_field(u'test_from_model', Article, return_attr=True), (u'Test    from    model', Article.test_from_model))
    self.assertEqual(label_for_field(u'test_from_model_with_override', Article), u'not    What    you    Expect')
    self.assertEqual(label_for_field((lambda x: u'nothing'), Article), u'--')
    class MockModelAdmin(object, ):
        def test_from_model(self, obj):
            return u'nothing'
        test_from_model.short_description = u'not    Really    the    Model'
    self.assertEqual(label_for_field(u'test_from_model', Article, model_admin=MockModelAdmin), u'not    Really    the    Model')
    self.assertEqual(label_for_field(u'test_from_model', Article, model_admin=MockModelAdmin, return_attr=True), (u'not    Really    the    Model', MockModelAdmin.test_from_model))
