Here is a skeleton to help you test your applications which use Elixir. Elixir's own test suite uses nosetests. Here is an example to use Python's standard unittest and doctests.
#!/usr/bin/env python """ A skeleton for unit tests in Elixir. """ from sqlalchemy.exceptions import IntegrityError import unittest import doctest from elixir import * class Individual(Entity): """Table 'Individual'. >>> me = Individual('Groucho') # 'name' field is converted to lowercase >>> me.name 'groucho' """ name = Field(String(20), unique=True) favorite_color = Field(String(20)) def __init__(self, name, favorite_color=None): self.name = str(name).lower() self.favorite_color = favorite_color setup_all() class TestIndividual(unittest.TestCase): """Test case description """ def setUp(self): metadata.bind = 'sqlite:///:memory:' create_all() def tearDown(self): # clear the session and rollback any open transaction session.close() # drop all tables, so that we don't leak any data from one test to the # other drop_all() def test_simpleassert(self): """test description """ einstein = Individual('einstein') session.commit() ind1 = Individual.get_by(name = 'einstein') assert ind1 == einstein def test_exception(self): me = Individual('giuseppe') me_again = Individual('giuseppe') self.assertRaises(IntegrityError, session.commit) if __name__ == '__main__': # run the docstring tests doctest.testmod() # run the other unit tests unittest.main()
