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

Proposed by Daniel Holbach
Status: Superseded
Proposed branch: lp:~dholbach/help-app/1428677
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Diff against target: 267 lines (+175/-17)
7 files modified
Makefile (+4/-1)
edit-here/Makefile (+3/-0)
edit-here/run-tests (+14/-0)
edit-here/tests/test_files.py (+20/-0)
edit-here/tests/test_links.py (+75/-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/1428677
Reviewer Review Type Date Requested Status
Ubuntu Core Apps Drivers Pending
Review via email: mp+252301@code.launchpad.net

This proposal has been superseded by a proposal from 2015-03-09.

To post a comment you must log in.
lp:~dholbach/help-app/1428677 updated
87. By Daniel Holbach

remove unused code

88. By Daniel Holbach

explain what we do in terms of testing

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2015-02-26 16:26:57 +0000
+++ Makefile 2015-03-09 14:34:15 +0000
@@ -7,6 +7,9 @@
7 $(foreach fn, $(ignored), $(shell rm -r $(fn);))7 $(foreach fn, $(ignored), $(shell rm -r $(fn);))
8endif8endif
99
10check:
11 make -C edit-here check
12
10click: html13click: html
11 cd app && click build . && mv *.click ..14 cd app && click build . && mv *.click ..
1215
@@ -19,4 +22,4 @@
19update-pot:22update-pot:
20 cd edit-here && ./generate-pot23 cd edit-here && ./generate-pot
2124
22.PHONY: click html web update-pot clean25.PHONY: click html web update-pot clean check
2326
=== modified file 'edit-here/Makefile'
--- edit-here/Makefile 2015-03-06 10:32:59 +0000
+++ edit-here/Makefile 2015-03-09 14:34:15 +0000
@@ -60,6 +60,9 @@
60 @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html'60 @echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html'
61 @echo ' '61 @echo ' '
6262
63check:
64 ./run-tests
65
63web:66web:
64 ./generate-translations67 ./generate-translations
65 $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR_WEB) -s $(CONFFILE) $(PELICANOPTS) -t $(THEMEDIR_WEB)68 $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR_WEB) -s $(CONFFILE) $(PELICANOPTS) -t $(THEMEDIR_WEB)
6669
=== added file 'edit-here/run-tests'
--- edit-here/run-tests 1970-01-01 00:00:00 +0000
+++ edit-here/run-tests 2015-03-09 14:34:15 +0000
@@ -0,0 +1,14 @@
1#!/usr/bin/python3
2
3import sys
4import unittest
5
6test_directory = 'tests/'
7test_filename = 'test_*'
8if len(sys.argv) > 1:
9 test_filename = sys.argv[1]
10
11suite = unittest.TestLoader().discover(test_directory, pattern=test_filename)
12res = unittest.TextTestRunner(verbosity=2).run(suite)
13if res.failures or res.errors:
14 sys.exit(1)
015
=== added directory 'edit-here/tests'
=== added file 'edit-here/tests/test_files.py'
--- edit-here/tests/test_files.py 1970-01-01 00:00:00 +0000
+++ edit-here/tests/test_files.py 2015-03-09 14:34:15 +0000
@@ -0,0 +1,20 @@
1import os
2from unittest import TestCase
3
4import translations
5
6
7class HelpTestCase(TestCase):
8 def __init__(self, *args):
9 self.translations = translations.Translations()
10 TestCase.__init__(self, *args)
11
12 def test_doc_files_size_not_0(self):
13 sizes = [os.stat(fn).st_size
14 for fn in self.translations.documents.docs]
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)
021
=== added file 'edit-here/tests/test_links.py'
--- edit-here/tests/test_links.py 1970-01-01 00:00:00 +0000
+++ edit-here/tests/test_links.py 2015-03-09 14:34:15 +0000
@@ -0,0 +1,75 @@
1import codecs
2from html.parser import HTMLParser
3import os
4import shutil
5import subprocess
6import tempfile
7from unittest import TestCase
8import urllib.parse
9import urllib.request
10from urllib.request import FileHandler
11
12
13def require_build(build):
14 tempdir = tempfile.mkdtemp()
15 ret = subprocess.call(['make', '-es', build],
16 env={'OUTPUTDIR': tempdir})
17 return (ret, tempdir)
18
19
20def clean_tempdir(tempdir):
21 if os.path.exists(tempdir):
22 shutil.rmtree(tempdir)
23
24
25class MyHTMLParser(HTMLParser):
26 links = []
27
28 def handle_starttag(self, tag, attrs):
29 if tag == "a":
30 for name, value in attrs:
31 if name == "href":
32 url = urllib.parse.urlparse(value)
33 if not url.netloc or url.netloc == 'localhost':
34 self.links += [value]
35
36 def reload(self):
37 links = self.links
38 self.links = []
39 return links
40
41
42class HelpTestCase(TestCase):
43 def __init__(self, *args):
44 self.pwd = os.getcwd()
45 self.htmlparser = MyHTMLParser()
46 self.fh = FileHandler()
47 TestCase.__init__(self, *args)
48
49 def __del__(self):
50 os.chdir(self.pwd)
51
52 def _test_local_links(self, build):
53 (ret, tempdir) = require_build(build)
54 if ret:
55 return False
56 for dirpath, dirnames, filenames in os.walk(tempdir):
57 for fn in filenames:
58 full_fn = os.path.join(dirpath, fn)
59 os.chdir(dirpath)
60 if full_fn.endswith('.html'):
61 html = codecs.open(full_fn, encoding='utf-8').read()
62 self.htmlparser.feed(html)
63 links = self.htmlparser.reload()
64 for link in links:
65 rel_path = os.path.relpath(link, full_fn)
66 path = os.path.normpath(os.path.join(full_fn, rel_path))
67 self.assertTrue(os.path.exists(path))
68 clean_tempdir(tempdir)
69 return True
70
71 def test_local_phone_links(self):
72 return self._test_local_links('html')
73
74 def test_local_web_links(self):
75 return self._test_local_links('web')
076
=== 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 14:34:15 +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 14:34:15 +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