def test_compare_binds(self):
        b1 = bindparam("foo", type_=Integer())
        b2 = bindparam("foo", type_=Integer())
        b3 = bindparam("bar", type_=Integer())
        b4 = bindparam("foo", type_=String())

        def c1():
            return 5

        def c2():
            return 6

        b5 = bindparam("foo", type_=Integer(), callable_=c1)
        b6 = bindparam("foo", type_=Integer(), callable_=c2)
        b7 = bindparam("foo", type_=Integer(), callable_=c1)

        b8 = bindparam("foo", type_=Integer, value=5)
        b9 = bindparam("foo", type_=Integer, value=6)

        is_false(b1.compare(b5))
        is_true(b5.compare(b7))
        is_false(b5.compare(b6))
        is_true(b1.compare(b2))

        # currently not comparing "key", as we often have to compare
        # anonymous names.  however we should really check for that
        is_true(b1.compare(b3))

        is_false(b1.compare(b4))
        is_false(b1.compare(b8))
        is_false(b8.compare(b9))
        is_true(b8.compare(b8))
    def test_compare_clauselist_assoc_different_operator(self):

        l1 = and_(self.a.c.x == self.b.c.y, self.a.c.y == self.b.c.z)

        l2 = or_(self.a.c.y == self.b.c.z, self.a.c.x == self.b.c.y)

        is_false(l1.compare(l2))
    def test_compare_clauselist_associative(self):

        l1 = and_(self.a.c.x == self.b.c.y, self.a.c.y == self.b.c.z)

        l2 = and_(self.a.c.y == self.b.c.z, self.a.c.x == self.b.c.y)

        l3 = and_(self.a.c.x == self.b.c.z, self.a.c.y == self.b.c.y)

        is_true(l1.compare(l1))
        is_true(l1.compare(l2))
        is_false(l1.compare(l3))
    def test_compare_clauselist_not_assoc_different_operator(self):

        l1 = ClauseList(self.a.c.x,
                        self.a.c.y,
                        self.b.c.y,
                        operator=operators.sub)

        l2 = ClauseList(self.a.c.x,
                        self.a.c.y,
                        self.b.c.y,
                        operator=operators.div)

        is_false(l1.compare(l2))
    def test_compare_clauselist_not_associative(self):

        l1 = ClauseList(self.a.c.x,
                        self.a.c.y,
                        self.b.c.y,
                        operator=operators.sub)

        l2 = ClauseList(self.b.c.y,
                        self.a.c.x,
                        self.a.c.y,
                        operator=operators.sub)

        is_true(l1.compare(l1))
        is_false(l1.compare(l2))
    def test_dont_use_get_pj_is_different(self):
        mapper(self.classes.A, self.tables.a)
        m_b = mapper(
            self.classes.B,
            self.tables.b_sameorder,
            properties={
                "a":
                relationship(
                    self.classes.A,
                    primaryjoin=and_(
                        self.tables.a.c.id1 == self.tables.b_sameorder.c.a_id1,
                        self.tables.a.c.id2 == 12,
                    ),
                )
            },
        )

        configure_mappers()
        is_false(m_b.relationships.a.strategy.use_get)
    def test_comparison(self):
        components = (
            "drivername",
            "username",
            "password",
            "host",
            "database",
            "query",
            "port",
        )

        common_url = (
            "dbtype://*****:*****@[2001:da8:2004:1000:202:116:160:90]:80/database?foo=bar"
        )
        other_url = "dbtype://*****:*****@host/"

        url1 = url.make_url(common_url)
        url2 = url.make_url(common_url)
        url3 = url.make_url(other_url)

        is_true(url1 == url2)
        is_false(url1 != url2)
        is_true(url1 != url3)
        is_false(url1 == url3)

        for curr_component in components:
            setattr(url2, curr_component, "new_changed_value")
            is_true(url1 != url2)
            is_false(url1 == url2)
            setattr(url2, curr_component, getattr(url1, curr_component))
Exemple #8
0
    def test_dialect_initialize_retry_if_exception(self):
        from sqlalchemy_1_3.engine.url import URL
        from sqlalchemy_1_3.engine.default import DefaultDialect

        dbapi = self.dbapi

        class MyURL(URL):
            def _get_entrypoint(self):
                return Dialect

            def get_dialect(self):
                return Dialect

        class Dialect(DefaultDialect):
            initialize = Mock()

        # note that the first_connect hook is only invoked when the pool
        # makes a new DBAPI connection, and not when it checks out an existing
        # connection.  So there is a dependency here that if the initializer
        # raises an exception, the pool-level connection attempt is also
        # failed, meaning no DBAPI connection is pooled.  If the first_connect
        # exception raise did not prevent the connection from being pooled,
        # there could be the case where the pool could return that connection
        # on a subsequent attempt without initialization having proceeded.

        Dialect.initialize.side_effect = TypeError
        engine = create_engine(MyURL("foo://"), module=dbapi)

        assert_raises(TypeError, engine.connect)
        eq_(Dialect.initialize.call_count, 1)
        is_true(engine.pool._pool.empty())

        assert_raises(TypeError, engine.connect)
        eq_(Dialect.initialize.call_count, 2)
        is_true(engine.pool._pool.empty())

        engine.dispose()

        assert_raises(TypeError, engine.connect)
        eq_(Dialect.initialize.call_count, 3)
        is_true(engine.pool._pool.empty())

        Dialect.initialize.side_effect = None

        conn = engine.connect()
        eq_(Dialect.initialize.call_count, 4)
        conn.close()
        is_false(engine.pool._pool.empty())

        conn = engine.connect()
        eq_(Dialect.initialize.call_count, 4)
        conn.close()
        is_false(engine.pool._pool.empty())

        engine.dispose()
        conn = engine.connect()

        eq_(Dialect.initialize.call_count, 4)
        conn.close()
        is_false(engine.pool._pool.empty())