Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(21)

Side by Side Diff: translate/storage/test_po.py

Issue 101: Add setcontext method in PO storage classes SVN Base: https://translate.svn.sourceforge.net/svnroot/translate/src/trunk/
Patch Set: Created 1 year, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 3
4 from translate.storage import po 4 from translate.storage import po
5 from translate.storage import pypo 5 from translate.storage import pypo
6 from translate.storage import test_base 6 from translate.storage import test_base
7 from translate.misc import wStringIO 7 from translate.misc import wStringIO
8 from translate.misc.multistring import multistring 8 from translate.misc.multistring import multistring
9 from py.test import raises 9 from py.test import raises
10 10
11 def test_roundtrip_quoting(): 11 def test_roundtrip_quoting():
12 specials = ['Fish & chips', 'five < six', 'six > five', 12 specials = ['Fish & chips', 'five < six', 'six > five',
13 'Use &nbsp;', 'Use &amp;nbsp;' 13 'Use &nbsp;', 'Use &amp;nbsp;'
14 'A "solution"', "skop 'n bal", '"""', "'''", 14 'A "solution"', "skop 'n bal", '"""', "'''",
15 '\n', '\t', '\r', 15 '\n', '\t', '\r',
16 '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\'] 16 '\\n', '\\t', '\\r', '\\"', '\r\n', '\\r\\n', '\\']
17 for special in specials: 17 for special in specials:
18 quoted_special = pypo.quoteforpo(special) 18 quoted_special = pypo.quoteforpo(special)
19 unquoted_special = pypo.unquotefrompo(quoted_special) 19 unquoted_special = pypo.unquotefrompo(quoted_special)
20 print "special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_speci al, unquoted_special) 20 print "special: %r\nquoted: %r\nunquoted: %r\n" % (special, quoted_speci al, unquoted_special)
21 assert special == unquoted_special 21 assert special == unquoted_special
22 22
23 class TestPOUnit(test_base.TestTranslationUnit): 23 class TestPOUnit(test_base.TestTranslationUnit):
24 UnitClass = po.pounit 24 UnitClass = po.pounit
25 def test_istranslatable(self): 25 def test_istranslatable(self):
26 """Tests for the correct behaviour of istranslatable().""" 26 """Tests for the correct behaviour of istranslatable()."""
27 unit = self.UnitClass("Message") 27 unit = self.UnitClass("Message")
28 assert unit.istranslatable() 28 assert unit.istranslatable()
29 29
30 unit.source = "" 30 unit.source = ""
31 assert not unit.istranslatable() 31 assert not unit.istranslatable()
32 # simulate a header 32 # simulate a header
33 unit.target = "PO-Revision-Date: 2006-02-09 23:33+0200\n" 33 unit.target = "PO-Revision-Date: 2006-02-09 23:33+0200\n"
34 assert unit.isheader() 34 assert unit.isheader()
35 assert not unit.istranslatable() 35 assert not unit.istranslatable()
36 36
37 unit.source = "Message" 37 unit.source = "Message"
38 unit.target = "Boodskap" 38 unit.target = "Boodskap"
39 unit.makeobsolete() 39 unit.makeobsolete()
40 assert not unit.istranslatable() 40 assert not unit.istranslatable()
41 41
42 def test_adding_empty_note(self): 42 def test_adding_empty_note(self):
43 unit = self.UnitClass("bla") 43 unit = self.UnitClass("bla")
44 assert not '#' in str(unit) 44 assert not '#' in str(unit)
45 for empty_string in [ "", " ", "\t", "\n" ]: 45 for empty_string in [ "", " ", "\t", "\n" ]:
46 unit.addnote(empty_string) 46 unit.addnote(empty_string)
47 assert not '#' in str(unit) 47 assert not '#' in str(unit)
48 48
49 def test_markreview(self): 49 def test_markreview(self):
50 """Tests if we can mark the unit to need review.""" 50 """Tests if we can mark the unit to need review."""
51 unit = self.unit 51 unit = self.unit
52 # We have to explicitly set the target to nothing, otherwise xliff 52 # We have to explicitly set the target to nothing, otherwise xliff
53 # tests will fail. 53 # tests will fail.
54 # Can we make it default behavior for the UnitClass? 54 # Can we make it default behavior for the UnitClass?
55 unit.target = "" 55 unit.target = ""
56 56
57 unit.addnote("Test note 1", origin="translator") 57 unit.addnote("Test note 1", origin="translator")
58 unit.addnote("Test note 2", origin="translator") 58 unit.addnote("Test note 2", origin="translator")
59 original_notes = unit.getnotes(origin="translator") 59 original_notes = unit.getnotes(origin="translator")
60 60
61 assert not unit.isreview() 61 assert not unit.isreview()
62 unit.markreviewneeded() 62 unit.markreviewneeded()
63 print unit.getnotes() 63 print unit.getnotes()
64 assert unit.isreview() 64 assert unit.isreview()
65 unit.markreviewneeded(False) 65 unit.markreviewneeded(False)
66 assert not unit.isreview() 66 assert not unit.isreview()
67 assert unit.getnotes(origin="translator") == original_notes 67 assert unit.getnotes(origin="translator") == original_notes
68 unit.markreviewneeded(explanation="Double check spelling.") 68 unit.markreviewneeded(explanation="Double check spelling.")
69 assert unit.isreview() 69 assert unit.isreview()
70 notes = unit.getnotes(origin="translator") 70 notes = unit.getnotes(origin="translator")
71 assert notes.count("Double check spelling.") == 1 71 assert notes.count("Double check spelling.") == 1
72 72
73 def test_errors(self): 73 def test_errors(self):
74 """Tests that we can add and retrieve error messages for a unit.""" 74 """Tests that we can add and retrieve error messages for a unit."""
75 unit = self.unit 75 unit = self.unit
76 76
77 assert len(unit.geterrors()) == 0 77 assert len(unit.geterrors()) == 0
78 unit.adderror(errorname='test1', errortext='Test error message 1.') 78 unit.adderror(errorname='test1', errortext='Test error message 1.')
79 unit.adderror(errorname='test2', errortext='Test error message 2.') 79 unit.adderror(errorname='test2', errortext='Test error message 2.')
80 unit.adderror(errorname='test3', errortext='Test error message 3.') 80 unit.adderror(errorname='test3', errortext='Test error message 3.')
81 assert len(unit.geterrors()) == 3 81 assert len(unit.geterrors()) == 3
82 assert unit.geterrors()['test1'] == 'Test error message 1.' 82 assert unit.geterrors()['test1'] == 'Test error message 1.'
83 assert unit.geterrors()['test2'] == 'Test error message 2.' 83 assert unit.geterrors()['test2'] == 'Test error message 2.'
84 assert unit.geterrors()['test3'] == 'Test error message 3.' 84 assert unit.geterrors()['test3'] == 'Test error message 3.'
85 unit.adderror(errorname='test1', errortext='New error 1.') 85 unit.adderror(errorname='test1', errortext='New error 1.')
86 assert unit.geterrors()['test1'] == 'New error 1.' 86 assert unit.geterrors()['test1'] == 'New error 1.'
87 87
88 def test_no_plural_settarget(self): 88 def test_no_plural_settarget(self):
89 """tests that target handling of file with no plural is correct""" 89 """tests that target handling of file with no plural is correct"""
90 # plain text, no plural test 90 # plain text, no plural test
91 unit = self.UnitClass("Tree") 91 unit = self.UnitClass("Tree")
92 unit.target = "ki" 92 unit.target = "ki"
93 assert unit.hasplural() == False 93 assert unit.hasplural() == False
94 94
95 # plural test with multistring 95 # plural test with multistring
96 unit.setsource(["Tree", "Trees"]) 96 unit.setsource(["Tree", "Trees"])
97 assert unit.source.strings == ["Tree", "Trees"] 97 assert unit.source.strings == ["Tree", "Trees"]
98 assert unit.hasplural() 98 assert unit.hasplural()
99 unit.target = multistring(["ki", "ni ki"]) 99 unit.target = multistring(["ki", "ni ki"])
100 assert unit.target.strings == ["ki", "ni ki"] 100 assert unit.target.strings == ["ki", "ni ki"]
101 101
102 # test of msgid with no plural and msgstr with plural 102 # test of msgid with no plural and msgstr with plural
103 unit = self.UnitClass("Tree") 103 unit = self.UnitClass("Tree")
104 assert raises(ValueError, unit.settarget, [u"ki", u"ni ki"]) 104 assert raises(ValueError, unit.settarget, [u"ki", u"ni ki"])
105 assert unit.hasplural() == False 105 assert unit.hasplural() == False
106 106
107 def test_wrapping_bug(self): 107 def test_wrapping_bug(self):
108 """This tests for a wrapping bug that existed at some stage.""" 108 """This tests for a wrapping bug that existed at some stage."""
109 unit = self.UnitClass("") 109 unit = self.UnitClass("")
110 message = 'Projeke ya Pootle ka boyona e ho <a href="http://translate.so urceforge.net/">translate.sourceforge.net</a> moo o ka fumanang dintlha ka sourc e code, di mailing list jwalo jwalo.' 110 message = 'Projeke ya Pootle ka boyona e ho <a href="http://translate.so urceforge.net/">translate.sourceforge.net</a> moo o ka fumanang dintlha ka sourc e code, di mailing list jwalo jwalo.'
111 unit.target = message 111 unit.target = message
112 print unit.target 112 print unit.target
113 assert unit.target == message 113 assert unit.target == message
114 114
115 def test_extract_msgidcomments_from_text(self): 115 def test_extract_msgidcomments_from_text(self):
116 """Test that KDE style comments are extracted correctly.""" 116 """Test that KDE style comments are extracted correctly."""
117 unit = self.UnitClass("test source") 117 unit = self.UnitClass("test source")
118 118
119 kdetext = "_: Simple comment\nsimple text" 119 kdetext = "_: Simple comment\nsimple text"
120 assert unit._extract_msgidcomments(kdetext) == "Simple comment" 120 assert unit._extract_msgidcomments(kdetext) == "Simple comment"
121 121
122 def test_isheader(self): 122 def test_isheader(self):
123 """checks that we deal correctly with headers.""" 123 """checks that we deal correctly with headers."""
124 unit = self.UnitClass() 124 unit = self.UnitClass()
125 unit.target = "PO-Revision-Date: 2006-02-09 23:33+0200\n" 125 unit.target = "PO-Revision-Date: 2006-02-09 23:33+0200\n"
126 assert unit.isheader() 126 assert unit.isheader()
127 unit.source = "Some English string" 127 unit.source = "Some English string"
128 assert not unit.isheader() 128 assert not unit.isheader()
129 unit.source = u"Goeiemôre" 129 unit.source = u"Goeiemôre"

error: old chunk mismatch

OLDNEW

Powered by Google App Engine
This is Rietveld r159