<s> import os <EOL> from contextlib import contextmanager <EOL> from unittest import TestSuite , TextTestRunner , defaultTestLoader <EOL> from django . test import TestCase <EOL> from django . test . runner import DiscoverRunner <EOL> @ contextmanager <EOL> def change_cwd ( directory ) : <EOL> current_dir = os . path . abspath ( os . path . dirname ( __file__ ) ) <EOL> new_dir = os . path . join ( current_dir , directory ) <EOL> old_cwd = os . getcwd ( ) <EOL> os . chdir ( new_dir ) <EOL> try : <EOL> yield <EOL> finally : <EOL> os . chdir ( old_cwd ) <EOL> class DiscoverRunnerTest ( TestCase ) : <EOL> def test_dotted_test_module ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:6> ) <EOL> def test_dotted_test_class_vanilla_unittest ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_dotted_test_class_django_testcase ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_dotted_test_method_django_testcase ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_pattern ( self ) : <EOL> count = DiscoverRunner ( <EOL> pattern = "<STR_LIT>" , <EOL> ) . build_suite ( [ "<STR_LIT>" ] ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_file_path ( self ) : <EOL> with change_cwd ( "<STR_LIT:..>" ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:7> ) <EOL> def test_empty_label ( self ) : <EOL> """<STR_LIT>""" <EOL> with change_cwd ( "<STR_LIT:.>" ) : <EOL> suite = DiscoverRunner ( ) . build_suite ( [ ] ) <EOL> self . assertEqual ( <EOL> suite . _tests [ <NUM_LIT:0> ] . id ( ) . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] , <EOL> os . path . basename ( os . getcwd ( ) ) , <EOL> ) <EOL> def test_empty_test_case ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:0> ) <EOL> def test_discovery_on_package ( self ) : <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:1> ) <EOL> def test_ignore_adjacent ( self ) : <EOL> """<STR_LIT>""" <EOL> count = DiscoverRunner ( ) . build_suite ( <EOL> [ "<STR_LIT>" ] , <EOL> ) . countTestCases ( ) <EOL> self . assertEqual ( count , <NUM_LIT:0> ) <EOL> def test_testcase_ordering ( self ) : <EOL> with change_cwd ( "<STR_LIT:..>" ) : <EOL> suite = DiscoverRunner ( ) . build_suite ( [ "<STR_LIT>" ] ) <EOL> self . assertEqual ( <EOL> suite . _tests [ <NUM_LIT:0> ] . __class__ . __name__ , <EOL> '<STR_LIT>' , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertEqual ( <EOL> suite . _tests [ <NUM_LIT:1> ] . __class__ . __name__ , <EOL> '<STR_LIT>' , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , [ t . __class__ . __name__ for t in suite . _tests [ <NUM_LIT:2> : ] ] ) <EOL> def test_duplicates_ignored ( self ) : <EOL> """<STR_LIT>""" <EOL> base_app = '<STR_LIT>' <EOL> sub_app = '<STR_LIT>' <EOL> with self . modify_settings ( INSTALLED_APPS = { '<STR_LIT>' : sub_app } ) : <EOL> single = DiscoverRunner ( ) . build_suite ( [ base_app ] ) . countTestCases ( ) <EOL> dups = DiscoverRunner ( ) . build_suite ( [ base_app , sub_app ] ) . countTestCases ( ) <EOL> self . assertEqual ( single , dups ) <EOL> def test_reverse ( self ) : <EOL> """<STR_LIT>""" <EOL> runner = DiscoverRunner ( reverse = True ) <EOL> suite = runner . build_suite ( <EOL> test_labels = ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertIn ( '<STR_LIT>' , next ( iter ( suite ) ) . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> suite = runner . build_suite ( test_labels = ( '<STR_LIT>' , ) ) <EOL> suite = tuple ( suite ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:0> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:4> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:0> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:4> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:8> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:0> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:4> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> self . assertIn ( '<STR_LIT>' , suite [ <NUM_LIT:8> ] . id ( ) , <EOL> msg = "<STR_LIT>" ) <EOL> def test_overridable_test_suite ( self ) : <EOL> self . assertEqual ( DiscoverRunner ( ) . test_suite , TestSuite ) <EOL> def test_overridable_test_runner ( self ) : <EOL> self . assertEqual ( DiscoverRunner ( ) . test_runner , TextTestRunner ) <EOL> def test_overridable_test_loader ( self ) : <EOL> self . assertEqual ( DiscoverRunner ( ) . test_loader , defaultTestLoader ) <EOL> def test_tags ( self ) : <EOL> runner = DiscoverRunner ( tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:1> ) <EOL> runner = DiscoverRunner ( tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:2> ) <EOL> runner = DiscoverRunner ( tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:2> ) <EOL> def test_exclude_tags ( self ) : <EOL> runner = DiscoverRunner ( tags = [ '<STR_LIT>' ] , exclude_tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:1> ) <EOL> runner = DiscoverRunner ( tags = [ '<STR_LIT>' ] , exclude_tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:0> ) <EOL> runner = DiscoverRunner ( exclude_tags = [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( runner . build_suite ( [ '<STR_LIT>' ] ) . countTestCases ( ) , <NUM_LIT:4> ) </s>
