Commits

Anonymous committed 677c0bc

Improved an error message

  • Participants
  • Parent commits 84e1eef

Comments (0)

Files changed (2)

File djangotoolbox/fields.py

 
         model = self.embedded_model or models.Model
         if not isinstance(embedded_instance, model):
-            raise TypeError("Expected instance of type %r, not %r" % (
-                            type(model), type(embedded_instance)))
+            raise TypeError("Expected instance of type %r, not %r"
+                            % (model, type(embedded_instance)))
 
         values = []
         for field in embedded_instance._meta.fields:

File djangotoolbox/tests.py

         self.assertGreater(instance.simple.auto_now, auto_now)
 
     def test_error_messages(self):
-        for kwargs in (
-            {'simple_untyped' : 42},
-            {'simple' : 42}
+        for kwargs, expected in (
+            ({'simple' : 42}, EmbeddedModel),
+            ({'simple_untyped' : 42}, models.Model),
+            ({'typed_list': [EmbeddedModel()]}, SetModel)
         ):
-            self.assertRaisesRegexp(TypeError, "Expected instance of type",
-                                    EmbeddedModelFieldModel(**kwargs).save)
+            self.assertRaisesRegexp(
+                TypeError, "Expected instance of type %r" % expected,
+                EmbeddedModelFieldModel(**kwargs).save
+            )
 
     def test_typed_listfield(self):
         EmbeddedModelFieldModel.objects.create(