Merge lp:~dholbach/help-app/1428678 into lp:~ubuntu-touch-coreapps-drivers/help-app/trunk

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 85
Proposed branch: lp:~dholbach/help-app/1428678
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Prerequisite: lp:~dholbach/help-app/1428676
Diff against target: 154 lines (+69/-18)
5 files modified
edit-here/Makefile (+1/-1)
edit-here/run-tests (+3/-1)
edit-here/tests/test_files.py (+6/-0)
edit-here/tests/test_translations.py (+30/-0)
edit-here/translations.py (+29/-16)
To merge this branch: bzr merge lp:~dholbach/help-app/1428678
Reviewer Review Type Date Requested Status
Ubuntu Core Apps Drivers Pending
Review via email: mp+252130@code.launchpad.net
To post a comment you must log in.
lp:~dholbach/help-app/1428678 updated
82. By Daniel Holbach

make pep8 happy, export to check (internal) links in translated markdown docs

83. By Daniel Holbach

error out if test suite fails

84. By Daniel Holbach

fix opening of markdown documents, uncovered in testsuite run in pbuilder

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Some comments. Personally this also seems to fail for me. It fails in various manners on each run in test_translated_filenames_in_markdown_links.

make check
make -C edit-here check
make[1]: Entering directory '/home/nskaggs/projects/ubuntutouch/merges/help-app/edit-here'
./run-tests && echo true
test_doc_files_size_not_0 (test_files.HelpTestCase) ... ok
test_po_files_size_not_0 (test_files.HelpTestCase) ... ok
test_first_line_of_docs_is_title_line (test_translations.HelpTestCase) ... ok
test_translated_filenames_in_markdown_links (test_translations.HelpTestCase) ... FAIL

======================================================================
FAIL: test_translated_filenames_in_markdown_links (test_translations.HelpTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/nskaggs/projects/ubuntutouch/merges/help-app/edit-here/tests/test_translations.py", line 27, in test_translated_filenames_in_markdown_links
    self.assertNotIn(link_msgid, link_msgstr)
AssertionError: 'basic.md' unexpectedly found in ['basic.md']

----------------------------------------------------------------------
Ran 4 tests in 0.140s

FAILED (failures=1)
Exception ignored in: <bound method PO.__del__ of <translations.PO object at 0x7fb4bbf047b8>>
Traceback (most recent call last):
  File "/home/nskaggs/projects/ubuntutouch/merges/help-app/edit-here/translations.py", line 183, in __del__
  File "/home/nskaggs/projects/ubuntutouch/merges/help-app/edit-here/translations.py", line 179, in _remove_fake_po_file
AttributeError: 'NoneType' object has no attribute 'path'
Makefile:64: recipe for target 'check' failed
make[1]: *** [check] Error 1
make[1]: Leaving directory '/home/nskaggs/projects/ubuntutouch/merges/help-app/edit-here'
Makefile:11: recipe for target 'check' failed
make: *** [check] Error 2

Revision history for this message
Nicholas Skaggs (nskaggs) wrote :

Just noting it all works when I merge https://code.launchpad.net/~dholbach/help-app/1428677/+merge/252302 on top.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'edit-here/Makefile'
2--- edit-here/Makefile 2015-03-09 10:19:29 +0000
3+++ edit-here/Makefile 2015-03-09 10:19:29 +0000
4@@ -61,7 +61,7 @@
5 @echo ' '
6
7 check:
8- ./run-tests
9+ ./run-tests && echo true
10
11 web:
12 ./generate-translations
13
14=== modified file 'edit-here/run-tests'
15--- edit-here/run-tests 2015-03-09 10:19:29 +0000
16+++ edit-here/run-tests 2015-03-09 10:19:29 +0000
17@@ -9,4 +9,6 @@
18 test_filename = sys.argv[1]
19
20 suite = unittest.TestLoader().discover(test_directory, pattern=test_filename)
21-unittest.TextTestRunner(verbosity=2).run(suite)
22+res = unittest.TextTestRunner(verbosity=2).run(suite)
23+if res.failures or res.errors:
24+ sys.exit(1)
25
26=== modified file 'edit-here/tests/test_files.py'
27--- edit-here/tests/test_files.py 2015-03-09 10:19:29 +0000
28+++ edit-here/tests/test_files.py 2015-03-09 10:19:29 +0000
29@@ -3,6 +3,7 @@
30
31 import translations
32
33+
34 class HelpTestCase(TestCase):
35 def __init__(self, *args):
36 self.translations = translations.Translations()
37@@ -12,3 +13,8 @@
38 sizes = [os.stat(fn).st_size
39 for fn in self.translations.documents.docs]
40 self.assertNotIn(0, sizes)
41+
42+ def test_po_files_size_not_0(self):
43+ sizes = [os.stat(fn).st_size
44+ for fn in self.translations.po.langs]
45+ self.assertNotIn(0, sizes)
46
47=== added file 'edit-here/tests/test_translations.py'
48--- edit-here/tests/test_translations.py 1970-01-01 00:00:00 +0000
49+++ edit-here/tests/test_translations.py 2015-03-09 10:19:29 +0000
50@@ -0,0 +1,30 @@
51+from unittest import TestCase
52+
53+import translations
54+
55+
56+class HelpTestCase(TestCase):
57+ def __init__(self, *args):
58+ self.translations = translations.Translations()
59+ TestCase.__init__(self, *args)
60+
61+ def test_first_line_of_docs_is_title_line(self):
62+ po = self.translations.po
63+ self.assertTrue(po.gettextize(self.translations.documents))
64+ results = []
65+ for entry, first_line in po.pot_file_ob.find_title_lines():
66+ results += [entry.msgid == first_line]
67+ self.assertNotIn(False, results)
68+
69+ def test_translated_filenames_in_markdown_links(self):
70+ po = self.translations.po
71+ for po_fn in po.langs:
72+ po.load_pofile(po_fn)
73+ pofile = po.langs[po_fn]['pofile']
74+ for entry in pofile.find_in_msgid('{filename}'):
75+ (link_msgid, link_msgstr) = \
76+ pofile.find_link_in_markdown_message(entry)
77+ self.assertNotIn(link_msgid, link_msgstr)
78+ self.assertEqual(1, len(link_msgstr))
79+ self.assertIn(po.langs[po_fn]['gettext_code'],
80+ link_msgstr[0])
81
82=== modified file 'edit-here/translations.py'
83--- edit-here/translations.py 2015-03-05 09:32:33 +0000
84+++ edit-here/translations.py 2015-03-09 10:19:29 +0000
85@@ -106,29 +106,37 @@
86 results += [entry]
87 return results
88
89- def replace_title_lines(self):
90- results = {}
91+ def find_title_lines(self):
92+ results = []
93 for entry in self.find_in_msgid('Title: '):
94 if entry.msgid.startswith('Title: '):
95 where = entry.occurrences[0][0]
96- first_line = open(where).readline().strip()
97- if entry.msgid != first_line:
98- print('Title line "%s" found, but not on the first line '
99- 'of "%s".' % (entry.msgid, entry.linenum))
100- return False
101- entry.msgid = entry.msgid.replace('Title: ', '')
102- fn = entry.occurrences[0][0]
103- results[fn] = entry.msgid
104- if self.po_fn.endswith('.po'):
105- entry.msgstr = ''
106+ first_line = codecs.open(where, encoding='utf-8').readline().strip()
107+ results += [(entry, first_line)]
108+ return results
109+
110+ def replace_title_lines(self):
111+ for entry, first_line in self.find_title_lines():
112+ if entry.msgid != first_line:
113+ print('Title line "%s" found, but not on the first line '
114+ 'of "%s".' % (entry.msgid, entry.linenum))
115+ return False
116+ entry.msgid = entry.msgid.replace('Title: ', '')
117+ if self.po_fn.endswith('.po'):
118+ entry.msgstr = ''
119 self.save()
120 return True
121
122+ def find_link_in_markdown_message(self, entry):
123+ link_regex = r'\[.+?\]\(\{filename\}(.+?)\)'
124+ link_msgid = re.findall(link_regex, entry.msgid)[0]
125+ link_msgstr = list(re.findall(link_regex, entry.msgstr))
126+ return (link_msgid, link_msgstr)
127+
128 def rewrite_links(self, documents, bcp47):
129- link_regex = r'\[.+?\]\(\{filename\}(.+?)\)'
130 for entry in self.find_in_msgid('{filename}'):
131- link_msgid = re.findall(link_regex, entry.msgid)[0]
132- link_msgstr = list(re.findall(link_regex, entry.msgstr))
133+ (link_msgid, link_msgstr) = \
134+ self.find_link_in_markdown_message(entry)
135 translated_doc_fn = os.path.basename(
136 documents.translated_doc_fn(link_msgid, bcp47))
137 if not link_msgstr:
138@@ -178,10 +186,15 @@
139 if not self.langs[po_fn]['pofile']:
140 self.langs[po_fn]['pofile'] = POFile(po_fn)
141
142- def generate_pot_file(self, documents):
143+ def gettextize(self, documents):
144 if not self.po4a.gettextize(documents.docs, self.pot_fn):
145 return False
146 self.pot_file_ob.reread()
147+ return True
148+
149+ def generate_pot_file(self, documents):
150+ if not self.gettextize(documents):
151+ return False
152 if not self.pot_file_ob.replace_title_lines():
153 return False
154 for po_fn in self.langs:

Subscribers

People subscribed via source and target branches