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
=== modified file 'edit-here/Makefile'
--- edit-here/Makefile 2015-03-09 10:19:29 +0000
+++ edit-here/Makefile 2015-03-09 10:19:29 +0000
@@ -61,7 +61,7 @@
61 @echo ' '61 @echo ' '
6262
63check:63check:
64 ./run-tests64 ./run-tests && echo true
6565
66web:66web:
67 ./generate-translations67 ./generate-translations
6868
=== modified file 'edit-here/run-tests'
--- edit-here/run-tests 2015-03-09 10:19:29 +0000
+++ edit-here/run-tests 2015-03-09 10:19:29 +0000
@@ -9,4 +9,6 @@
9 test_filename = sys.argv[1]9 test_filename = sys.argv[1]
1010
11suite = unittest.TestLoader().discover(test_directory, pattern=test_filename)11suite = unittest.TestLoader().discover(test_directory, pattern=test_filename)
12unittest.TextTestRunner(verbosity=2).run(suite)12res = unittest.TextTestRunner(verbosity=2).run(suite)
13if res.failures or res.errors:
14 sys.exit(1)
1315
=== modified file 'edit-here/tests/test_files.py'
--- edit-here/tests/test_files.py 2015-03-09 10:19:29 +0000
+++ edit-here/tests/test_files.py 2015-03-09 10:19:29 +0000
@@ -3,6 +3,7 @@
33
4import translations4import translations
55
6
6class HelpTestCase(TestCase):7class HelpTestCase(TestCase):
7 def __init__(self, *args):8 def __init__(self, *args):
8 self.translations = translations.Translations()9 self.translations = translations.Translations()
@@ -12,3 +13,8 @@
12 sizes = [os.stat(fn).st_size13 sizes = [os.stat(fn).st_size
13 for fn in self.translations.documents.docs]14 for fn in self.translations.documents.docs]
14 self.assertNotIn(0, sizes)15 self.assertNotIn(0, sizes)
16
17 def test_po_files_size_not_0(self):
18 sizes = [os.stat(fn).st_size
19 for fn in self.translations.po.langs]
20 self.assertNotIn(0, sizes)
1521
=== added file 'edit-here/tests/test_translations.py'
--- edit-here/tests/test_translations.py 1970-01-01 00:00:00 +0000
+++ edit-here/tests/test_translations.py 2015-03-09 10:19:29 +0000
@@ -0,0 +1,30 @@
1from unittest import TestCase
2
3import translations
4
5
6class HelpTestCase(TestCase):
7 def __init__(self, *args):
8 self.translations = translations.Translations()
9 TestCase.__init__(self, *args)
10
11 def test_first_line_of_docs_is_title_line(self):
12 po = self.translations.po
13 self.assertTrue(po.gettextize(self.translations.documents))
14 results = []
15 for entry, first_line in po.pot_file_ob.find_title_lines():
16 results += [entry.msgid == first_line]
17 self.assertNotIn(False, results)
18
19 def test_translated_filenames_in_markdown_links(self):
20 po = self.translations.po
21 for po_fn in po.langs:
22 po.load_pofile(po_fn)
23 pofile = po.langs[po_fn]['pofile']
24 for entry in pofile.find_in_msgid('{filename}'):
25 (link_msgid, link_msgstr) = \
26 pofile.find_link_in_markdown_message(entry)
27 self.assertNotIn(link_msgid, link_msgstr)
28 self.assertEqual(1, len(link_msgstr))
29 self.assertIn(po.langs[po_fn]['gettext_code'],
30 link_msgstr[0])
031
=== modified file 'edit-here/translations.py'
--- edit-here/translations.py 2015-03-05 09:32:33 +0000
+++ edit-here/translations.py 2015-03-09 10:19:29 +0000
@@ -106,29 +106,37 @@
106 results += [entry]106 results += [entry]
107 return results107 return results
108108
109 def replace_title_lines(self):109 def find_title_lines(self):
110 results = {}110 results = []
111 for entry in self.find_in_msgid('Title: '):111 for entry in self.find_in_msgid('Title: '):
112 if entry.msgid.startswith('Title: '):112 if entry.msgid.startswith('Title: '):
113 where = entry.occurrences[0][0]113 where = entry.occurrences[0][0]
114 first_line = open(where).readline().strip()114 first_line = codecs.open(where, encoding='utf-8').readline().strip()
115 if entry.msgid != first_line:115 results += [(entry, first_line)]
116 print('Title line "%s" found, but not on the first line '116 return results
117 'of "%s".' % (entry.msgid, entry.linenum))117
118 return False118 def replace_title_lines(self):
119 entry.msgid = entry.msgid.replace('Title: ', '')119 for entry, first_line in self.find_title_lines():
120 fn = entry.occurrences[0][0]120 if entry.msgid != first_line:
121 results[fn] = entry.msgid121 print('Title line "%s" found, but not on the first line '
122 if self.po_fn.endswith('.po'):122 'of "%s".' % (entry.msgid, entry.linenum))
123 entry.msgstr = ''123 return False
124 entry.msgid = entry.msgid.replace('Title: ', '')
125 if self.po_fn.endswith('.po'):
126 entry.msgstr = ''
124 self.save()127 self.save()
125 return True128 return True
126129
130 def find_link_in_markdown_message(self, entry):
131 link_regex = r'\[.+?\]\(\{filename\}(.+?)\)'
132 link_msgid = re.findall(link_regex, entry.msgid)[0]
133 link_msgstr = list(re.findall(link_regex, entry.msgstr))
134 return (link_msgid, link_msgstr)
135
127 def rewrite_links(self, documents, bcp47):136 def rewrite_links(self, documents, bcp47):
128 link_regex = r'\[.+?\]\(\{filename\}(.+?)\)'
129 for entry in self.find_in_msgid('{filename}'):137 for entry in self.find_in_msgid('{filename}'):
130 link_msgid = re.findall(link_regex, entry.msgid)[0]138 (link_msgid, link_msgstr) = \
131 link_msgstr = list(re.findall(link_regex, entry.msgstr))139 self.find_link_in_markdown_message(entry)
132 translated_doc_fn = os.path.basename(140 translated_doc_fn = os.path.basename(
133 documents.translated_doc_fn(link_msgid, bcp47))141 documents.translated_doc_fn(link_msgid, bcp47))
134 if not link_msgstr:142 if not link_msgstr:
@@ -178,10 +186,15 @@
178 if not self.langs[po_fn]['pofile']:186 if not self.langs[po_fn]['pofile']:
179 self.langs[po_fn]['pofile'] = POFile(po_fn)187 self.langs[po_fn]['pofile'] = POFile(po_fn)
180188
181 def generate_pot_file(self, documents):189 def gettextize(self, documents):
182 if not self.po4a.gettextize(documents.docs, self.pot_fn):190 if not self.po4a.gettextize(documents.docs, self.pot_fn):
183 return False191 return False
184 self.pot_file_ob.reread()192 self.pot_file_ob.reread()
193 return True
194
195 def generate_pot_file(self, documents):
196 if not self.gettextize(documents):
197 return False
185 if not self.pot_file_ob.replace_title_lines():198 if not self.pot_file_ob.replace_title_lines():
186 return False199 return False
187 for po_fn in self.langs:200 for po_fn in self.langs:

Subscribers

People subscribed via source and target branches