<s> from django . utils import unittest <EOL> import sys <EOL> class RegistryProcessTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister import models <EOL> models . registry = models . QuestionRegistry ( ) <EOL> def test_register ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import Question , registry <EOL> class MyQuestion ( Question ) : <EOL> pass <EOL> registry . register ( MyQuestion ) <EOL> def test_non_subclass_register ( self ) : <EOL> """<STR_LIT>""" <EOL> from appregister . base import InvalidOperation <EOL> from test_appregister . models import registry <EOL> class NonSubclass ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidOperation ) : <EOL> registry . register ( NonSubclass ) <EOL> @ unittest . skipIf ( sys . version_info < ( <NUM_LIT:2> , <NUM_LIT:6> ) , <EOL> "<STR_LIT>" ) <EOL> def test_decorator_register ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import Question , registry <EOL> @ registry . register <EOL> class MyQuestion ( Question ) : <EOL> pass <EOL> self . assertIn ( MyQuestion , registry . all ( ) ) <EOL> def test_already_registered ( self ) : <EOL> """<STR_LIT>""" <EOL> from appregister . base import AlreadyRegistered <EOL> from test_appregister . models import Question , registry <EOL> class MyQuestion2 ( Question ) : <EOL> pass <EOL> registry . register ( MyQuestion2 ) <EOL> with self . assertRaises ( AlreadyRegistered ) : <EOL> registry . register ( MyQuestion2 ) <EOL> def test_unregister ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import Question , registry <EOL> class MyQuestion3 ( Question ) : <EOL> pass <EOL> registry . register ( MyQuestion3 ) <EOL> self . assertIn ( MyQuestion3 , registry . all ( ) ) <EOL> registry . unregister ( MyQuestion3 ) <EOL> self . assertNotIn ( MyQuestion3 , registry . all ( ) ) <EOL> registry . register ( MyQuestion3 ) <EOL> self . assertIn ( MyQuestion3 , registry . all ( ) ) <EOL> def test_unregister_without_register ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import Question , registry <EOL> class MyQuestion4 ( Question ) : <EOL> pass <EOL> with self . assertRaises ( KeyError ) : <EOL> registry . unregister ( MyQuestion4 ) <EOL> def test_doesnt_contain_base ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import Question , registry <EOL> self . assertEqual ( registry . all ( ) , set ( ) ) <EOL> class MyQuestion3 ( Question ) : <EOL> pass <EOL> registry . register ( MyQuestion3 ) <EOL> self . assertEqual ( registry . all ( ) , set ( [ MyQuestion3 , ] ) ) <EOL> def test_clear_register ( self ) : <EOL> from test_appregister . models import Question , registry <EOL> class MyQuestion ( Question ) : <EOL> pass <EOL> registry . register ( MyQuestion ) <EOL> self . assertIn ( MyQuestion , registry . all ( ) ) <EOL> registry . clear ( ) <EOL> self . assertNotIn ( MyQuestion , registry . all ( ) ) <EOL> def test_repr ( self ) : <EOL> from test_appregister . models import registry <EOL> self . assertEqual ( repr ( registry ) , '<STR_LIT>' ) <EOL> class NamedRegistryTestCase ( unittest . TestCase ) : <EOL> def test_basic_registry ( self ) : <EOL> from appregister import NamedRegistry <EOL> from appregister . base import InvalidOperation , AlreadyRegistered <EOL> from test_appregister . models import Question <EOL> class MyRegistry ( NamedRegistry ) : <EOL> base = Question <EOL> registry = MyRegistry ( ) <EOL> class MyTestSubClass ( Question ) : <EOL> pass <EOL> registry . register ( '<STR_LIT>' , MyTestSubClass ) <EOL> with self . assertRaises ( AlreadyRegistered ) : <EOL> registry . register ( '<STR_LIT>' , MyTestSubClass ) <EOL> registry . register ( '<STR_LIT>' , MyTestSubClass ) <EOL> class MyObject ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidOperation ) : <EOL> registry . register ( '<STR_LIT>' , MyObject ) <EOL> registry . unregister ( '<STR_LIT>' ) <EOL> with self . assertRaises ( KeyError ) : <EOL> registry [ '<STR_LIT>' ] <EOL> self . assertEqual ( registry [ '<STR_LIT>' ] , MyTestSubClass ) <EOL> self . assertEqual ( len ( registry ) , <NUM_LIT:1> ) <EOL> for i in registry : <EOL> self . assertIn ( i , registry . keys ( ) ) <EOL> def test_decorator_registry ( self ) : <EOL> from appregister import NamedRegistry <EOL> from test_appregister . models import Question <EOL> class MyRegistry ( NamedRegistry ) : <EOL> base = Question <EOL> registry = MyRegistry ( ) <EOL> @ registry . register ( '<STR_LIT>' ) <EOL> class MyTestSubClass ( Question ) : <EOL> pass <EOL> MyTestSubClass ( ) <EOL> self . assertIn ( MyTestSubClass , registry . values ( ) ) <EOL> class SortedRegistryTestCase ( unittest . TestCase ) : <EOL> def test_basic_registry ( self ) : <EOL> from appregister import SortedRegistry <EOL> from appregister . base import InvalidOperation , AlreadyRegistered <EOL> from test_appregister . models import Question <EOL> class MyRegistry ( SortedRegistry ) : <EOL> base = Question <EOL> registry = MyRegistry ( ) <EOL> class MyTestSubClass ( Question ) : <EOL> pass <EOL> registry . register ( MyTestSubClass ) <EOL> with self . assertRaises ( AlreadyRegistered ) : <EOL> registry . register ( MyTestSubClass ) <EOL> class MyObject ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidOperation ) : <EOL> registry . register ( MyObject ) <EOL> self . assertIn ( MyTestSubClass , registry ) <EOL> registry . unregister ( MyTestSubClass ) <EOL> self . assertNotIn ( MyTestSubClass , registry ) <EOL> self . assertEqual ( len ( registry ) , <NUM_LIT:0> ) <EOL> def test_decorator_registry ( self ) : <EOL> from appregister import NamedRegistry <EOL> from test_appregister . models import Question <EOL> class MyRegistry ( NamedRegistry ) : <EOL> base = Question <EOL> registry = MyRegistry ( ) <EOL> @ registry . register ( '<STR_LIT>' ) <EOL> class MyTestSubClass ( Question ) : <EOL> pass <EOL> MyTestSubClass ( ) <EOL> self . assertIn ( MyTestSubClass , registry . values ( ) ) <EOL> class RegistryDefinitionTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister import models <EOL> models . registry = models . QuestionRegistry ( ) <EOL> def test_basic_registry ( self ) : <EOL> from appregister import Registry <EOL> from appregister . base import InvalidOperation <EOL> from test_appregister . models import Question <EOL> class MyRegistry ( Registry ) : <EOL> base = Question <EOL> registry = MyRegistry ( ) <EOL> class MySubClass ( Question ) : <EOL> pass <EOL> registry . register ( MySubClass ) <EOL> class MyObject ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidOperation ) : <EOL> registry . register ( MyObject ) <EOL> def test_dotted_path_base ( self ) : <EOL> """<STR_LIT>""" <EOL> from appregister import Registry <EOL> from appregister . base import InvalidOperation <EOL> class MyRegistry ( Registry ) : <EOL> base = '<STR_LIT>' <EOL> registry = MyRegistry ( ) <EOL> from test_appregister . models import Question <EOL> class MySubClass ( Question ) : <EOL> pass <EOL> registry . register ( MySubClass ) <EOL> class MyObject ( object ) : <EOL> pass <EOL> with self . assertRaises ( InvalidOperation ) : <EOL> registry . register ( MyObject ) <EOL> class AutodiscoverTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister import models <EOL> models . registry = models . QuestionRegistry ( ) <EOL> def test_autodiscover ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import registry <EOL> registry . autodiscover ( ) <EOL> names = [ ( c . __module__ , c . __name__ ) for c in registry . all ( ) ] <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' ) , names ) <EOL> def test_autodiscover_overwrite ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import registry <EOL> registry . autodiscover ( '<STR_LIT>' ) <EOL> names = [ ( c . __module__ , c . __name__ ) for c in registry . all ( ) ] <EOL> self . assertIn ( ( '<STR_LIT>' , '<STR_LIT>' ) , names ) <EOL> def test_autodiscover_import_error ( self ) : <EOL> """<STR_LIT>""" <EOL> from test_appregister . models import registry <EOL> with self . assertRaises ( ImportError ) : <EOL> registry . autodiscover ( '<STR_LIT>' ) </s>
