<s> """<STR_LIT>""" <EOL> import re <EOL> from elixir import * <EOL> import elixir <EOL> def camel_to_underscore ( entity ) : <EOL> return re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , entity . __name__ ) . lower ( ) <EOL> def setup ( ) : <EOL> cleanup_all ( ) <EOL> metadata . bind = '<STR_LIT>' <EOL> elixir . options_defaults [ '<STR_LIT>' ] = True <EOL> def teardown ( ) : <EOL> elixir . options_defaults [ '<STR_LIT>' ] = False <EOL> class TestAbstractInheritance ( object ) : <EOL> def teardown ( self ) : <EOL> cleanup_all ( True ) <EOL> def test_abstract_alone ( self ) : <EOL> class AbstractPerson ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> firstname = Field ( String ( <NUM_LIT:30> ) ) <EOL> lastname = Field ( String ( <NUM_LIT:30> ) ) <EOL> setup_all ( True ) <EOL> assert not hasattr ( AbstractPerson , '<STR_LIT>' ) <EOL> def test_inheritance ( self ) : <EOL> class AbstractPerson ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( tablename = camel_to_underscore ) <EOL> firstname = Field ( String ( <NUM_LIT:30> ) ) <EOL> lastname = Field ( String ( <NUM_LIT:30> ) ) <EOL> class AbstractEmployee ( AbstractPerson ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( identity = camel_to_underscore ) <EOL> corporation = Field ( String ( <NUM_LIT:30> ) ) <EOL> class ConcreteEmployee ( AbstractEmployee ) : <EOL> service = Field ( String ( <NUM_LIT:30> ) ) <EOL> class ConcreteCitizen ( AbstractPerson ) : <EOL> country = Field ( String ( <NUM_LIT:30> ) ) <EOL> setup_all ( True ) <EOL> assert not hasattr ( AbstractPerson , '<STR_LIT>' ) <EOL> assert not hasattr ( AbstractEmployee , '<STR_LIT>' ) <EOL> assert hasattr ( ConcreteEmployee , '<STR_LIT>' ) <EOL> assert hasattr ( ConcreteCitizen , '<STR_LIT>' ) <EOL> assert ConcreteEmployee . table . name == '<STR_LIT>' <EOL> assert ConcreteCitizen . table . name == '<STR_LIT>' <EOL> assert '<STR_LIT>' in ConcreteEmployee . table . columns <EOL> assert '<STR_LIT>' in ConcreteEmployee . table . columns <EOL> assert '<STR_LIT>' in ConcreteEmployee . table . columns <EOL> assert '<STR_LIT>' in ConcreteEmployee . table . columns <EOL> assert '<STR_LIT>' in ConcreteCitizen . table . columns <EOL> assert '<STR_LIT>' in ConcreteCitizen . table . columns <EOL> assert '<STR_LIT>' not in ConcreteCitizen . table . columns <EOL> assert '<STR_LIT>' in ConcreteCitizen . table . columns <EOL> assert ConcreteCitizen . _descriptor . identity == '<STR_LIT>' <EOL> def test_simple_relation ( self ) : <EOL> class Page ( Entity ) : <EOL> title = Field ( String ( <NUM_LIT:30> ) ) <EOL> content = Field ( String ( <NUM_LIT:30> ) ) <EOL> comments = OneToMany ( '<STR_LIT>' ) <EOL> class AbstractAttachment ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> page = ManyToOne ( '<STR_LIT>' ) <EOL> is_spam = Field ( Boolean ( ) ) <EOL> class Comment ( AbstractAttachment ) : <EOL> message = Field ( String ( <NUM_LIT:100> ) ) <EOL> setup_all ( True ) <EOL> p1 = Page ( title = "<STR_LIT>" , content = "<STR_LIT>" ) <EOL> p1 . comments . append ( Comment ( message = '<STR_LIT>' , is_spam = False ) ) <EOL> assert p1 . comments [ <NUM_LIT:0> ] . page == p1 <EOL> session . commit ( ) <EOL> def test_simple_relation_abstract_wh_multiple_children ( self ) : <EOL> class Page ( Entity ) : <EOL> title = Field ( String ( <NUM_LIT:30> ) ) <EOL> content = Field ( String ( <NUM_LIT:30> ) ) <EOL> comments = OneToMany ( '<STR_LIT>' ) <EOL> links = OneToMany ( '<STR_LIT>' ) <EOL> class AbstractAttachment ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> page = ManyToOne ( '<STR_LIT>' ) <EOL> is_spam = Field ( Boolean ( ) ) <EOL> class Link ( AbstractAttachment ) : <EOL> url = Field ( String ( <NUM_LIT:30> ) ) <EOL> class Comment ( AbstractAttachment ) : <EOL> message = Field ( String ( <NUM_LIT:100> ) ) <EOL> setup_all ( True ) <EOL> p1 = Page ( title = "<STR_LIT>" , content = "<STR_LIT>" ) <EOL> p1 . comments . append ( Comment ( message = '<STR_LIT>' , is_spam = False ) ) <EOL> p1 . links . append ( Link ( url = "<STR_LIT>" , is_spam = True ) ) <EOL> assert p1 . comments [ <NUM_LIT:0> ] . page == p1 <EOL> session . commit ( ) <EOL> def test_multiple_inheritance ( self ) : <EOL> class AbstractDated ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( tablename = camel_to_underscore ) <EOL> created_date = Field ( DateTime ) <EOL> modified_date = Field ( DateTime ) <EOL> class AbstractContact ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( identity = camel_to_underscore ) <EOL> first_name = Field ( Unicode ( <NUM_LIT:50> ) ) <EOL> last_name = Field ( Unicode ( <NUM_LIT:50> ) ) <EOL> class DatedContact ( AbstractContact , AbstractDated ) : <EOL> pass <EOL> setup_all ( True ) <EOL> assert '<STR_LIT>' in DatedContact . table . columns <EOL> assert '<STR_LIT>' in DatedContact . table . columns <EOL> assert '<STR_LIT>' in DatedContact . table . columns <EOL> assert '<STR_LIT>' in DatedContact . table . columns <EOL> assert DatedContact . _descriptor . identity == '<STR_LIT>' <EOL> assert DatedContact . table . name == '<STR_LIT>' <EOL> contact1 = DatedContact ( first_name = u"<STR_LIT>" , last_name = u"<STR_LIT>" ) <EOL> session . commit ( ) <EOL> def test_mixed_inheritance ( self ) : <EOL> class AbstractDated ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( tablename = camel_to_underscore ) <EOL> created_date = Field ( DateTime ) <EOL> modified_date = Field ( DateTime ) <EOL> class AbstractContact ( Entity ) : <EOL> using_options ( abstract = True ) <EOL> using_options_defaults ( identity = camel_to_underscore ) <EOL> first_name = Field ( Unicode ( <NUM_LIT:50> ) ) <EOL> last_name = Field ( Unicode ( <NUM_LIT:50> ) ) <EOL> class Contact ( AbstractContact ) : <EOL> using_options ( inheritance = '<STR_LIT>' ) <EOL> class MixedDatedContact ( AbstractDated , Contact ) : <EOL> using_options ( inheritance = '<STR_LIT>' ) <EOL> setup_all ( True ) <EOL> assert '<STR_LIT>' in MixedDatedContact . table . columns <EOL> assert '<STR_LIT>' in MixedDatedContact . table . columns <EOL> assert MixedDatedContact . _descriptor . identity == '<STR_LIT>' <EOL> assert MixedDatedContact . table . name == '<STR_LIT>' <EOL> contact1 = MixedDatedContact ( first_name = u"<STR_LIT>" , <EOL> last_name = u"<STR_LIT>" ) <EOL> session . commit ( ) </s>
