<commit_before>"""tests that various From objects properly export their columns, as well as useable primary keys
and foreign keys.  Full relational algebra depends on every selectable unit behaving
nicely with others.."""

import testbase
import unittest, sys, datetime


db = testbase.db

from sqlalchemy import *


table = Table('table1', db, 
    Column('col1', Integer, primary_key=True),
    Column('col2', String(20)),
    Column('col3', Integer),
    redefine=True
)

table2 = Table('table2', db,
    Column('col1', Integer, primary_key=True),
    Column('col2', Integer, ForeignKey('table1.col1')),
    Column('col3', String(20)),
    redefine=True
)

class SelectableTest(testbase.AssertMixin):
    def testtablealias(self):
        a = table.alias('a')
        
        j = join(a, table2)
        
        criterion = a.c.col1 == table2.c.col2
        print
        print str(j)
        self.assert_(criterion.compare(j.onclause))

    def testjoin(self):
        a = join(table, table2)
        print str(a.select(use_labels=True))<commit_msg>hypothetical (failing) test for primary key selection of joins<commit_after>"""tests that various From objects properly export their columns, as well as useable primary keys
and foreign keys.  Full relational algebra depends on every selectable unit behaving
nicely with others.."""

import testbase
import unittest, sys, datetime


db = testbase.db

from sqlalchemy import *


table = Table('table1', db, 
    Column('col1', Integer, primary_key=True),
    Column('col2', String(20)),
    Column('col3', Integer),
    redefine=True
)

table2 = Table('table2', db,
    Column('col1', Integer, primary_key=True),
    Column('col2', Integer, ForeignKey('table1.col1')),
    Column('col3', String(20)),
    redefine=True
)

table3 = Table('table3', db, 
    Column('col1', Integer, ForeignKey('table1.col1'), primary_key=True),
    Column('col2', Integer),
    Column('col3', String(20)),
    redefine=True
    )

class SelectableTest(testbase.AssertMixin):
    def testtablealias(self):
        a = table.alias('a')
        
        j = join(a, table2)
        
        criterion = a.c.col1 == table2.c.col2
        print
        print str(j)
        self.assert_(criterion.compare(j.onclause))

    def testjoinpks(self):
        a = join(table, table3)
        b = join(table, table3, table.c.col1==table3.c.col2)
        c = join(table, table3, table.c.col2==table3.c.col2)
        d = join(table, table3, table.c.col2==table3.c.col1)
        
        self.assert_(a.primary_key==[table.c.col1])
        self.assert_(b.primary_key==[table.c.col1, table3.c.col1])
        self.assert_(c.primary_key==[table.c.col1, table3.c.col1])
        self.assert_(d.primary_key==[table.c.col1, table3.c.col1])
        
    def testjoin(self):
        a = join(table, table2)
        print str(a.select(use_labels=True))
{'fraction_non_alphanumeric': 0.13522012578616352, 'fraction_numerical': 0.025157232704402517, 'mean_word_length': 3.185672514619883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4289553', 'n_tokens_mistral': 961, 'n_tokens_neox': 939, 'n_words': 217}