<commit_before>import testbase
from datetime import datetime

from sqlalchemy.ext.activemapper           import ActiveMapper, column, one_to_many, one_to_one, many_to_many, objectstore
from sqlalchemy             import and_, or_, exceptions
from sqlalchemy             import ForeignKey, String, Integer, DateTime, Table, Column
from sqlalchemy.orm         import clear_mappers, backref, create_session, class_mapper
import sqlalchemy.ext.activemapper as activemapper
import sqlalchemy
from testlib import *


class testcase(PersistTest):
    def setUpAll(self):
        clear_mappers()
        objectstore.clear()
        global Person, Preferences, Address
        
        class Person(ActiveMapper):
            class mapping:
                __version_id_col__ = 'row_version'
                full_name   = column(String)
                first_name  = column(String)
                middle_name = column(String)
                last_name   = column(String)
                birth_date  = column(DateTime)
                ssn         = column(String)
                gender      = column(String)
                home_phone  = column(String)
                cell_phone  = column(String)
                work_phone  = column(String)
                row_version = column(Integer, default=0)
                prefs_id    = column(Integer, foreign_key=ForeignKey('preferences.id'))
                addresses   = one_to_many('Address', colname='person_id', backref='person', order_by=['state', 'city', 'postal_code'])
                preferences = one_to_one('Preferences', colname='pref_id', backref='person')

            def __str__(self):
                s =  '%s\n' % self.full_name
                s += '  * birthdate: %s\n' % (self.birth_date or 'not provided')
                s += '  * fave color: %s\n' % (self.preferences.favorite_color or 'Unknown')
                s += '  * personality: %s\n' % (self.preferences.personality_type or 'Unknown')

                for address in self.addresses:
                    s += '  * address: %s\n' % address.address_1
                    s += '             %s, %s %s\n' % (address.city, address.state, address.postal_code)

                return s

        class Preferences(ActiveMapper):
            class mapping:
                __table__        = 'preferences'
                favorite_color   = column(String)
                personality_type = column(String)

        class Address(ActiveMapper):
            class mapping:
                # note that in other objects, the 'id' primary key is 
                # automatically added -- if you specify a primary key,
                # then ActiveMapper will not add an integer primary key
                # for you.
                id          = column(Integer, primary_key=True)
                type        = column(String)
                address_1   = column(String)
                city        = column(String)
                state       = column(String)
                postal_code = column(String)
                person_id   = column(Integer, foreign_key=ForeignKey('person.id'))

        activemapper.metadata.connect(testbase.db)
        activemapper.create_tables()
    
    def tearDownAll(self):
        clear_mappers()
        activemapper.drop_tables()
        
    def tearDown(self):
        for t in activemapper.metadata.table_iterator(reverse=True):
            t.delete().execute()
    
    def create_person_one(self):
        # create a person
        p1 = Person(
                full_name='<NAME>',
                birth_date=datetime(1979, 10, 12),
                preferences=Preferences(
                                favorite_color='Green',
                                personality_type='ENTP'
                            ),
                addresses=[
                    Address(
                        address_1='123 Some Great Road.',
                        city='Atlanta',
                        state='GA',<commit_msg>Changed some columns from TEXT to VARCHAR for sapdb.<commit_after>import testbase
from datetime import datetime

from sqlalchemy.ext.activemapper           import ActiveMapper, column, one_to_many, one_to_one, many_to_many, objectstore
from sqlalchemy             import and_, or_, exceptions
from sqlalchemy             import ForeignKey, String, Integer, DateTime, Table, Column
from sqlalchemy.orm         import clear_mappers, backref, create_session, class_mapper
import sqlalchemy.ext.activemapper as activemapper
import sqlalchemy
from testlib import *


class testcase(PersistTest):
    def setUpAll(self):
        clear_mappers()
        objectstore.clear()
        global Person, Preferences, Address
        
        class Person(ActiveMapper):
            class mapping:
                __version_id_col__ = 'row_version'
                full_name   = column(String)
                first_name  = column(String)
                middle_name = column(String)
                last_name   = column(String)
                birth_date  = column(DateTime)
                ssn         = column(String)
                gender      = column(String)
                home_phone  = column(String)
                cell_phone  = column(String)
                work_phone  = column(String)
                row_version = column(Integer, default=0)
                prefs_id    = column(Integer, foreign_key=ForeignKey('preferences.id'))
                addresses   = one_to_many('Address', colname='person_id', backref='person', order_by=['state', 'city', 'postal_code'])
                preferences = one_to_one('Preferences', colname='pref_id', backref='person')

            def __str__(self):
                s =  '%s\n' % self.full_name
                s += '  * birthdate: %s\n' % (self.birth_date or 'not provided')
                s += '  * fave color: %s\n' % (self.preferences.favorite_color or 'Unknown')
                s += '  * personality: %s\n' % (self.preferences.personality_type or 'Unknown')

                for address in self.addresses:
                    s += '  * address: %s\n' % address.address_1
                    s += '             %s, %s %s\n' % (address.city, address.state, address.postal_code)

                return s

        class Preferences(ActiveMapper):
            class mapping:
                __table__        = 'preferences'
                favorite_color   = column(String(128))
                personality_type = column(String)

        class Address(ActiveMapper):
            class mapping:
                # note that in other objects, the 'id' primary key is 
                # automatically added -- if you specify a primary key,
                # then ActiveMapper will not add an integer primary key
                # for you.
                id          = column(Integer, primary_key=True)
                type        = column(String)
                address_1   = column(String)
                city        = column(String)
                state       = column(String)
                postal_code = column(String(128))
                person_id   = column(Integer, foreign_key=ForeignKey('person.id'))

        activemapper.metadata.connect(testbase.db)
        activemapper.create_tables()
    
    def tearDownAll(self):
        clear_mappers()
        activemapper.drop_tables()
        
    def tearDown(self):
        for t in activemapper.metadata.table_iterator(reverse=True):
            t.delete().execute()
    
    def create_person_one(self):
        # create a person
        p1 = Person(
                full_name='<NAME>',
                birth_date=datetime(1979, 10, 12),
                preferences=Preferences(
                                favorite_color='Green',
                                personality_type='ENTP'
                            ),
                addresses=[
                    Address(
                        address_1='123 Some Great Road.',
                        city='Atlanta',
                        state='GA',
{'fraction_non_alphanumeric': 0.08678772698810269, 'fraction_numerical': 0.004758922980588604, 'mean_word_length': 1.6166448230668413, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2610521', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2011, 'n_words': 477}