Download:
child 295:c54ef744f6e6
parent 293:085ce95c6d95
294:df33e25d8960
Anton Shestakov <av6@dwimlabs.net>, Mon, 18 Sep 2017 17:07:32 +0800
tests: shared XML namespace dictionary (for checking Atom and SVG)

1 файлов изменено, 13 вставок(+), 9 удалений(-) [+]
tests/test_viewer.py file | annotate | diff | comparison | revisions
--- a/tests/test_viewer.py Mon Sep 18 16:54:55 2017 +0800
+++ b/tests/test_viewer.py Mon Sep 18 17:07:32 2017 +0800
@@ -11,6 +11,12 @@
from viewer import CandolintViewer
+XMLNS = {
+ 'atom': 'http://www.w3.org/2005/Atom',
+ 'svg': 'http://www.w3.org/2000/svg'
+}
+
+
def setup_module():
with database.transaction():
project = Project.create(
@@ -127,12 +133,12 @@
assert response.code == 200
assert 'atom+xml' in response.headers['Content-Type']
root = ElementTree.fromstring(response.body)
- ns = {'atom': 'http://www.w3.org/2005/Atom'}
- title = root.find('./atom:entry/atom:title', ns)
+ assert root.tag == '{%s}%s' % (XMLNS['atom'], 'feed')
+ title = root.find('./atom:entry/atom:title', XMLNS)
assert title is not None
assert title.text.startswith('Check #')
assert title.text.endswith(' 1 error, 1 warning')
- updates = [el.text for el in root.findall('.//atom:updated', ns)]
+ updates = [el.text for el in root.findall('.//atom:updated', XMLNS)]
assert len(updates) == min(Check.select().count(), 20) + 1
assert updates[0] == updates[1] == '2016-08-20T02:38:53Z'
@@ -179,19 +185,17 @@
response = self.fetch('/example.com/alice/test-viewer/status.svg')
assert response.code == 200
root = ElementTree.fromstring(response.body)
- ns = {'svg': 'http://www.w3.org/2000/svg'}
- assert root.tag == '{http://www.w3.org/2000/svg}svg'
+ assert root.tag == '{%s}%s' % (XMLNS['svg'], 'svg')
assert root.attrib.get('height') == '20'
- text = [el.text for el in root.findall('./svg:g/svg:text', ns)]
+ text = [el.text for el in root.findall('./svg:g/svg:text', XMLNS)]
assert text[::2] == ['lint', '1 error', '1 warning']
def test_dot(self):
response = self.fetch('/example.com/alice/test-viewer/latest/dot.svg')
assert response.code == 200
root = ElementTree.fromstring(response.body)
- ns = {'svg': 'http://www.w3.org/2000/svg'}
- assert root.tag == '{http://www.w3.org/2000/svg}svg'
+ assert root.tag == '{%s}%s' % (XMLNS['svg'], 'svg')
assert root.attrib.get('height') == '12'
- circles = root.findall('./svg:circle', ns)
+ circles = root.findall('./svg:circle', XMLNS)
assert len(circles) == 1
assert circles[0].attrib.get('fill').startswith('#')