On Thu, May 18, 2017 at 11:56 PM, jan.karstens via sqlalchemy <
sqlalchemy@googlegroups.com> wrote:

> Upgrading a specific dialect (EXASOL) to 1.1.9 made me stumble across this
> test (part of test_reflection.py):
>
> https://github.com/zzzeek/sqlalchemy/blob/rel_1_1_9/lib/
> sqlalchemy/testing/suite/test_reflection.py#L737
>
> def test_get_table_names(self):
> tablenames = [
> t for t in inspect(testing.db).get_table_names()
> if t.lower() in ("t1", "t2")]
> eq_(tablenames[0].upper(), tablenames[0].lower())
> eq_(tablenames[1].upper(), tablenames[1].lower())
>
> The test case fails and this does not look too unexpected to me. The
> tables T1 and T2 are added to the tablenames array, and u"t1".upper() is
> always different from u"t1".lower().
>
> Am I missing the purpose of the test case or is this always bound to fail?
>

This piqued my interest, so I did a bit of digging. The tables are defined
using the "quoted_name" class with quote=True:

https://github.com/zzzeek/sqlalchemy/blob/rel_1_1_9/lib/sqlalchemy/testing/suite/test_reflection.py#L717

https://github.com/zzzeek/sqlalchemy/blob/rel_1_1_9/lib/sqlalchemy/sql/elements.py#L3872

That class defines _memoized_method_lower() and _memoized_method_upper()
methods, and inherits from the MemoizedSlots class:

    def _memoized_method_lower(self):
        if self.quote:
            return self
        else:
            return util.text_type(self).lower()

https://github.com/zzzeek/sqlalchemy/blob/rel_1_1_9/lib/sqlalchemy/util/langhelpers.py#L817

The result is that .upper() and .lower() call those memoized methods,
rather than the base string implementations. When self.quote is True, those
methods both return self unchanged. So "eq_(tablenames[0].upper(),
tablenames[0].lower())" should succeed.

I guess the intention of the test is to check that the inspection routines
return a quoted_name with quote=True.

Hope that helps,

Simon

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to