fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / test_oo.py
blobf676848c2bd7f43c2b682342a754b998f553fd4f
1 #!/usr/bin/env python
3 from translate.storage import oo
4 from translate.misc import wStringIO
5 import warnings
7 class TestOO:
8 def setup_method(self, method):
9 warnings.resetwarnings()
11 def teardown_method(self, method):
12 warnings.resetwarnings()
14 def ooparse(self, oosource):
15 """helper that parses oo source without requiring files"""
16 dummyfile = wStringIO.StringIO(oosource)
17 oofile = oo.oofile(dummyfile)
18 return oofile
20 def ooregen(self, oosource):
21 """helper that converts oo source to oofile object and back"""
22 return str(self.ooparse(oosource))
24 def test_simpleentry(self):
25 """checks that a simple oo entry is parsed correctly"""
26 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US Character 20050924 09:13:58'
27 oofile = self.ooparse(oosource)
28 assert len(oofile.units) == 1
29 oe = oofile.units[0]
30 assert oe.languages.keys() == ["en-US"]
31 ol = oofile.oolines[0]
32 assert ol.getkey() == ('svx', r'source\dialog\numpages.src', 'string', 'RID_SVXPAGE_NUM_OPTIONS', 'STR_BULLET', '')
33 assert ol.text == 'Character'
34 assert str(ol) == oosource
36 def test_simpleentry_quickhelptest(self):
37 """checks that a simple entry with quickhelptext is parsed correctly"""
38 oosource = r'sd source\ui\dlg\sdobjpal.src 0 imagebutton FLTWIN_SDOBJPALETTE BTN_SYMSIZE 16 en-US - Toggle Symbol Size 20051017 21:40:56'
39 oofile = self.ooparse(oosource)
40 assert len(oofile.units) == 1
41 oe = oofile.units[0]
42 assert oe.languages.keys() == ["en-US"]
43 ol = oofile.oolines[0]
44 assert ol.getkey() == ('sd', r'source\ui\dlg\sdobjpal.src', 'imagebutton', 'FLTWIN_SDOBJPALETTE', 'BTN_SYMSIZE', '')
45 assert ol.quickhelptext == 'Toggle Symbol Size'
46 assert str(ol) == oosource
48 def test_simpleentry_title(self):
49 """checks that a simple entry with title text is parsed correctly"""
50 oosource = r'dbaccess source\ui\dlg\indexdialog.src 0 querybox QUERY_SAVE_CURRENT_INDEX 0 en-US Do you want to save the changes made to the current index? Exit Index Design 20051017 21:40:56'
51 oofile = self.ooparse(oosource)
52 assert len(oofile.units) == 1
53 oe = oofile.units[0]
54 assert oe.languages.keys() == ["en-US"]
55 ol = oofile.oolines[0]
56 assert ol.getkey() == ('dbaccess', r'source\ui\dlg\indexdialog.src', 'querybox', 'QUERY_SAVE_CURRENT_INDEX', '', '')
57 assert ol.title == 'Exit Index Design'
58 assert str(ol) == oosource
60 def test_blankline(self):
61 """checks that a blank line is parsed correctly"""
62 oosource = '\n'
63 warnings.simplefilter("error")
64 oofile = self.ooparse(oosource)
65 assert len(oofile.units) == 0
67 def test_fieldlength(self):
68 """checks that we process the length field correctly"""
69 # Since the actual field is 18 characters long and the field width in this example is 16 we're not sure if they even use this!
70 oosource = r'sd source\ui\dlg\sdobjpal.src 0 imagebutton FLTWIN_SDOBJPALETTE BTN_SYMSIZE 16 en-US - Toggle Symbol Size 20051017 21:40:56'
71 oofile = self.ooparse(oosource)
72 assert len(oofile.units) == 1
73 oe = oofile.units[0]
74 assert oe.languages.keys() == ["en-US"]
75 ol = oofile.oolines[0]
76 assert int(ol.width) == 16
78 def test_escapes(self):
79 """checks that we escape properly"""
80 oosource = r'svx source\dialog\numpages.src 0 string RID_SVXPAGE_NUM_OPTIONS STR_BULLET 0 en-US size *2 \\langle x \\rangle 20050924 09:13:58'
81 oofile = self.ooregen(oosource)
82 assert r'size *2 \\langle x \\rangle' in oofile