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

Proposed by Daniel Holbach
Status: Merged
Merged at revision: 86
Proposed branch: lp:~dholbach/help-app/1428677
Merge into: lp:~ubuntu-touch-coreapps-drivers/help-app/trunk
Prerequisite: lp:~dholbach/help-app/1428678
Diff against target: 121 lines (+87/-1)
3 files modified
HACKING (+14/-0)
edit-here/Makefile (+1/-1)
edit-here/tests/test_links.py (+72/-0)
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+252302@code.launchpad.net

This proposal supersedes 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

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

+1, Just a small comment.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HACKING'
2--- HACKING 2015-03-09 12:01:16 +0000
3+++ HACKING 2015-03-09 16:09:32 +0000
4@@ -57,6 +57,7 @@
5    ├── content
6    │   └── pages ← Here is the place to edit the content.
7    ├── po ← Translations.
8+    ├── tests ← Code for automated testing goes here.
9    └── themes ← Themes files, both templates and css/js.
10       ├── phone ← Phone/device app theme.
11       └── web ← Online build (.ubuntu.com) theme.
12@@ -131,6 +132,19 @@
13 http://www.w3.org/International/questions/qa-apache-lang-neg for publishing
14 this on the web.
15
16+Testing
17+-------
18+
19+We love automated testing! We added a couple of test cases to
20+
21+ ./edit-here/tests/
22+
23+and it would be great if you added more. We want to run these tests
24+whenever we build the package or publish the docs or whatever else. Just
25+to make sure that everything works fine. To run the test suite, run:
26+
27+ make check
28+
29
30 Code, bugs, etc.
31 ----------------
32
33=== modified file 'edit-here/Makefile'
34--- edit-here/Makefile 2015-03-09 16:09:32 +0000
35+++ edit-here/Makefile 2015-03-06 14:32:59 +0000
36@@ -61,7 +61,7 @@
37 @echo ' '
38
39 check:
40- ./run-tests && echo true
41+ ./run-tests
42
43 web:
44 ./generate-translations
45
46=== added file 'edit-here/tests/test_links.py'
47--- edit-here/tests/test_links.py 1970-01-01 00:00:00 +0000
48+++ edit-here/tests/test_links.py 2015-03-09 16:09:32 +0000
49@@ -0,0 +1,72 @@
50+import codecs
51+from html.parser import HTMLParser
52+import os
53+import shutil
54+import subprocess
55+import tempfile
56+from unittest import TestCase
57+import urllib.parse
58+
59+
60+def require_build(build):
61+ tempdir = tempfile.mkdtemp()
62+ ret = subprocess.call(['make', '-es', build],
63+ env={'OUTPUTDIR': tempdir})
64+ return (ret, tempdir)
65+
66+
67+def clean_tempdir(tempdir):
68+ if os.path.exists(tempdir):
69+ shutil.rmtree(tempdir)
70+
71+
72+class MyHTMLParser(HTMLParser):
73+ links = []
74+
75+ def handle_starttag(self, tag, attrs):
76+ if tag == "a":
77+ for name, value in attrs:
78+ if name == "href":
79+ url = urllib.parse.urlparse(value)
80+ if not url.netloc or url.netloc == 'localhost':
81+ self.links += [value]
82+
83+ def reload(self):
84+ links = self.links
85+ self.links = []
86+ return links
87+
88+
89+class HelpTestCase(TestCase):
90+ def __init__(self, *args):
91+ self.pwd = os.getcwd()
92+ self.htmlparser = MyHTMLParser()
93+ TestCase.__init__(self, *args)
94+
95+ def __del__(self):
96+ os.chdir(self.pwd)
97+
98+ def _test_local_links(self, build):
99+ (ret, tempdir) = require_build(build)
100+ if ret:
101+ return False
102+ for dirpath, dirnames, filenames in os.walk(tempdir):
103+ for fn in filenames:
104+ full_fn = os.path.join(dirpath, fn)
105+ os.chdir(dirpath)
106+ if full_fn.endswith('.html'):
107+ html = codecs.open(full_fn, encoding='utf-8').read()
108+ self.htmlparser.feed(html)
109+ links = self.htmlparser.reload()
110+ for link in links:
111+ rel_path = os.path.relpath(link, full_fn)
112+ path = os.path.normpath(os.path.join(full_fn, rel_path))
113+ self.assertTrue(os.path.exists(path))
114+ clean_tempdir(tempdir)
115+ return True
116+
117+ def test_local_phone_links(self):
118+ return self._test_local_links('html')
119+
120+ def test_local_web_links(self):
121+ return self._test_local_links('web')

Subscribers

People subscribed via source and target branches