chide 2.0.0 released! - sample objects for tests

2 views
Skip to first unread message

Chris Withers

unread,
Apr 21, 2016, 7:34:04 AM4/21/16
to sqlal...@googlegroups.com, testing-...@lists.idyll.org, simpl...@googlegroups.com
Hi All,

I've just released a new version of this tiny library for making sample objects for testing.

Here's a SQLAlchemy example:
class Parent(Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)
    child_id = Column(Integer, ForeignKey('child.id'))
    child = relationship('Child')

class Child(Base):
    __tablename__ = 'child'
    id = Column(Integer, primary_key=True)
    value = Column(Integer)
Now we can build a source of sample data:
from chide import Collection
from chide.sqlalchemy import Set

data = Collection({
    Parent: {'id': 1, 'child': Child},
    Child: {'id': 3, 'value': 42}
})
And finally, we can use it:
>>> session = Sess
 i
on()
>>> samples = Set(data)
>>> session.add(samples.get(Parent))
>>> session.commit()
>>> session.query(Parent).one()
<Parent ...>
>>> _.child
<Child ...>
The big change was realising that Collections tend to be module-level, so having them own the set of unique instances is bad. So, that's now split out into a Set object, which should be instantiated one per test! Documentation is here: http://chide.readthedocs.org/en/latest/ Development happens here: https://github.com/cjw296/chide/ cheers, Chris
Reply all
Reply to author
Forward
0 new messages