Exemplo n.º 1
0
    def _drop_column(self, table, column):
        cursor = sqlite3.connect(self.db).cursor()
        start = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        squeak = Squeak(self.db, table)
        squeak.drop_column(column)

        cursor = sqlite3.connect(self.db).cursor()
        end = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        return self.assert_(start == end + 1)
Exemplo n.º 2
0
    def _rename_column(self, table, column):
        cursor = sqlite3.connect(self.db).cursor()
        start = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        squeak = Squeak(self.db, table)
        squeak.rename_column(column, "%s_renamed" % column)

        was_renamed = False
        for field in squeak.fields:
            if re.match("[\"']%s_renamed" % column, field):
                was_renamed = True
                break

        cursor = sqlite3.connect(self.db).cursor()
        end = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        return self.assert_(start == end and was_renamed)
Exemplo n.º 3
0
def main():
    duck = MallardDuck()
    duck.swin()
    duck.display()
    duck.performFly()
    duck.performQuack()
    duck.setFlyBehavior(FlyNoWay())
    duck.setQuackBehavior(Squeak())
    duck.performFly()
    duck.performQuack()
Exemplo n.º 4
0
    def _replace_definition(self, table, column, new_definition):
        cursor = sqlite3.connect(self.db).cursor()
        start = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        squeak = Squeak(self.db, table)
        squeak.replace_definition(column, new_definition)

        was_replaced = False
        for field in squeak.fields:
            m = re.match(r'^["\']?(%s)["\']?\s(.*)' % column, field)
            if m and m.group(1) == column and m.group(2) == new_definition:
                was_replaced = True
                break

        cursor = sqlite3.connect(self.db).cursor()
        end = len(cursor.execute("SELECT * from %s" % table).fetchone())
        cursor.close()

        return self.assert_(start == end and was_replaced)