Changeset 187
- Timestamp:
- 08/16/08 21:01:22 (11 months ago)
- Location:
- trunk/shakespeare
- Files:
-
- 8 added
- 3 modified
-
controllers/stats.py (added)
-
model/dm.py (modified) (3 diffs)
-
stats.py (added)
-
templates/stats (added)
-
templates/stats/__init__.py (added)
-
templates/stats/index.html (added)
-
templates/stats/text.html (added)
-
tests/__init__.py (modified) (2 diffs)
-
tests/functional/test_stats.py (added)
-
tests/test_model.py (modified) (2 diffs)
-
tests/test_stats.py (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/shakespeare/model/dm.py
r176 r187 45 45 Column('material_id', types.Integer, ForeignKey('material.id')), 46 46 Column('word', types.String(50)), 47 Column(' occurrences', types.Integer, default=1),47 Column('freq', types.Integer), 48 48 ) 49 49 … … 67 67 @classmethod 68 68 def byName(self, name): 69 return self.query.filter_by(name=name). one()69 return self.query.filter_by(name=name).first() 70 70 71 71 def get_text(self, format=None): … … 92 92 cfgp.readfp(fileobj) 93 93 for section in cfgp.sections(): 94 try: 95 item = Material.byName(section) 96 except: 94 item = Material.byName(section) 95 if item is None: 97 96 item = Material(name=section) 97 assert item is not None 98 98 for key, val in cfgp.items(section): 99 99 setattr(item, key, val) 100 Session.flush() 100 101 101 102 class Statistic(object): -
trunk/shakespeare/tests/__init__.py
r150 r187 18 18 from routes import url_for 19 19 20 __all__ = ['url_for', 'TestController' ]20 __all__ = ['url_for', 'TestController', 'make_fixture' ] 21 21 22 22 here_dir = os.path.dirname(os.path.abspath(__file__)) … … 32 32 cmd.run([test_file]) 33 33 34 sonnet18_text = \ 35 '''Shall I compare thee to a summer's day? 36 Thou art more lovely and more temperate: 37 Rough winds do shake the darling buds of May, 38 And summer's lease hath all too short a date: 39 40 Sometime too hot the eye of heaven shines, 41 And often is his gold complexion dimm'd, 42 And every fair from fair sometime declines, 43 By chance, or nature's changing course untrimm'd: 44 45 But thy eternal summer shall not fade, 46 Nor lose possession of that fair thou ow'st, 47 Nor shall death brag thou wander'st in his shade, 48 When in eternal lines to time thou grow'st, 49 50 So long as men can breathe, or eyes can see, 51 So long lives this, and this gives life to thee. 52 ''' 53 54 # must use make_fixture rather than just create object as we need to be in 55 # current db session 56 def make_fixture(): 57 import shakespeare.model as model 58 sonnet18_name = 'test_sonnet18' 59 sonnet18 = model.Material.byName(sonnet18_name) 60 if not sonnet18: 61 sonnet18 = model.Material(name=sonnet18_name, 62 title='Sonnet 18', 63 ) 64 model.Session.flush() 65 sonnet18.content = sonnet18_text 66 return sonnet18 67 68 34 69 class TestController(object): 35 70 -
trunk/shakespeare/tests/test_model.py
r176 r187 48 48 self.text = model.Material(name=self.name, title=self.title) 49 49 self.word = 'jones' 50 self. occurrences= 550 self.freq = 5 51 51 self.cc1 = model.Statistic( 52 52 text=self.text, 53 53 word=self.word, 54 occurrences=self.occurrences54 freq=self.freq 55 55 ) 56 56 model.Session.flush() … … 69 69 out1 = model.Statistic.query.get(self.statid) 70 70 assert out1.text.name == self.name 71 assert out1. occurrences == self.occurrences71 assert out1.freq == self.freq 72 72 73 73 def test_select(self):
