Ticket #7557: 7557_type_check_test_working.diff

File 7557_type_check_test_working.diff, 1.1 KB (added by Steffen Zieger, 12 years ago)

Fixes the test and improves code

  • django/template/base.py

    diff --git a/django/template/base.py b/django/template/base.py
    index dc6b0c3..ba2694b 100644
    a b class Variable(object):  
    690690        self.lookups = None
    691691        self.translate = False
    692692        self.message_context = None
    693 
     693        if not isinstance(var, six.string_types):
     694            raise TypeError(
     695                "Variable must be a string or number, got %s" % type(var))
    694696        try:
    695697            # First try to treat this variable as a number.
    696698            #
  • tests/template_tests/test_parser.py

    diff --git a/tests/template_tests/test_parser.py b/tests/template_tests/test_parser.py
    index 9422da8..60454df 100644
    a b class ParserTests(TestCase):  
    8686            Variable, "article._hidden"
    8787        )
    8888
     89        # Variables should raise on non string type
     90        self.assertRaises(TypeError,
     91            Variable, {}
     92        )
     93
    8994    @override_settings(DEBUG=True, TEMPLATE_DEBUG=True)
    9095    def test_compile_filter_error(self):
    9196        # regression test for #19819
Back to Top