Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added tests for missing pyyaml.

This test makes sure an YAML import errors are communicated to the
caller rather than stating the serializer does not exist.
  • Loading branch information...
commit d8d61d8260badd87b85accaf5776587f2d355c10 1 parent 630eb05
@rca rca authored
Showing with 22 additions and 1 deletion.
  1. +1 −0  tests/fixtures/tests.py
  2. +21 −1 tests/serializers/tests.py
View
1  tests/fixtures/tests.py
@@ -1,5 +1,6 @@
from __future__ import unicode_literals
+import unittest
import warnings
from django.contrib.sites.models import Site
View
22 tests/serializers/tests.py
@@ -14,7 +14,7 @@
from django.conf import settings
-from django.core import serializers
+from django.core import management, serializers
from django.db import transaction, connection
from django.test import TestCase, TransactionTestCase, Approximate
from django.utils import six
@@ -440,6 +440,26 @@ class JsonSerializerTransactionTestCase(SerializersTransactionTestBase, Transact
}]"""
+@unittest.skipIf(HAS_YAML, "Yaml is installed")
+class NoYamlSerializerTestCase(TestCase):
+ """Not having pyyaml installed provides a misleading error
+
+ #12756
+ """
+ def test_missing_pyyaml_error_message(self):
+ """Using yaml serializer without pyyaml raises ImportError"""
+ jane = Author(name="Jane")
+ self.assertRaises(ImportError, serializers.serialize, "yaml", [jane])
+
+ def test_deserializer_pyyaml_error_message(self):
+ """Using yaml deserializer without pyyaml raises ImportError"""
+ self.assertRaises(ImportError, serializers.deserialize, "yaml", "")
+
+ def test_missing_pyyaml_error_message(self):
+ self.assertRaisesRegexp(management.CommandError, r'No module named yaml',
+ management.call_command, 'dumpdata', format='yaml')
+
+
@unittest.skipUnless(HAS_YAML, "No yaml library detected")
class YamlSerializerTestCase(SerializersTestBase, TestCase):
serializer_name = "yaml"
Please sign in to comment.
Something went wrong with that request. Please try again.