[sqlalchemy] Re: inconsistent results between 2 testuites executions (SA 0.3.4)

2007-02-07 Thread svilen

  Why not just use util.Dict (defaulting to dict) instead of {}?
 
  Then whoever wants, replaces that with Ordered one and voila, all
  things get repeatable, if a little slower.

 the ordering of the data sent to the sort should not affect the
 outcome of the program.  therefore its important to test all kinds
 of orderings to ensure that the initial lists of dependencies are
 correct.  while you can hardcode the internal datastructures to use
 a deterministic ordering, that says nothing about the order in
 which the calling application inserts records into the UOW, which
 will then change the ordering anyway.
well, if one wants deterministic behavior all-over the chain, then one 
should feed SA with deterministic data as _first_ thing, and just 
then expect something.

This is about the 2 levels of testing: 
 - one, on the level of SQL, where ordering etc does matter; this 
sort-a tests SA _and_ one's-own-usage of it for correctness of the 
conversion to-sql and back
 - two, on the app/persistency/orm level, where u want the data in to 
match the data out no-matter-what's-in-between, is it sql or txt file 
or someone writing on a stone-plate. A thorough test here would also 
include writing on one machine and reading on another... 

All them ordering problems come on level one - while they should NOT 
matter on level 2.

It is not exactly/only in the topology-sort; it's all over. Any 
SQL-echo of - tables, columns, inserts, props - whatever - will 
change the next time u change the status of the machine.
i.e. a unittest which compares SQL-output, or most other SA-log, is 
hardly possible. (Object id's/adresses which will also change do not 
matter - a simple identity-map filter takes care of those easily).

for example, i've hacked dict to ordereddict in 6-7 choosen places, 
and this covered ~80% of the cases; but i still have cases which give 
differently ordered SQL everytime - i've missed something.
i don't have _enough_ internal knowledge of SA, hence finding which 
dicts are important for ordering and which not, takes big time - and 
time is a scarce resource; so i'll probably just mass-replace them 
all.

 i think my --reversetop solution will be sufficient for now, ive
 seen lots and lots of these issues in the past year and a half and
 a combination of testing with straight/reverse will pretty much
 bring all of them out.

okay, when u feel ready to replace the {} with util.Dict, just yell, 
i'll prepare the patch.

  i mentioned this dictionary-order on my ramblings some weeks ago;
  then u didnt take it into account.

 because i stop reading rambles after 50-60 words or so, and the
 stress of glossing over the rest generally causes me to forget
 words 30-60 as well.
hmmm. so u prefer problems one by one, or in a big list?
within 2 weeks we've fixed most of those mentioned there (see the end 
of it)... those which i do care about. Some still remain: 
polymorphics - are u ready to debug again (-:)? ticket 452. 
Other's i don't care - e.g. it does matter if engine is bound or not 
before doing tables - some cases work only if it is bound beforehand; 
or doing the 3rd non-primary mapper does require a pre-build 
_polymorphic_map, etc.

awww what a long post again
ciao
svil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: new setuptools vs local SA copy

2007-02-07 Thread Sébastien LELONG

 [...] I challenged him to name *any* scenario where an
 administrator would want a local-environment-based PYTHONPATH to be
 overridden by an application-wide configuration and he didnt reply to
 that one.  he sees it as a if youre using .eggs, then you must accept
 that PYTHONPATH only points to installation directories, not runtime
 directories...so basically breaking PYTHONPATH's documented behavior
 into something repurposed is by design.
I completely agree. I too have spent a lot of time finding why my PYTHONPATH 
was not considered anymore. Having it overridden is definitly not the 
expected behavior.

-- 
Sébastien LELONG
sebastien.lelong[at]sirloon.net



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: new setuptools vs local SA copy

2007-02-07 Thread svilen

u mean eggs will override pythonpath? that's bullshit!
one more reasone for me to hate eggs... be them cockroach' or python 
ones...

 as I have like 12 different SA directories which id like to jump
 between without going through a distinct install for each one, im a
 big fan of PYTHONPATH, and after futile-ly arguing with PJE that
 plain libraries on PYTHONPATH should take precedence over installed
 .eggs (he strongly feels that .eggs take precedence in all cases,
 although others agree with me), I hacked my Python install to work
 the way i wanted it:

 put a file -pythonpath.pth into your site_packages folder:

 import os, sys; sys.__egginsert=len(os.environ.get('PYTHONPATH',
 '').split(os.pathsep));
duly noted for future usage _when_ i meet an egg.

Here i have 4 SA installs, and switch them by re-pointing a symbolic 
link in the global site-packages/. Which would not be possble if the 
machine was shared - or i was using SA for something else that should 
not break.

 if people are interested in more organized petitioning of PJE to
 change his mind on this behavior, sign me up.  generally people
 seem to be unaware of it.  I challenged him to name *any* scenario
 where an administrator would want a local-environment-based
 PYTHONPATH to be overridden by an application-wide configuration
 and he didnt reply to that one.  he sees it as a if youre using
 .eggs, then you must accept that PYTHONPATH only points to
 installation directories, not runtime directories...so basically
 breaking PYTHONPATH's documented behavior into something repurposed
 is by design.

hell, The whole idea of 
having /home/my/bin /usr/local/bin /usr/bin /bin 
in this order in the path is exactly that: so more-local behavior can 
override more-global one (e.g. my own ls script overrides the 
me-installed new-version /usr/local/ one which overrides the global 
old-version /usr/bin/ which overrides the simplistic /bin one...

if he wants such behaviour, let him add a switch that force-ignores 
PYTHONPATH or whatever other env-vars, and let the default stuff in 
piece; all other reasonable apps behave this way.

svil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread svilen

 If you have the time and know how, do you know what the efficient
 way to iterate through all the class definitions in a module would
 be to grab all the classes that have a certain member?

import module
for k,v in module.__dict__.iteritems()
  if isinstance(v,type):
if issubclass(v, somebase): #i would advice this, it's up to u
if hasattr( v, yourmember):


btw. u should read the sources _more_, reading the docs aside.
What's the point of using interpreted language _and_ open-source  
otherwise?

 Ie If I add this field to an orm class

 class Page:
   admin_fields = [blahblah]

 then I want to grab that class from my controller code and read the
 admin field values. ( without having to say in the controller which
 ones have that )

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] offlist thanks Re: [sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread iain duncan

On Wed, 2007-07-02 at 11:53 +0200, svilen wrote:
  If you have the time and know how, do you know what the efficient
  way to iterate through all the class definitions in a module would
  be to grab all the classes that have a certain member?
 
 import module
 for k,v in module.__dict__.iteritems()
   if isinstance(v,type):
 if issubclass(v, somebase):   #i would advice this, it's up to u
   if hasattr( v, yourmember):
   
 

Thanks! I didn't know how to use iteritems that way
 btw. u should read the sources _more_, reading the docs aside.
 What's the point of using interpreted language _and_ open-source  
 otherwise?

yes I'm sure you're right. But the SA sources right now look a ways over
my head!

Anyway, thanks so much for the tips.

Iain



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: offlist thanks Re: [sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread iain duncan

Darn, apologies to all. Clearly I am too sleepy to be doing this as I
can't even work my mail client. :/

Thanks

On Wed, 2007-07-02 at 01:58 -0800, iain duncan wrote:
 On Wed, 2007-07-02 at 11:53 +0200, svilen wrote:
   If you have the time and know how, do you know what the efficient
   way to iterate through all the class definitions in a module would
   be to grab all the classes that have a certain member?
  
  import module
  for k,v in module.__dict__.iteritems()
if isinstance(v,type):
  if issubclass(v, somebase): #i would advice this, it's up to u
  if hasattr( v, yourmember):
  
  
 
 Thanks! I didn't know how to use iteritems that way
  btw. u should read the sources _more_, reading the docs aside.
  What's the point of using interpreted language _and_ open-source  
  otherwise?
 
 yes I'm sure you're right. But the SA sources right now look a ways over
 my head!
 
 Anyway, thanks so much for the tips.
 
 Iain
 
 
 
  


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread Sébastien LELONG

 Thanks. I've been using the inspect module but there's such a lot in
 there it's a bit dizzying!
FWIW, you can also use ipython and its dynamic object introspection, 
completion, etc... This helps a *lot* finding what you want. It's also 
usefull to dive into the sources, precisely where you want, since you can 
invoke the edit command on several python object. Give a try with:

In [9]: edit mytable.__class__.columns


Seb
-- 
Sébastien LELONG
sebastien.lelong[at]sirloon.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] list of strings/unicode strings

2007-02-07 Thread rgravina

Hello sqlalchemy users and developers!

I was wondering if there was a way to store a list of strings (or
unicode strings) and access them using a normal Python list when using
SQLAlchemy?

I've pasted my attempt at implementing a simple book database below
this message. You can specify a book's name and description, as well
tags as a list of unicode strings like this:

book = Book()
book.name = Python Cookbook
book.description = It's delicious!
book.tags = [UnicodeItem(python), UnicodeItem(programming)]

Running the code should output the book details:

$ python unicode_list.py
   name: Python Cookbook
description: It's delicious!
   tags: [python, programming]


Is there anyway I can specify the list of tags like this, instead?

book.tags = [upython, uprogramming]

What I'd like to do is be able to have other parts of my code use this
class like any other, and hide away the implementation details of my
sqlalchemy database.

Also, does anyone have any suggestions about how I could maintain the
order of this list as well?

Thanks,

Robert


from sqlalchemy import *

###
# SQLAlchemy code
###
unicode_item_table = Table('unicode_item',
Column('item_id', Integer, primary_key=True),
Column('value', Unicode(255)),
)
class UnicodeItem(object):
def __init__(self, value):
self.value = value
def __repr__(self):
return self.value
def __cmp__(self, other):
if isinstance(other, UnicodeItem):
return cmp(self.value, other.value)
mapper(UnicodeItem, unicode_item_table)
#this table specifies the many-many relationship between books and
tags
book_tags_table = Table('book_tags',
Column('book_id', Integer, ForeignKey(book.book_id)),
Column('unicode_item_id', Integer,
ForeignKey(unicode_item.item_id)),
)

book_table = Table('book',
Column('book_id', Integer, primary_key=True),
Column('title', Unicode(255)),
Column('description', Unicode(255)),
)
class Book(object):
pass
mapper(Book, book_table, properties = {
'tags' : relation(UnicodeItem, secondary=book_tags_table,
lazy=False)
}
)

###
# main
###

#create database and session
global_connect(sqlite:///)
default_metadata.create_all()
session = create_session()

#insert some books/tags
book = Book()
book.name = Python Cookbook
book.description = It's delicious!
#book.tags = [upython, uprogramming]
book.tags = [UnicodeItem(python), UnicodeItem(programming)]
session.save(book)
session.flush()

#print out book details
print \
   name: %s
description: %s
   tags: %s % (book.name, book.description, book.tags)


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: list of strings/unicode strings

2007-02-07 Thread Sébastien LELONG
 Is there anyway I can specify the list of tags like this, instead?

 book.tags = [upython, uprogramming]

Well you could use a PickleType column in your book table... Of course, you'll 
loose functionnalities you could have using a real Tag object. The problem is 
how you consider a tag in your model...

See attachment for the pickletype col.

Hope it helps.

Cheers, 

Seb
-- 
Sébastien LELONG
sebastien.lelong[at]sirloon.net

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



with_pickletype.py
Description: application/python


[sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread HD Mail

Hi Iain,

 I'm working on an admin interface and trying to make it generic when
 that will do, a la django, but more easily customizable. A couple of
 things I could not yet find in the SA docs, can anyone point me to the
 right place or if they know pipe up?

 - how would one ask a mapper object for its underlying table(s)?
   

This is what I use.

mapper.local_table.c

It seems to give me the columns in the same order as I define them in my 
Table object.
 - I found out that table_name._orig_cols gives me the column names and
 types, but as it's in a dict, it's not ordered

 - the repr of a table name gives the Table object, which has the columns
 listed in order. Before I do something stupid like slice up this repr
 with reg exes, is there an easy way to access the columns and their
 attributes in the order they are declared in the Table call?

 Lastly, is anyone working on this kind of stuff with pointers or code
 that I should look at? I'm sure I'm going to do some silly stuff on my
 own. ;)

   
For generic admin interfaces, I would use the autoload=True feature. 
However, this may not
give you the ordering of columns which you desire because it's totally 
up to the database server
how the order of the columns are returned when SA queries the metadata.

I got around this by mimicking what django does, that is define a inner 
Admin class on my model classes
with similar types of properties as you would find in django to control 
the layout of tables,forms,lists etc.
You don't have to use the inner class but it boils down to have some 
sort of metadata (whether it's in code,config files,xml etc) to help you 
auto generate gui stuff.

The rich metadata which SA captures is awesome for this type of stuff.

Hope that helps.

Huy

 Thanks
 Iain




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: making crud with assign_mapper

2007-02-07 Thread yi huang

 If you have the time and know how, do you know what the efficient way to
 iterate through all the class definitions in a module would be to grab
 all the classes that have a certain member?

 Ie If I add this field to an orm class

 class Page:
 admin_fields = [blahblah]

 then I want to grab that class from my controller code and read the
 admin field values. ( without having to say in the controller which ones
 have that )


I think subclassing would be more efficient , django does this by using
metaclass.

-- 
http://codeplayer.blogspot.com/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Unit testing with SA?

2007-02-07 Thread Allen Bierbaum

I have taken a quick look at this code.  But be warned I have not
actually used it yet so I have limited real experience with it...

Overall it looks very interesting.  I was expecting something much
more along the vein of DbUnit where you do something like this:

setUp():
   dataset = XmlDataset(dataset.xml)
   db.refresh(dataset)

tearDown():
   db.tearDown()

testMethod():
   # Do normal db queries here relying upon the data to be in there
   # some custom comparisons against loaded datasets are supported

You can get the idea of DbUnit by look at it's howto page:
http://dbunit.sourceforge.net/howto.html

So far the fixture code looks a little magic to me but that may be
because I do not use SessionContext or assign_mapper in my code.  I
think it would be helpful to see a full example of a simple test case
class (using unittest) that only uses the standard SA features found
in the SA tutorial.  This may help separate the SA plugin magic from
the fixture magic.

Anyway, see below for more detailed comments

On 2/6/07, Kumar McMillan [EMAIL PROTECTED] wrote:

 On 2/3/07, Allen Bierbaum [EMAIL PROTECTED] wrote:
 
  This works for creating the table structure, and that is important,
  but for me I think the actual data in the database is just was
  important if not more so. What are people using to populate the
  database with test data to use in the tests?

 if you feel adventurous, I've been working to implement SQLAlchemy in
 the fixture module :

 http://code.google.com/p/fixture/

 It's not too difficult to run insert statements at the top of your
 tests, or inject an SQL file.  But when you want to make assertions
 using that data things get tricky, which is why I created the fixture
 module.  To give you a very rough example of how this works (since the
 docs are very lacking at the moment), you have 1) DataSet objects to
 define data and 2) a Fixture object that knows how to load that data.

 In fact, special for you--!--and because I've been meaning to do so, I
 just checked in this example, to illustrate the point (if formatting
 goes funny, it is here:
 http://fixture.googlecode.com/svn/trunk/fixture/examples/db/sqlalchemy_examples.py
 ).  Before I get to it, I want to quickly address the point you made
 about having a gigabyte database but only needing a sample of it for
 testing.  I actually find the simplest way to work with fixtures is to
 use existing data.  So the module also includes a command line that
 can generate fixture code from a data source, given an object that
 knows how to select.  I.E.

 $ fixture path.to.a.table.widgets --dsn=postgres://[EMAIL PROTECTED]/db
 --query=widget_id=2

 will build fixture code (including all foreign key refs) by creating a
 select statement using the widgets table.  This command isn't
 implemented fully and may be rough around the edges but it works for
 something like above.

This command looks interesting and I need to try it on some of my
real data.  One question though, it looks like this generates python
code correct?  Have you thought about supporting the option of
generating some metadata xml file that can be loaded directly.  This
may make maintenance a little easier and the datasets less verbose.
It could also allow for hand editing of the xml datasources when that
makes sense.

 Now ... that example:


 SequencedSet Fixtures with SQLAlchemy and nose
 --

 Create your tables::

  from sqlalchemy import *
  from sqlalchemy.ext.sessioncontext import SessionContext
  from sqlalchemy.ext.assignmapper import assign_mapper

  meta = BoundMetaData(sqlite:///:memory:)
  session_context = SessionContext(
 ... lambda: create_session(bind_to=meta.engine))
 ...
  affiliates = Table('affiliates', meta,
 ... Column('id', INT, primary_key=True),
 ... Column('name', String),)
 ...
  class Affiliate(object): pass
  m = assign_mapper(session_context, Affiliate, affiliates)
  events = Table('events', meta,
 ... Column('id', INT, primary_key=True),
 ... Column('type', String),
 ... Column('affiliate_id', INT,
 ... ForeignKey('affiliates.id')),)
 ...
  class Event(object): pass
  m = assign_mapper(session_context, Event, events, properties = {
 ... 'affiliate': relation(Affiliate), })

 Note that using mappers above is not necessary.  The fixture module also
 supports interacting with mapper classes, however.

 Next you build the DataSet objects that you want to load, in this case they
 inherit from SequencedSet, an optional DataSet enhancement that simulates
 auto-incrementing IDs.  The IDs values can be overridden for any row and the
 column name is configurable, but defaults to 'id'::

Why is this needed?  If the id is already a sequence shouldn't the
standard inserts into the database handle this automatically?  How can
it be disabled?


  from fixture 

[sqlalchemy] Re: Unit testing with SA?

2007-02-07 Thread Allen Bierbaum

I am going to try to integrate this into my testing framework this
afternoon so I am sure I will have more questions after that.  In the
meantime see below...

On 2/7/07, Kumar McMillan [EMAIL PROTECTED] wrote:

 Thanks for taking a close look Allen.  Here are some answers...

 On 2/7/07, Allen Bierbaum [EMAIL PROTECTED] wrote:
  Overall it looks very interesting.  I was expecting something much
  more along the vein of DbUnit where you do something like this:
 
  setUp():
 dataset = XmlDataset(dataset.xml)
 db.refresh(dataset)
 
  tearDown():
 db.tearDown()
 
  testMethod():
 # Do normal db queries here relying upon the data to be in there
 # some custom comparisons against loaded datasets are supported

 given the first example datasets, the equivalent with fixture is:

 class TestMyCodeWithData(unittest.TestCase):
 def setUp(self):
 self.data = db.data(events_data)
 self.data.setup()

 def tearDown(self):
 self.data.teardown()

 def testSomething(self):
 joe = Affiliate.get(self.data.affiliates_data.joe.id)
 click = Event.get(self.data.events_data.joes_click.id)
 assert click.affiliate is joe
 assert click.type == self.data.events_data.joes_click.type


 And you;re right, I should add an example to this since people coming
 from DbUnit or rails, etc, will be more familiar with this approach.
 I started with the decorator example since I believe most of the time
 it is easier and faster to write small test functions over classes.
 But classes scale better and often it's cumbersome to convert test
 functions into classes when it comes to that -- hence, like the print
 problem [1], there is a good argument to always use test classes

Agreed.  This is probably the simplest example that people may want to
start with.  You could make it even simpler by using only a single
table but that prevents you from showing some of the advanced
features.

 [1] http://www.python.org/dev/peps/pep-3105/

 Having said that, this is a good idea.  I've committed
 fixture.DataTestCase, a mixin for use with unittest.TestCase
 derivatives.

I will give this a try and see how it works.

 I should also point out here that in python 2.5 you can write tests like:

 with db.data(events_data) as data:
  joe = Affiliate.get(data.affiliates_data.joe.id)
  click = Event.get(data.events_data.joes_click.id)
  assert click.affiliate is joe
  assert click.type == data.events_data.joes_click.type

I have no idea how this works. I guess that means I need to learn a
bit of python 2.5 soon. :)

Until then, it is nice to know that it can be even easier once I
understand python 2.5.

 As far as the XML approach -- I dislike this because I think fixtures
 are meant to be hand-coded and editable (in most cases).  XML is hard
 to edit and the rails approach to use YAML is good, but, python code
 is as good as YAML if you ask me.  Somone who feels storngly can
 submit a patch to me for loading fixtures in XML or YAML.

I understand your hesitation.  Maybe I could suggest that you just
think about adding some sort of loader plugin support similar to the
IDataSet interfaces in DbUnit
(http://dbunit.sourceforge.net/components.html).  This could provide a
point of extension for people in the future that may want to load XML,
YAML, or even excel files. :)

  So far the fixture code looks a little magic to me but that may be
  because I do not use SessionContext or assign_mapper in my code.  I
  think it would be helpful to see a full example of a simple test case
  class (using unittest) that only uses the standard SA features found
  in the SA tutorial.  This may help separate the SA plugin magic from
  the fixture magic.

 I admit the discovery of table objects is magical so yes I should
 come up with a better example.  Also, good point about not using
 extensions.  I just committed an update so that you can create a
 fixture purely from a session:

 db = SQLAlchemyFixture(session=sqlalchemy.create_session())

 keep in mind that if you need to init the session elsewhere, you can ...

 db = SQLAlchemyFixture()
 # anytime before db.data().setup() ...
 db.session = my_session

In my current system I have a single global session that is used for
everything.  Is there any reason you can see that I could not just
reuse this session in all the test cases or should I be creating a new
on each time?

  This command looks interesting and I need to try it on some of my
  real data.  One question though, it looks like this generates python
  code correct?  Have you thought about supporting the option of
  generating some metadata xml file that can be loaded directly.  This
  may make maintenance a little easier and the datasets less verbose.
  It could also allow for hand editing of the xml datasources when that
  makes sense.

 I think I addressed this above.  If you are talking about tons and
 tons of data, then yes I can see how python code might not make 

[sqlalchemy] Re: Unit testing with SA?

2007-02-07 Thread Kumar McMillan

  db = SQLAlchemyFixture()
  # anytime before db.data().setup() ...
  db.session = my_session

 In my current system I have a single global session that is used for
 everything.  Is there any reason you can see that I could not just
 reuse this session in all the test cases or should I be creating a new
 on each time?

Are you using postgres?  The only problem I foresee is if your test
does some work with table instances shared by the fixtures but doesn't
explicitly call rollback when there is an exception.  You will
probably even get a deadlock if that happens.  `ps aux | grep
postgres` will show if a fixture's delete statement is waiting on
another transaction.  I've tried to accomodate for this scenario so
let me know if you run into it again so I can add some tests for it.


 The other thing you lose with an SQL dump is that the output may not
 work across different database backends.  That is why I would really
 like the loading of the table to be routed back through SA so we can
 have some support for moving the testing data to whatever db's you end
 up needed.  (in my particular case this isn't really going to work
 because I need GIS support which is non portable, but it sounds like a
 nice capability to me)


agreed.  I'm not entirely convinced that XML is the way to go, but
this makes sense (and I like the plugin idea).  It would be mighty
fast with lxml.etree.iterparse().  still thinking...

 ...and points out a problem I am going to
 have using it.  In my current code I am not keeping the tables or
 mappers around.  Instead I have a database manager class that sets
 everthing up and simply holds onto the session and engine that should
 be used to query the database.  I rely upon the mapped classes to keep
 track of the table and metadata references internally.

 So... is there any way to associated a dataset with the Class type
 that is associated with the data in the dataset?

 for example maybe something like:

 class anything_I_want(DataSet):
mappedType = MyDataClass
class click:
   name=click

 or something else along these lines.  This seems like it would work
 well to tie the data back to the class type that is actually being
 mapped.  Then the anything_I_want class is really just a list of
 MyDataClass objects that need to be populated into the database.

Yes, I've made an attempt to support mapped classes but there are many
different ways to map classes so I might not have captured them all.
Please try:

class anything_i_want(DataSet):
class Meta:
storable=MyDataClass
class click:
name=click

and let me know if that doesn't work, so I can get an idea for how you
are using mapped classes.


-Kumar

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: mapping sql - python types

2007-02-07 Thread Michael Bayer

theres an ancient ticket for this which i didnt entirely disagree  
with, i just chose not to deal with it.  mostly becuase its not  
always guaranteed about what type you get back, like string could  
return str or unicode, etc.

doing the FLOAT=Float thing, if it doesnt break anything, still  
woulndt be a general solution since types can be subclassed freely  
(and are).   if you want to map from SQL types to Python, we should  
just put a __type__ attribute or similar on TypeEngine (i.e. class  
String(TypeEngine): __type__ = str)

On Feb 6, 2007, at 11:52 PM, Jonathan Ellis wrote:


 IIRC SA doesn't really have a map of this is the python type I should
 get for this sql type, and relies on the db driver to handle that.

 I need to at least approximate this mapping w/o going through the
 driver, though.  So I was just going to set up a dict for the classes
 defined in types.py.  But, it would make the dict a lot shorter if the
 CONSTANTS at the end were defined as
 FLOAT = Float
 TEXT = String
 ...

 instead of
 class FLOAT(Float):pass
 class TEXT(String):pass
 ...

 Would this break anything?

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---