Changeset 176
- Timestamp:
- 08/11/08 21:01:52 (11 months ago)
- Location:
- trunk/shakespeare
- Files:
-
- 11 modified
-
concordance.py (modified) (2 diffs)
-
concordance_test.py (modified) (1 diff)
-
config/environment.py (modified) (2 diffs)
-
gutenberg.py (modified) (1 diff)
-
gutenberg_test.py (modified) (1 diff)
-
index.py (modified) (1 diff)
-
moby.py (modified) (1 diff)
-
model/dm.py (modified) (5 diffs)
-
tests/functional/test_site.py (modified) (1 diff)
-
tests/test_model.py (modified) (5 diffs)
-
websetup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/shakespeare/concordance.py
r154 r176 11 11 import re 12 12 13 import sqlobject14 15 13 import shakespeare.index 16 14 import shakespeare.cache … … 21 19 TODO: caching?? 22 20 """ 23 sqlcc = shakespeare.model.Concordance21 # sqlcc = shakespeare.model.Concordance 24 22 sqlstat = shakespeare.model.Statistic 25 23 -
trunk/shakespeare/concordance_test.py
r150 r176 7 7 import shakespeare.concordance 8 8 9 class TestConcordancer: 9 # Disable in preparation for removal 10 class _TestConcordancer: 10 11 11 12 inText = \ -
trunk/shakespeare/config/environment.py
r148 r176 1 1 """Pylons environment configuration""" 2 2 import os 3 4 from sqlalchemy import engine_from_config 3 5 4 6 from pylons import config … … 32 34 # CONFIGURATION OPTIONS HERE (note: all config options will override 33 35 # any Pylons config options) 36 config['pylons.g'].sa_engine = engine_from_config(config, 'sqlalchemy.') -
trunk/shakespeare/gutenberg.py
r150 r176 319 319 name += '_f' 320 320 321 numExistingTexts = shakespeare.model.Material. select(322 shakespeare.model.Material.q.name==name).count()321 numExistingTexts = shakespeare.model.Material.query.filter_by( 322 name=name).count() 323 323 if numExistingTexts > 0: 324 324 if self.verbose: -
trunk/shakespeare/gutenberg_test.py
r150 r176 142 142 shakespeare.model.Material.byName('hamlet_gut_f') 143 143 assert 'Shakespeare, William' == text1.creator 144 alltexts = shakespeare.model.Material. select()144 alltexts = shakespeare.model.Material.query.all() 145 145 # do not delete because we may remove stuff that was there 146 146 # though this may undermine tests -
trunk/shakespeare/index.py
r150 r176 9 9 10 10 def __init__(self): 11 self.all = shakespeare.model.Material. select(orderBy='name')11 self.all = shakespeare.model.Material.query.order_by('name').all() 12 12 13 13 -
trunk/shakespeare/moby.py
r150 r176 124 124 url = text[1] 125 125 notes = 'Moby/Bosak Shakespeare, sourced from %s' % text[1] 126 numExistingTexts = shakespeare.model.Material. select(127 shakespeare.model.Material.q.name==name).count()126 numExistingTexts = shakespeare.model.Material.query.filter_by( 127 name=name).count() 128 128 if numExistingTexts > 0: 129 129 if self.verbose: -
trunk/shakespeare/model/dm.py
r154 r176 8 8 text is a version. 9 9 """ 10 import sqlobject 10 from pylons import config 11 from sqlalchemy import Column, MetaData, Table, types, ForeignKey 12 from sqlalchemy import orm 13 from sqlalchemy.orm import relation, backref 11 14 12 15 # make sure config is registered … … 14 17 shakespeare.conf() 15 18 16 from pylons.database import PackageHub 17 hub = PackageHub('shakespeare') 18 sqlobject.sqlhub.processConnection = hub.getConnection() 19 metadata = MetaData() 20 Session = orm.scoped_session(orm.sessionmaker( 21 autoflush=True, 22 transactional=False, 23 bind=config['pylons.g'].sa_engine 24 )) 19 25 20 26 import shakespeare … … 25 31 import annotater.model 26 32 27 # note we run this at bottom of module to auto create db tables on import 28 def createdb(): 29 Material.createTable(ifNotExists=True) 30 Concordance.createTable(ifNotExists=True) 31 Statistic.createTable(ifNotExists=True) 32 annotater.model.createdb() 33 material_table = Table('material', metadata, 34 Column('id', types.Integer, primary_key=True), 35 Column('name', types.String(255)), 36 Column('title', types.String(255)), 37 Column('creator', types.String(255)), 38 Column('url', types.String(255)), 39 Column('notes', types.Text()) 40 ) 33 41 34 def cleandb(): 35 Statistic.dropTable(ifExists=True) 36 Concordance.dropTable(ifExists=True) 37 Material.dropTable(ifExists=True) 38 annotater.model.cleandb() 42 # TODO: indices on word and occurences 43 statistic_table = Table('statistic', metadata, 44 Column('id', types.Integer, primary_key=True), 45 Column('material_id', types.Integer, ForeignKey('material.id')), 46 Column('word', types.String(50)), 47 Column('occurrences', types.Integer, default=1), 48 ) 39 49 40 def rebuilddb(): 41 cleandb() 42 createdb() 50 51 from ConfigParser import SafeConfigParser 43 52 44 53 45 54 46 from ConfigParser import SafeConfigParser 47 class Material(sqlobject.SQLObject): 55 class Material(object): 48 56 """Material related to Shakespeare (usually text of works and ancillary 49 57 matter such as introductions). … … 55 63 TODO: mutiple creators ?? 56 64 """ 65 66 # TODO: remove (just here for sqlobject bkwards compat) 67 @classmethod 68 def byName(self, name): 69 return self.query.filter_by(name=name).one() 57 70 58 name = sqlobject.StringCol(alternateID=True)59 title = sqlobject.StringCol(default=None, length=255)60 # creator rather than author to fit with dublin core61 creator = sqlobject.StringCol(default=None, length=255)62 url = sqlobject.StringCol(default=None, length=255)63 notes = sqlobject.StringCol(default=None)64 65 71 def get_text(self, format=None): 66 72 '''Get text (if any) associated with this material. … … 93 99 setattr(item, key, val) 94 100 101 class Statistic(object): 102 pass 95 103 96 class Concordance(sqlobject.SQLObject): 104 # Map each domain model class to its corresponding relational table. 105 mapper = Session.mapper 106 mapper(Material, material_table) 107 mapper(Statistic, statistic_table, properties={ 108 'text':relation(Material, backref='statistics') 109 }) 97 110 98 text = sqlobject.ForeignKey('Material')99 word = sqlobject.StringCol(length=50)100 line = sqlobject.IntCol()101 char_index = sqlobject.IntCol()102 103 word_index = sqlobject.DatabaseIndex('word')104 text_index = sqlobject.DatabaseIndex('text')105 106 class Statistic(sqlobject.SQLObject):107 108 text = sqlobject.ForeignKey('Material')109 word = sqlobject.StringCol(length=50)110 occurrences = sqlobject.IntCol(default=1)111 112 word_index = sqlobject.DatabaseIndex('word')113 text_index = sqlobject.DatabaseIndex('text')114 115 116 # auto create db tables on import117 createdb()118 -
trunk/shakespeare/tests/functional/test_site.py
r157 r176 17 17 assert 'guide to the features of the Open Shakespeare web' in res 18 18 19 def test_concordance(self):19 def _test_concordance(self): 20 20 url = url_for(controller='site', action='concordance') 21 21 res = self.app.get(url) -
trunk/shakespeare/tests/test_model.py
r154 r176 1 import sqlobject2 3 1 import shakespeare.model as model 4 2 … … 12 10 self.text = model.Material(name=self.name, 13 11 title=self.title, url=self.url) 12 model.Session.flush() 13 self.textid = self.text.id 14 model.Session.clear() 14 15 15 16 @classmethod 16 17 def teardown_class(self): 17 model.Material.delete(self.text.id) 18 text = model.Material.query.get(self.textid) 19 model.Session.delete(text) 20 model.Session.flush() 18 21 19 22 def test1(self): 20 txtid = self.text.id 21 txt2 = model.Material.get(txtid) 23 txt2 = model.Material.query.get(self.textid) 22 24 txt3 = model.Material.byName(self.name) 23 25 assert self.text.id == txt2.id … … 29 31 assert len(out) > 0 30 32 31 def test_get_text(self): 33 # TODO: set up fixtures before running this ... 34 def _test_get_text(self): 32 35 text = model.Material.byName('phoenix_and_the_turtle_gut') 33 36 out = text.get_text() … … 36 39 assert out[:26] == 'THE PHOENIX AND THE TURTLE' 37 40 38 39 class TestConcordance(object):40 41 @classmethod42 def setup_class(self):43 self.name = 'test-123'44 self.title = 'Hamlet'45 self.text = model.Material(name=self.name, title=self.title)46 word = 'jones'47 line = 2048 char_index = 50049 self.cc1 = model.Concordance(text=self.text,50 word=word,51 line=line,52 char_index=char_index)53 54 @classmethod55 def teardown_class(self):56 model.Concordance.delete(self.cc1.id)57 model.Material.delete(self.text.id)58 59 def test1(self):60 out1 = model.Concordance.get(self.cc1.id)61 assert self.text == out1.text62 41 63 42 class TestStatistic: … … 75 54 occurrences=self.occurrences 76 55 ) 56 model.Session.flush() 57 self.statid = self.cc1.id 58 model.Session.clear() 77 59 78 60 @classmethod 79 61 def teardown_class(self): 80 model.Statistic.delete(self.cc1.id) 81 model.Material.delete(self.text.id) 62 stat = model.Statistic.query.get(self.statid) 63 model.Session.delete(stat) 64 model.Session.delete(stat.text) 65 model.Session.flush() 66 model.Session.remove() 82 67 83 68 def test1(self): 84 out1 = model.Statistic. get(self.cc1.id)85 assert self.text == out1.text69 out1 = model.Statistic.query.get(self.statid) 70 assert out1.text.name == self.name 86 71 assert out1.occurrences == self.occurrences 87 72 88 73 def test_select(self): 89 tresults = model.Statistic.select( 90 sqlobject.AND( 91 model.Statistic.q.textID == self.text.id, 92 model.Statistic.q.word == self.word, 93 )) 74 tresults = model.Statistic.query.filter_by(text=self.text 75 ).filter_by(word=self.word) 94 76 num = tresults.count() 95 77 assert num == 1 -
trunk/shakespeare/websetup.py
r148 r176 13 13 conf = appconfig('config:' + filename) 14 14 load_environment(conf.global_conf, conf.local_conf) 15 from shakespeare import model 16 log.info('Creating tables') 17 model.metadata.create_all(bind=config['pylons.g'].sa_engine) 18 log.info('Creating tables: SUCCESS') 19
