I'm considering just checking for terms in the sql statement produced from str(query). That way I don't have to muddle with the internals of Query. However, I do introduce table and column names from the DB into my test code as strings, which of course defeats one of the reasons for using SA. However, this is *just* test code, and when I change column names in the DB and the tests fail, I''l change the tests. The alternative would to be to change the tests when the internals of Query change, which I don't have as much control over.
Thanks for the insight. On Aug 27, 10:58 am, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Aug 27, 1:24 pm, Bryan <bryanv...@gmail.com> wrote: > > > I am writing a function that adds particular columns and groupings to > > a query based on some options. I am trying to write some unit tests > > for the function, and would like to check that the correct columns are > > being added/grouped. > > > Give a query like: > > > q = session.query(Employee.firstName, Employee.lastName) > > > How can I check later that the query object has included > > Employee.firstName in the output columns? > > for output columns, we have recently added a method for this purpose > as of version 0.6.3: > > http://www.sqlalchemy.org/docs/reference/orm/query.html#sqlalchemy.or... > > I'm using it successfully in a library that converts Query objects > into Excel spreadsheets with xlwt. > > > Similarly, how can I check, for instance, that the query object is > > grouping on Employee.lastName? > > stuff like that is semi-private but relatively stable, most are > available by names like query._group_by, query._order_by, > query._criterion. If you look at the top of the Query class (the > source), they are all defaulted at the class level. > > Semi-private because I really don't want to push things like that to > be first class accessors until we are super certain nothing is > changing there. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.