1
2
3
4 from translate.storage import po
5 from translate.storage import statsdb
6
8 - def count(self, source, expectedsource, target=None, expectedtarget=None):
9 """simple helper to check the respective word counts"""
10 poelement = po.pounit(source)
11 if target is not None:
12 poelement.target = target
13 wordssource, wordstarget = statsdb.wordsinunit(poelement)
14 print 'Source (expected=%d; actual=%d): "%s"' % (expectedsource, wordssource, source)
15 assert wordssource == expectedsource
16 if target is not None:
17 print 'Target (expected=%d; actual=%d): "%s"' % (expectedtarget, wordstarget, target)
18 assert wordstarget == expectedtarget
19
21 """no content"""
22 self.count("", 0)
23
25 """simplest one word count"""
26 self.count("One", 1)
27
29 """simplest one word count"""
30 self.count("One two", 2)
31
33 """test that we break words when there is punctuation"""
34 self.count("One. Two", 2)
35 self.count("One.Two", 2)
36
45
47 """test to see that newlines divide words"""
48
49 self.count("A word.\nAnother word", 4)
50 self.count(r"A word.\\n\nAnother word", 4)
51
53 """test that we count variables as words"""
54 self.count("%PROGRAMNAME %PROGRAM% %s $file $1", 5)
55
57 """test that we can handle plural PO elements"""
58
59
60
61
62
63
64
66 """test that we correcly count old style KDE plurals"""
67 self.count("_n: Singular\\n\nPlural", 2, "Een\\n\ntwee\\n\ndrie", 3)
68
70 """counts a message id"""
71 self.count(" ", 0)
72
73
74
75
76
77
78
79
80
81
82