sqlalchemy.testing.schema.Column

Here are the examples of the python api sqlalchemy.testing.schema.Column taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: SickGear
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 2

Project: SickGear
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 3

Project: SickGear
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 4

Project: SickRage
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 5

Project: SickRage
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 6

Project: SickRage
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 7

Project: moviegrabber
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
                Column('id', Integer, primary_key=True),
                Column('data', String(50))
            )

Example 8

Project: moviegrabber
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                    *[
                        Column('t%d' % i, type_)
                        for i, type_ in enumerate(types)
                    ]
                )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 9

Project: moviegrabber
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                        Column('a', Integer, nullable=True),
                        Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 10

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('test_table', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(50))
              )

Example 11

Project: sqlalchemy
Source File: test_reflection.py
View license
    @testing.provide_metadata
    def _type_round_trip(self, *types):
        t = Table('t', self.metadata,
                  *[
                      Column('t%d' % i, type_)
                      for i, type_ in enumerate(types)
                  ]
                  )
        t.create()

        return [
            c['type'] for c in
            inspect(self.metadata.bind).get_columns('t')
        ]

Example 12

Project: sqlalchemy
Source File: test_reflection.py
View license
    @testing.requires.table_reflection
    @testing.provide_metadata
    def test_nullable_reflection(self):
        t = Table('t', self.metadata,
                  Column('a', Integer, nullable=True),
                  Column('b', Integer, nullable=False))
        t.create()
        eq_(
            dict(
                (col['name'], col['nullable'])
                for col in inspect(self.metadata.bind).get_columns('t')
            ),
            {"a": True, "b": False}
        )

Example 13

Project: sqlalchemy
Source File: test_memusage.py
View license
    def test_path_registry(self):
        metadata = MetaData()
        a = Table("a", metadata,
                  Column('id', Integer, primary_key=True),
                  Column('foo', Integer),
                  Column('bar', Integer)
                  )
        m1 = mapper(A, a)

        @profile_memory()
        def go():
            ma = sa.inspect(aliased(A))
            m1._path_registry[m1.attrs.foo][ma][m1.attrs.bar]
        go()
        clear_mappers()

Example 14

Project: sqlalchemy
Source File: test_memusage.py
View license
    @testing.provide_metadata
    def test_key_fallback_result(self):
        e = self.engine
        m = self.metadata
        t = Table('t', m, Column('x', Integer), Column('y', Integer))
        m.create_all(e)
        e.execute(t.insert(), {"x": 1, "y": 1})

        @profile_memory()
        def go():
            r = e.execute(t.alias().select())
            for row in r:
                row[t.c.x]
        go()

Example 15

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('parent', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(20)),
              Column('child_id', Integer, ForeignKey('child.id'))
              )

        Table('child', metadata,
              Column('id', Integer, primary_key=True),
              Column('data', String(20))
              )

Example 16

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('a', metadata,
              Column('id', Integer, primary_key=True),
              Column('c_id', Integer, ForeignKey('c.id'))
              )
        Table('b', metadata,
              Column('id', Integer, primary_key=True),
              Column('a_id', Integer, ForeignKey('a.id'))
              )
        Table('c', metadata,
              Column('id', Integer, primary_key=True),
              )
        Table('d', metadata,
              Column('id', Integer, primary_key=True),
              Column('a_id', Integer, ForeignKey('a.id'))
              )

Example 17

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('a', metadata,
              Column('id', Integer, primary_key=True),
              Column('x', String(5)),
              Column('y', String(5)),
              Column('z', String(5)),
              Column('q', String(5)),
              Column('p', String(5)),
              Column('r', String(5)),
              )

Example 18

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table(
            'parent',
            metadata,
            Column('id', Integer,
                   primary_key=True, test_needs_autoincrement=True),
            Column('data', String(20)))
        Table(
            'child', metadata,
            Column('id', Integer, primary_key=True,
                   test_needs_autoincrement=True),
            Column(
                'data', String(20)), Column(
                'parent_id', Integer, ForeignKey('parent.id'), nullable=False))

Example 19

Project: sqlalchemy
Source File: test_orm.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table(
            'parent',
            metadata,
            Column('id', Integer,
                   primary_key=True, test_needs_autoincrement=True),
            Column('data1', String(20)),
            Column('data2', String(20)),
            Column('data3', String(20)),
            Column('data4', String(20)),
        )

Example 20

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_explicit(self):
        metadata = MetaData()
        table = Table('test_table', metadata,
            Column('foo', Integer))
        for bind in (
            testing.db,
            testing.db.connect()
        ):
            for args in [
                ([], {'bind': bind}),
                ([bind], {})
            ]:
                metadata.create_all(*args[0], **args[1])
                assert table.exists(*args[0], **args[1])
                metadata.drop_all(*args[0], **args[1])
                table.create(*args[0], **args[1])
                table.drop(*args[0], **args[1])
                assert not table.exists(*args[0], **args[1])

Example 21

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_err_metadata(self):
        metadata = MetaData()
        Table('test_table', metadata, Column('foo', Integer))
        for meth in [metadata.create_all, metadata.drop_all]:
            assert_raises_message(
                exc.UnboundExecutionError,
                "MetaData object is not bound to an Engine or Connection.",
                meth
            )

Example 22

Project: sqlalchemy
Source File: test_bind.py
View license
    def test_create_drop_err_table(self):
        metadata = MetaData()
        table = Table('test_table', metadata,
            Column('foo', Integer))

        for meth in [
            table.exists,
            table.create,
            table.drop,
        ]:
            assert_raises_message(
                exc.UnboundExecutionError,
                ("Table object 'test_table' is not bound to an Engine or "
                 "Connection."),
                meth
            )

Example 23

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    def setup(self):
        self.engine = engines.mock_engine()
        self.metadata = MetaData(self.engine)
        self.users = Table('users', self.metadata,
                           Column('user_id', Integer, primary_key=True),
                           Column('user_name', String(40)),
                           )

Example 24

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    def test_filter(self):
        cx = self.mock_engine()

        tbl = Table('t', MetaData(), Column('id', Integer))
        target = cx.name

        assert DDL('')._should_execute(tbl, cx)
        assert DDL('').execute_if(dialect=target)._should_execute(tbl, cx)
        assert not DDL('').execute_if(dialect='bogus').\
                        _should_execute(tbl, cx)
        assert DDL('').execute_if(callable_=lambda d, y, z, **kw: True).\
                        _should_execute(tbl, cx)
        assert(DDL('').execute_if(
                        callable_=lambda d, y, z, **kw: z.engine.name
                        != 'bogus').
               _should_execute(tbl, cx))

Example 25

Project: sqlalchemy
Source File: test_ddlevents.py
View license
    @testing.uses_deprecated(r'See DDLEvents')
    def test_filter_deprecated(self):
        cx = self.mock_engine()

        tbl = Table('t', MetaData(), Column('id', Integer))
        target = cx.name

        assert DDL('')._should_execute_deprecated('x', tbl, cx)
        assert DDL('', on=target)._should_execute_deprecated('x', tbl, cx)
        assert not DDL('', on='bogus').\
                        _should_execute_deprecated('x', tbl, cx)
        assert DDL('', on=lambda d, x, y, z: True).\
                        _should_execute_deprecated('x', tbl, cx)
        assert(DDL('', on=lambda d, x, y, z: z.engine.name != 'bogus').
               _should_execute_deprecated('x', tbl, cx))

Example 26

Project: sqlalchemy
Source File: test_reconnect.py
View license
    def setup(self):
        self.engine = engines.reconnecting_engine()
        self.meta = MetaData(self.engine)
        table = Table(
            'sometable', self.meta,
            Column('id', Integer, primary_key=True),
            Column('name', String(50)))
        self.meta.create_all()
        table.insert().execute(
            [{'id': i, 'name': 'row %d' % i} for i in range(1, 100)]
        )

Example 27

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("a", metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              )
        Table("b", metadata,
              Column('id', Integer,
                     ForeignKey('a.id'),
                     primary_key=True),
              Column('x', Integer, primary_key=True)
              )

Example 28

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('users', metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              Column('name', String(50)), test_needs_fk=True)
        Table(
            'addresses',
            metadata,
            Column('id', Integer, primary_key=True,
                   test_needs_autoincrement=True),
            Column('email', String(50)),
            Column('user_id', Integer, ForeignKey('users.id')),
            test_needs_fk=True,
        )

Example 29

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_redefine_fk_double(self):
        class User(decl.DeferredReflection, fixtures.ComparableEntity,
                   Base):
            __tablename__ = 'users'
            addresses = relationship("Address", backref="user")

        class Address(decl.DeferredReflection, fixtures.ComparableEntity,
                      Base):
            __tablename__ = 'addresses'
            user_id = Column(Integer, ForeignKey('users.id'))

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 30

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table('users', metadata,
              Column('id', Integer,
                     primary_key=True, test_needs_autoincrement=True),
              Column('name', String(50)), test_needs_fk=True)

        Table('user_items', metadata,
              Column('user_id', ForeignKey('users.id'), primary_key=True),
              Column('item_id', ForeignKey('items.id'), primary_key=True),
              test_needs_fk=True
              )

        Table('items', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('name', String(50)),
              test_needs_fk=True
              )

Example 31

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("foo", metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('type', String(32)),
              Column('data', String(30)),
              Column('bar_data', String(30))
              )

Example 32

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_add_subclass_column(self):
        class Foo(decl.DeferredReflection, fixtures.ComparableEntity,
                  Base):
            __tablename__ = 'foo'
            __mapper_args__ = {"polymorphic_on": "type",
                               "polymorphic_identity": "foo"}

        class Bar(Foo):
            __mapper_args__ = {"polymorphic_identity": "bar"}
            bar_data = Column(String(30))

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 33

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_add_pk_column(self):
        class Foo(decl.DeferredReflection, fixtures.ComparableEntity,
                  Base):
            __tablename__ = 'foo'
            __mapper_args__ = {"polymorphic_on": "type",
                               "polymorphic_identity": "foo"}
            id = Column(Integer, primary_key=True)

        class Bar(Foo):
            __mapper_args__ = {"polymorphic_identity": "bar"}

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 34

Project: sqlalchemy
Source File: test_reflection.py
View license
    @classmethod
    def define_tables(cls, metadata):
        Table("foo", metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('type', String(32)),
              Column('data', String(30)),
              test_needs_fk=True,
              )
        Table('bar', metadata,
              Column('id', Integer, ForeignKey('foo.id'), primary_key=True),
              Column('bar_data', String(30)),
              test_needs_fk=True,
              )

Example 35

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_add_subclass_column(self):
        class Foo(decl.DeferredReflection, fixtures.ComparableEntity,
                  Base):
            __tablename__ = 'foo'
            __mapper_args__ = {"polymorphic_on": "type",
                               "polymorphic_identity": "foo"}

        class Bar(Foo):
            __tablename__ = 'bar'
            __mapper_args__ = {"polymorphic_identity": "bar"}
            bar_data = Column(String(30))

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 36

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_add_pk_column(self):
        class Foo(decl.DeferredReflection, fixtures.ComparableEntity,
                  Base):
            __tablename__ = 'foo'
            __mapper_args__ = {"polymorphic_on": "type",
                               "polymorphic_identity": "foo"}
            id = Column(Integer, primary_key=True)

        class Bar(Foo):
            __tablename__ = 'bar'
            __mapper_args__ = {"polymorphic_identity": "bar"}

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 37

Project: sqlalchemy
Source File: test_reflection.py
View license
    def test_add_fk_pk_column(self):
        class Foo(decl.DeferredReflection, fixtures.ComparableEntity,
                  Base):
            __tablename__ = 'foo'
            __mapper_args__ = {"polymorphic_on": "type",
                               "polymorphic_identity": "foo"}

        class Bar(Foo):
            __tablename__ = 'bar'
            __mapper_args__ = {"polymorphic_identity": "bar"}
            id = Column(Integer, ForeignKey('foo.id'), primary_key=True)

        decl.DeferredReflection.prepare(testing.db)
        self._roundtrip()

Example 38

Project: sqlalchemy
Source File: test_hybrid.py
View license
    def _fixture(self, assignable):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column(Integer, primary_key=True)
            _value = Column("value", String)

            @hybrid.hybrid_property
            def value(self):
                return self._value - 5

            if assignable:
                @value.setter
                def value(self, v):
                    self._value = v + 5

        return A

Example 39

Project: sqlalchemy
Source File: test_hybrid.py
View license
    def _fixture(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column(Integer, primary_key=True)
            _value = Column("value", String)

            @hybrid.hybrid_property
            def value(self):
                "This is an instance-level docstring"
                return self._value
        return A

Example 40

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_array_longinit(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column('id', Integer, primary_key=True)
            array = Column('_array', ARRAY(Integer),
                           default=[])
            first = index_property('array', 0)

            fifth = index_property('array', 4)

        a1 = A(fifth=10)
        a2 = A(first=5)

        eq_(a1.array, [None, None, None, None, 10])
        eq_(a2.array, [5])

        assert_raises(IndexError, setattr, a2, "fifth", 10)

Example 41

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_json(self):
        Base = declarative_base()

        class J(Base):
            __tablename__ = 'j'
            id = Column('id', Integer, primary_key=True)
            json = Column('_json', JSON, default={})
            field = index_property('json', 'field')

        j = J(json={'a': 1, 'b': 2})
        assert_raises(AttributeError, lambda: j.field)
        j.field = 'test'
        eq_(j.field, 'test')
        eq_(j.json, {'a': 1, 'b': 2, 'field': 'test'})

        j2 = J(field='test')
        eq_(j2.json, {"field": "test"})
        eq_(j2.field, "test")

Example 42

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_value_is_none_attributeerror(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column('id', Integer, primary_key=True)
            array = Column('_array', ARRAY(Integer))
            first = index_property('array', 1)

        a = A()
        assert_raises(AttributeError, getattr, a, "first")

        assert_raises(AttributeError, delattr, a, "first")

Example 43

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_get_attribute_error(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column('id', Integer, primary_key=True)
            array = Column('_array', ARRAY(Integer))
            first = index_property('array', 1)

        a = A(array=[])
        assert_raises(AttributeError, lambda: a.first)

Example 44

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_set_immutable(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = 'a'
            id = Column(Integer, primary_key=True)
            array = Column(ARRAY(Integer))
            first = index_property('array', 1, mutable=False)

        a = A()

        def set_():
            a.first = 10
        assert_raises(AttributeError, set_)

Example 45

Project: sqlalchemy
Source File: test_indexable.py
View license
    def test_set_mutable_dict(self):
        Base = declarative_base()

        class J(Base):
            __tablename__ = 'j'
            id = Column(Integer, primary_key=True)
            json = Column(JSON, default={})
            field = index_property('json', 'field')

        j = J()

        j.field = 10

        j.json = {}
        assert_raises(AttributeError, lambda: j.field)
        assert_raises(AttributeError, delattr, j, "field")

        j.field = 10
        eq_(j.field, 10)

Example 46

Project: sqlalchemy
Source File: test_indexable.py
View license
    @classmethod
    def setup_classes(cls):
        Base = cls.DeclarativeBasic

        class Array(fixtures.ComparableEntity, Base):
            __tablename__ = "array"

            id = Column(sa.Integer, primary_key=True,
                        test_needs_autoincrement=True)
            array = Column(ARRAY(Integer), default=[])
            array0 = Column(ARRAY(Integer, zero_indexes=True), default=[])
            first = index_property('array', 0)
            first0 = index_property('array0', 0, onebased=False)

Example 47

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableDict = cls._type_fixture()

        mutable_pickle = MutableDict.as_mutable(PickleType)
        Table(
            'foo', metadata,
            Column(
                'id', Integer, primary_key=True,
                test_needs_autoincrement=True),
            Column('data', mutable_pickle, default={}),
        )

Example 48

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableDict = cls._type_fixture()

        mutable_pickle = MutableDict.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 49

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableList = cls._type_fixture()

        mutable_pickle = MutableList.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )

Example 50

Project: sqlalchemy
Source File: test_mutable.py
View license
    @classmethod
    def define_tables(cls, metadata):
        MutableSet = cls._type_fixture()

        mutable_pickle = MutableSet.as_mutable(PickleType)
        Table('foo', metadata,
              Column('id', Integer, primary_key=True,
                     test_needs_autoincrement=True),
              Column('skip', mutable_pickle),
              Column('data', mutable_pickle),
              Column('non_mutable_data', PickleType),
              Column('unrelated_data', String(50))
              )