def setUp(self): """Create a new database.""" self.ctx = Context(cfg) self.ctx.create_all() self.session = self.ctx.session setup.add_enums(self.ctx) self.enum = setup.ENUM
class SchemaTestCase(TestCase): """Creates a new database before every test. This also provides some helper code. """ def setUp(self): """Create a new database.""" self.ctx = Context(cfg) self.ctx.create_all() self.session = self.ctx.session setup.add_enums(self.ctx) self.enum = setup.ENUM def add_root(self, name): """Add a root with the given name. :param name: the name of the root. """ root = Root(name=name) self.session.add(root) self.session.commit() return root
def setUp(self): """Load all sandhi rules into the database.""" s = str.split self.two_split = [ (s('kim akurvata'), 'kim akurvata'), (s('tat hita'), 'tad Dita'), (s('kanyA fcCati'), 'kanyarcCati'), (s('PalAni alaBat'), 'PalAny alaBat'), (s('yogin arjuna'), 'yoginn arjuna'), (s('narEs agacCat'), 'narEr agacCat'), ] self.three_split = [ (s('pARqavAS ca eva'), 'pARqavAS cEva'), (['tasmin', 'Pale', 'iti'], 'tasmin Pala iti'), (['te', sandhi.Exempt('Pale'), 'iti'], 'te Pale iti'), ] ctx = Context(cfg) ctx.create_all() S.add_enums(ctx) S.add_sandhi(ctx) self.sandhi = sandhi.Sandhi() self.sandhi.load(ctx)
def sa_drop_all(): """Drops tables for `sanskrit`.""" if prompt_bool('This will drop all linguistic data. Proceed?'): ctx = Context(app.config) ctx.drop_all()
def sa_seed_all(*blueprints): """Seeds tables for `sanskrit`.""" # TODO: fix this if prompt_bool('This will drop then recreate all linguistic data. Proceed?'): ctx = Context(app.config) ctx.build()
test.query ~~~~~~~~~~ Tests something. :license: MIT and BSD """ from sanskrit import Context from sanskrit import setup as S # ``as S`` avoids problems with nose from sanskrit.query import SimpleQuery from sanskrit.schema import * from . import TestCase, config as cfg ctx = Context(cfg) db_built = False class QueryTestCase(TestCase): def setUp(self): """Initialize the database if it doesn't exist.""" global db_built if not db_built: ctx.drop_all() ctx.create_all() S.run(ctx) db_built = True
def testOverride(self): """Test overriding a default option""" config = dict(DATABASE_URI=cfg.DATABASE_URI, DATA_PATH=cfg.DATA_PATH, MONIER_XML_PATH='foo') ctx = Context(config) self.assertEqual(ctx.config['MONIER_XML_PATH'], 'foo')
def testDict(self): """Test creating from a :class:`dict`.""" config = dict(DATABASE_URI=cfg.DATABASE_URI, DATA_PATH=cfg.DATA_PATH) ctx = Context(config) self.compare_all(ctx)
def testModule(self): """Test creating from a module.""" ctx = Context(cfg) self.compare_all(ctx)
def testFile(self): """Test creating from a filename.""" path = os.path.join(os.path.dirname(__file__), 'config.py') ctx = Context(path) self.compare_all(ctx)