~bjornt/grammatista/basic-ui

« back to all changes in this revision

Viewing changes to itest.py

  • Committer: Bjorn Tillenius
  • Date: 2008-11-02 21:57:57 UTC
  • Revision ID: bjorn@tillenius.me-20081102215757-9hal1f3ldbqu9g9j
Remove a bunch of old cruft.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
# Copyright (c) 2004 Bjorn Tillenius
5
 
# All Rights Reserved.
6
 
#
7
 
# This file is part of Grammatista.
8
 
#
9
 
# Grammatista is free software; you can redistribute it and/or modify
10
 
# it under the terms of the GNU General Public License as published by
11
 
# the Free Software Foundation; either version 2 of the License, or
12
 
# (at your option) any later version.
13
 
#
14
 
# Grammatista is distributed in the hope that it will be useful,
15
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
# GNU General Public License for more details.
18
 
#
19
 
# You should have received a copy of the GNU General Public License
20
 
# along with Grammatista; if not, write to the Free Software
21
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 
#
23
 
##############################################################################
24
 
"""'Interaction' test for grammatista
25
 
 
26
 
It creates a new database, and inserts the definition for
27
 
Lithuanian. Then you get to do some exercises.
28
 
 
29
 
Usage: itests.py
30
 
"""
31
 
 
32
 
import os
33
 
import sys
34
 
 
35
 
import grammatista
36
 
 
37
 
 
38
 
def setUp():
39
 
    """Sets up everything before the tests are run."""
40
 
    # First add 'utilities' and 'lang' to sys path
41
 
    cwd = os.getcwd()
42
 
    for libdir in ('utilities', 'lang'):
43
 
        path = os.path.join(cwd, libdir)
44
 
        sys.path.insert(0, path)
45
 
 
46
 
    import lithuanian
47
 
    import createdb
48
 
                    
49
 
    # Then create the database    
50
 
    createdb.main()
51
 
 
52
 
    # And finally define Lithuanian
53
 
    lithuanian.main(args=('-t',))
54
 
 
55
 
def main(args=sys.argv[1:], stdout=sys.stdout, stderr=sys.stderr):
56
 
    setUp()
57
 
    from grammatista import Grammatista
58
 
    from grammatista.exercise import IExercise
59
 
 
60
 
    gram = Grammatista()
61
 
    lithuanian = gram.getLanguage(u'Lietuvių')
62
 
    noun = lithuanian.getWordCategory('Noun')
63
 
    while True and noun.exerciseDefinitions:
64
 
        for definition in noun.exerciseDefinitions:
65
 
            exercise = IExercise(definition)
66
 
            print '("%s" (%s): ' % (
67
 
                exercise.baseWord,
68
 
                ",".join([object.label
69
 
                          for object in exercise.inflectionForm.objects])),
70
 
            answer = sys.stdin.readline().strip()
71
 
            if exercise.checkAnswer(answer):
72
 
                print "Correct answer."
73
 
            else:
74
 
                print "Wrong answer, correct was: '%s'" % (
75
 
                    exercise.correctAnswer,)
76
 
            
77
 
       
78
 
    
79
 
    
80
 
if __name__ == "__main__":
81
 
    sys.exit(main())