Ticket #2333: regressiontests.patch

File regressiontests.patch, 16.6 KB (added by russellm, 9 years ago)

Changes to the regressiontests

  • string_lookup/models.py

     
    3434    def __str__(self):
    3535        return "Base %s" % self.name
    3636
    37 API_TESTS = """
     37__test__ = {'API_TESTS':"""
    3838# Regression test for #1661 and #1662: Check that string form referencing of models works,
    3939# both as pre and post reference, on all RelatedField types.
    4040
     
    6666
    6767>>> child1.parent
    6868<Base: Base Base1>
    69 """
     69"""}
  • markup/tests.py

     
    11# Quick tests for the markup templatetags (django.contrib.markup)
    22
    33from django.template import Template, Context, add_to_builtins
    4 
     4import unittest
    55add_to_builtins('django.contrib.markup.templatetags.markup')
    66
    7 # find out if markup modules are installed and tailor the test appropriately
    8 try:
    9     import textile
    10 except ImportError:
    11     textile = None
     7class Templates(unittest.TestCase):
     8    def test_textile(self):
     9        try:
     10            import textile
     11        except ImportError:
     12            textile = None
    1213
    13 try:
    14     import markdown
    15 except ImportError:
    16     markdown = None
     14        ### test textile
     15       
     16        textile_content = """Paragraph 1
     17       
     18        Paragraph 2 with "quotes" and @code@"""
     19       
     20        t = Template("{{ textile_content|textile }}")
     21        rendered = t.render(Context(locals())).strip()
     22        if textile:
     23            assert rendered == """<p>Paragraph 1</p>
     24       
     25        <p>Paragraph 2 with &#8220;quotes&#8221; and <code>code</code></p>"""
     26        else:
     27            assert rendered == textile_content
    1728
    18 try:
    19     import docutils
    20 except ImportError:
    21     docutils = None
     29    def test_markdown(self):
     30        try:
     31            import markdown
     32        except ImportError:
     33            markdown = None
     34       
     35        ### test markdown
     36       
     37        markdown_content = """Paragraph 1
     38       
     39        ## An h2"""
     40       
     41        t = Template("{{ markdown_content|markdown }}")
     42        rendered = t.render(Context(locals())).strip()
     43        if markdown:
     44            assert rendered == """<p>Paragraph 1</p><h2>An h2</h2>"""
     45        else:
     46            assert rendered == markdown_content
    2247
    23 # simple examples 'cause this isn't actually testing the markup, just
    24 # that the filters work as advertised
    25 
    26 ### test textile
    27 
    28 textile_content = """Paragraph 1
    29 
    30 Paragraph 2 with "quotes" and @code@"""
    31 
    32 t = Template("{{ textile_content|textile }}")
    33 rendered = t.render(Context(locals())).strip()
    34 if textile:
    35     assert rendered == """<p>Paragraph 1</p>
    36 
    37 <p>Paragraph 2 with &#8220;quotes&#8221; and <code>code</code></p>"""
    38 else:
    39     assert rendered == textile_content
    40 
    41 ### test markdown
    42 
    43 markdown_content = """Paragraph 1
    44 
    45 ## An h2"""
    46 
    47 t = Template("{{ markdown_content|markdown }}")
    48 rendered = t.render(Context(locals())).strip()
    49 if markdown:
    50     assert rendered == """<p>Paragraph 1</p><h2>An h2</h2>"""
    51 else:
    52     assert rendered == markdown_content
    53 
    54 ### test rest
    55 
    56 rest_content = """Paragraph 1
    57 
    58 Paragraph 2 with a link_
    59 
    60 .. _link: http://www.example.com/"""
    61 
    62 t = Template("{{ rest_content|restructuredtext }}")
    63 rendered = t.render(Context(locals())).strip()
    64 if docutils:
    65     assert rendered =="""<p>Paragraph 1</p>
    66 <p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>"""
    67 else:
    68     assert rendered == rest_content
     48    def test_rest(self):
     49        try:
     50            import docutils
     51        except ImportError:
     52            docutils = None
     53       
     54        ### test rest
     55       
     56        rest_content = """Paragraph 1
     57       
     58        Paragraph 2 with a link_
     59       
     60        .. _link: http://www.example.com/"""
     61       
     62        t = Template("{{ rest_content|restructuredtext }}")
     63        rendered = t.render(Context(locals())).strip()
     64        if docutils:
     65            assert rendered =="""<p>Paragraph 1</p>
     66        <p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>"""
     67        else:
     68            assert rendered == rest_content
     69           
     70if __name__ == '__main__':
     71    unittest.main()
     72 No newline at end of file
  • many_to_one_regress/models.py

     
    1010# created (the field names being lower-cased versions of their opposite
    1111# classes is important here).
    1212
    13 API_TESTS = ""
     13__test__ = {'API_TESTS':""}
  • initial_sql_regress/models.py

     
    77class Simple(models.Model):
    88    name = models.CharField(maxlength = 50)
    99
    10 API_TESTS = ""
     10__test__ = {'API_TESTS':""}
    1111
    1212# NOTE: The format of the included SQL file for this test suite is important.
    1313# It must end with a trailing newline in order to test the fix for #2161.
  • cache/tests.py

     
    22# Uses whatever cache backend is set in the test settings file.
    33
    44from django.core.cache import cache
    5 import time
     5import time, unittest
    66
    77# functions/classes for complex data type tests       
    88def f():
     
    1111    def m(n):
    1212        return 24
    1313
    14 # simple set/get
    15 cache.set("key", "value")
    16 assert cache.get("key") == "value"
     14class Cache(unittest.TestCase):
     15    def test_simple(self):
     16        # simple set/get
     17        cache.set("key", "value")
     18        self.assertEqual(cache.get("key"), "value")
     19       
     20    def test_non_existent(self):
     21        # get with non-existent keys
     22        self.assertEqual(cache.get("does not exist"), None)
     23        self.assertEqual(cache.get("does not exist", "bang!"), "bang!")
     24       
     25    def test_get_many(self):
     26        # get_many
     27        cache.set('a', 'a')
     28        cache.set('b', 'b')
     29        cache.set('c', 'c')
     30        cache.set('d', 'd')
     31       
     32        self.assertEqual(cache.get_many(['a', 'c', 'd']), {'a' : 'a', 'c' : 'c', 'd' : 'd'})
     33        self.assertEqual(cache.get_many(['a', 'b', 'e']), {'a' : 'a', 'b' : 'b'})
     34       
     35    def test_delete(self):
     36        # delete
     37        cache.set("key1", "spam")
     38        cache.set("key2", "eggs")
     39        self.assertEqual(cache.get("key1"), "spam")
     40        cache.delete("key1")
     41        self.assertEqual(cache.get("key1"), None)
     42        self.assertEqual(cache.get("key2"), "eggs")
     43       
     44    def test_has_key(self):
     45        # has_key
     46        cache.set("hello", "goodbye")
     47        self.assertEqual(cache.has_key("hello"), True)
     48        self.assertEqual(cache.has_key("goodbye"), False)
     49       
     50    def test_data_types(self):
     51        # test data types
     52        stuff = {
     53            'string'    : 'this is a string',
     54            'int'       : 42,
     55            'list'      : [1, 2, 3, 4],
     56            'tuple'     : (1, 2, 3, 4),
     57            'dict'      : {'A': 1, 'B' : 2},
     58            'function'  : f,
     59            'class'     : C,
     60        }
     61        for (key, value) in stuff.items():
     62            cache.set(key, value)
     63            self.assertEqual(cache.get(key), value)
     64           
     65        # expiration
     66        cache.set('expire', 'very quickly', 1)
     67        time.sleep(2)
     68        self.assertEqual(cache.get("expire"), None)
    1769
    18 # get with non-existent keys
    19 assert cache.get("does not exist") is None
    20 assert cache.get("does not exist", "bang!") == "bang!"
    21 
    22 # get_many
    23 cache.set('a', 'a')
    24 cache.set('b', 'b')
    25 cache.set('c', 'c')
    26 cache.set('d', 'd')
    27 assert cache.get_many(['a', 'c', 'd']) == {'a' : 'a', 'c' : 'c', 'd' : 'd'}
    28 assert cache.get_many(['a', 'b', 'e']) == {'a' : 'a', 'b' : 'b'}
    29 
    30 # delete
    31 cache.set("key1", "spam")
    32 cache.set("key2", "eggs")
    33 assert cache.get("key1") == "spam"
    34 cache.delete("key1")
    35 assert cache.get("key1") is None
    36 assert cache.get("key2") == "eggs"
    37 
    38 # has_key
    39 cache.set("hello", "goodbye")
    40 assert cache.has_key("hello") == True
    41 assert cache.has_key("goodbye") == False
    42 
    43 # test data types
    44 stuff = {
    45     'string'    : 'this is a string',
    46     'int'       : 42,
    47     'list'      : [1, 2, 3, 4],
    48     'tuple'     : (1, 2, 3, 4),
    49     'dict'      : {'A': 1, 'B' : 2},
    50     'function'  : f,
    51     'class'     : C,
    52 }
    53 for (key, value) in stuff.items():
    54     cache.set(key, value)
    55     assert cache.get(key) == value
    56    
    57 # expiration
    58 cache.set('expire', 'very quickly', 1)
    59 time.sleep(2)
    60 assert cache.get("expire") == None
     70if __name__ == '__main__':
     71    unittest.main()
     72 No newline at end of file
  • db_typecasts/tests.py

     
    11# Unit tests for typecast functions in django.db.backends.util
    22
    33from django.db.backends import util as typecasts
    4 import datetime
     4import datetime, unittest
    55
    66TEST_CASES = {
    77    'typecast_date': (
     
    4545    ),
    4646}
    4747
    48 for k, v in TEST_CASES.items():
    49     for inpt, expected in v:
    50         got = getattr(typecasts, k)(inpt)
    51         assert got == expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got)
     48class DBTypeCasts(unittest.TestCase):
     49    def test_typeCasts(self):
     50        for k, v in TEST_CASES.items():
     51            for inpt, expected in v:
     52                got = getattr(typecasts, k)(inpt)
     53                self.assertEqual(got, expected, "In %s: %r doesn't match %r. Got %r instead." % (k, inpt, expected, got))
     54
     55if __name__ == '__main__':
     56    unittest.main()
     57 No newline at end of file
  • dateformat/tests.py

     
    7373os.environ['TZ'] = 'Europe/Copenhagen'
    7474translation.activate('en-us')
    7575
    76 time.tzset()
     76#time.tzset()
    7777
    7878my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
    7979summertime = datetime.datetime(2005, 10, 30, 1, 00)
    8080wintertime = datetime.datetime(2005, 10, 30, 4, 00)
     81
     82
     83if __name__ == '__main__':
     84    import doctest
     85    doctest.testmod()
  • one_to_one_regress/models.py

     
    2222    def __str__(self):
    2323        return "Favorites for %s" % self.name
    2424
    25 API_TESTS = """
     25__test__ = {'API_TESTS':"""
    2626# Regression test for #1064 and #1506: Check that we create models via the m2m
    2727# relation if the remote model has a OneToOneField.
    2828>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
     
    3434>>> f.restaurants = [r]
    3535>>> f.restaurants.all()
    3636[<Restaurant: Demon Dogs the restaurant>]
    37 """
     37"""}
  • templates/tests.py

     
    66from django.utils.translation import activate, deactivate, install
    77from django.utils.tzinfo import LocalTimezone
    88from datetime import datetime, timedelta
    9 import traceback
     9import unittest
    1010
    1111#################################
    1212# Custom template tag for tests #
     
    568568    except KeyError:
    569569        raise template.TemplateDoesNotExist, template_name
    570570
    571 def run_tests(verbosity=0, standalone=False):
    572     # Register our custom template loader.
    573     old_template_loaders = loader.template_source_loaders
    574     loader.template_source_loaders = [test_template_loader]
    575 
    576     failed_tests = []
    577     tests = TEMPLATE_TESTS.items()
    578     tests.sort()
    579 
    580     # Turn TEMPLATE_DEBUG off, because tests assume that.
    581     old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
    582     # Set TEMPLATE_STRING_IF_INVALID to a known string
    583     old_invalid, settings.TEMPLATE_STRING_IF_INVALID = settings.TEMPLATE_STRING_IF_INVALID, 'INVALID'
     571class Templates(unittest.TestCase):
     572    def test_templates(self):
     573        # Register our custom template loader.
     574        old_template_loaders = loader.template_source_loaders
     575        loader.template_source_loaders = [test_template_loader]
    584576   
    585     for name, vals in tests:
    586         install()
    587         if 'LANGUAGE_CODE' in vals[1]:
    588             activate(vals[1]['LANGUAGE_CODE'])
    589         else:
    590             activate('en-us')
    591         try:
    592             output = loader.get_template(name).render(template.Context(vals[1]))
    593         except Exception, e:
    594             if e.__class__ == vals[2]:
    595                 if verbosity:
    596                     print "Template test: %s -- Passed" % name
     577        failures = []
     578        tests = TEMPLATE_TESTS.items()
     579        tests.sort()
     580   
     581        # Turn TEMPLATE_DEBUG off, because tests assume that.
     582        old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False
     583        # Set TEMPLATE_STRING_IF_INVALID to a known string
     584        old_invalid, settings.TEMPLATE_STRING_IF_INVALID = settings.TEMPLATE_STRING_IF_INVALID, 'INVALID'
     585       
     586        for name, vals in tests:
     587            install()
     588            if 'LANGUAGE_CODE' in vals[1]:
     589                activate(vals[1]['LANGUAGE_CODE'])
    597590            else:
    598                 if verbosity:
    599                     traceback.print_exc()
    600                     print "Template test: %s -- FAILED. Got %s, exception: %s" % (name, e.__class__, e)
    601                 failed_tests.append(name)
    602             continue
    603         if 'LANGUAGE_CODE' in vals[1]:
    604             deactivate()
    605         if output == vals[2]:
    606             if verbosity:
    607                 print "Template test: %s -- Passed" % name
    608         else:
    609             if verbosity:
    610                 print "Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output)
    611             failed_tests.append(name)
    612     loader.template_source_loaders = old_template_loaders
    613     deactivate()
    614     settings.TEMPLATE_DEBUG = old_td
    615     settings.TEMPLATE_STRING_IF_INVALID = old_invalid
    616 
    617     if failed_tests and not standalone:
    618         msg = "Template tests %s failed." % failed_tests
    619         if not verbosity:
    620             msg += "  Re-run tests with -v1 to see actual failures"
    621         raise Exception, msg
    622 
    623 if __name__ == "__main__":
     591                activate('en-us')
     592            try:
     593                output = loader.get_template(name).render(template.Context(vals[1]))
     594            except Exception, e:               
     595                if e.__class__ != vals[2]:
     596                    failures.append("Template test: %s -- FAILED. Got %s, exception: %s" % (name, e.__class__, e))
     597                continue
     598                               
     599            if 'LANGUAGE_CODE' in vals[1]:
     600                deactivate()
     601            if output != vals[2]:
     602                failures.append("Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output))
     603        loader.template_source_loaders = old_template_loaders
     604        deactivate()
     605        settings.TEMPLATE_DEBUG = old_td
     606        settings.TEMPLATE_STRING_IF_INVALID = old_invalid
     607   
     608        self.assertEqual(failures,[])
     609       
     610if __name__ == '__main__':
    624611    settings.configure()
    625     run_tests(1, True)
     612    unittest.main()
Back to Top