Ticket #2333: regressiontests.patch
File regressiontests.patch, 16.6 KB (added by , 18 years ago) |
---|
-
string_lookup/models.py
34 34 def __str__(self): 35 35 return "Base %s" % self.name 36 36 37 API_TESTS ="""37 __test__ = {'API_TESTS':""" 38 38 # Regression test for #1661 and #1662: Check that string form referencing of models works, 39 39 # both as pre and post reference, on all RelatedField types. 40 40 … … 66 66 67 67 >>> child1.parent 68 68 <Base: Base Base1> 69 """ 69 """} -
markup/tests.py
1 1 # Quick tests for the markup templatetags (django.contrib.markup) 2 2 3 3 from django.template import Template, Context, add_to_builtins 4 4 import unittest 5 5 add_to_builtins('django.contrib.markup.templatetags.markup') 6 6 7 # find out if markup modules are installed and tailor the test appropriately 8 try: 9 import textile 10 except ImportError: 11 textile = None 7 class Templates(unittest.TestCase): 8 def test_textile(self): 9 try: 10 import textile 11 except ImportError: 12 textile = None 12 13 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 “quotes” and <code>code</code></p>""" 26 else: 27 assert rendered == textile_content 17 28 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 22 47 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 “quotes” 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 70 if __name__ == '__main__': 71 unittest.main() 72 No newline at end of file -
many_to_one_regress/models.py
10 10 # created (the field names being lower-cased versions of their opposite 11 11 # classes is important here). 12 12 13 API_TESTS = "" 13 __test__ = {'API_TESTS':""} -
initial_sql_regress/models.py
7 7 class Simple(models.Model): 8 8 name = models.CharField(maxlength = 50) 9 9 10 API_TESTS = "" 10 __test__ = {'API_TESTS':""} 11 11 12 12 # NOTE: The format of the included SQL file for this test suite is important. 13 13 # It must end with a trailing newline in order to test the fix for #2161. -
cache/tests.py
2 2 # Uses whatever cache backend is set in the test settings file. 3 3 4 4 from django.core.cache import cache 5 import time 5 import time, unittest 6 6 7 7 # functions/classes for complex data type tests 8 8 def f(): … … 11 11 def m(n): 12 12 return 24 13 13 14 # simple set/get 15 cache.set("key", "value") 16 assert cache.get("key") == "value" 14 class 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) 17 69 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 70 if __name__ == '__main__': 71 unittest.main() 72 No newline at end of file -
db_typecasts/tests.py
1 1 # Unit tests for typecast functions in django.db.backends.util 2 2 3 3 from django.db.backends import util as typecasts 4 import datetime 4 import datetime, unittest 5 5 6 6 TEST_CASES = { 7 7 'typecast_date': ( … … 45 45 ), 46 46 } 47 47 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) 48 class 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 55 if __name__ == '__main__': 56 unittest.main() 57 No newline at end of file -
dateformat/tests.py
73 73 os.environ['TZ'] = 'Europe/Copenhagen' 74 74 translation.activate('en-us') 75 75 76 time.tzset()76 #time.tzset() 77 77 78 78 my_birthday = datetime.datetime(1979, 7, 8, 22, 00) 79 79 summertime = datetime.datetime(2005, 10, 30, 1, 00) 80 80 wintertime = datetime.datetime(2005, 10, 30, 4, 00) 81 82 83 if __name__ == '__main__': 84 import doctest 85 doctest.testmod() -
one_to_one_regress/models.py
22 22 def __str__(self): 23 23 return "Favorites for %s" % self.name 24 24 25 API_TESTS ="""25 __test__ = {'API_TESTS':""" 26 26 # Regression test for #1064 and #1506: Check that we create models via the m2m 27 27 # relation if the remote model has a OneToOneField. 28 28 >>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton') … … 34 34 >>> f.restaurants = [r] 35 35 >>> f.restaurants.all() 36 36 [<Restaurant: Demon Dogs the restaurant>] 37 """ 37 """} -
templates/tests.py
6 6 from django.utils.translation import activate, deactivate, install 7 7 from django.utils.tzinfo import LocalTimezone 8 8 from datetime import datetime, timedelta 9 import traceback9 import unittest 10 10 11 11 ################################# 12 12 # Custom template tag for tests # … … 568 568 except KeyError: 569 569 raise template.TemplateDoesNotExist, template_name 570 570 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' 571 class 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] 584 576 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']) 597 590 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 610 if __name__ == '__main__': 624 611 settings.configure() 625 run_tests(1, True)612 unittest.main()