Merge lp:~cjwatson/lazr.restful/py3-make-entry into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 263
Proposed branch: lp:~cjwatson/lazr.restful/py3-make-entry
Merge into: lp:lazr.restful
Diff against target: 44 lines (+6/-14)
1 file modified
src/lazr/restful/tests/test_webservice.py (+6/-14)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/py3-make-entry
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+390264@code.launchpad.net

Commit message

Port lazr.restful.tests.test_webservice.make_entry to Python 3.

Description of the change

Python 3 has no exec statement. We could have switched to the "exec(code)" form, which works in both Python 2 and 3; but this is a good opportunity to switch to constructing the class dynamically without "exec", which seems more elegant.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restful/tests/test_webservice.py'
--- src/lazr/restful/tests/test_webservice.py 2020-09-02 22:26:24 +0000
+++ src/lazr/restful/tests/test_webservice.py 2020-09-03 18:39:07 +0000
@@ -13,7 +13,6 @@
13 )13 )
14from lxml import etree14from lxml import etree
15from operator import attrgetter15from operator import attrgetter
16from textwrap import dedent
17import collections16import collections
18import logging17import logging
19import random18import random
@@ -28,6 +27,7 @@
28 getUtility,27 getUtility,
29 )28 )
30from zope.interface import implementer, Interface29from zope.interface import implementer, Interface
30from zope.interface.interface import InterfaceClass
31from zope.publisher.browser import TestRequest31from zope.publisher.browser import TestRequest
32from zope.schema import Choice, Date, Datetime, TextLine32from zope.schema import Choice, Date, Datetime, TextLine
33from zope.schema.interfaces import ITextLine33from zope.schema.interfaces import ITextLine
@@ -773,19 +773,11 @@
773773
774def make_entry(name):774def make_entry(name):
775 """Make an entity with some attibutes to expose as a web service."""775 """Make an entity with some attibutes to expose as a web service."""
776 code = """776 fields = {
777 @exported_as_webservice_entry(singular_name='%(name)s')777 '%s_field' % letter: exported(TextLine(title=u'Field %s' % letter))
778 class %(name)s(Interface):778 for letter in 'rstuvwxyz'}
779 pass779 cls = InterfaceClass(name, bases=(Interface,), attrs=fields)
780 """ % locals()780 return exported_as_webservice_entry(singular_name=name)(cls)
781
782 for letter in 'rstuvwxyz':
783 code += """
784 %(letter)s_field = exported(TextLine(title=u'Field %(letter)s'))
785 """ % locals()
786
787 exec dedent(code)
788 return locals()[name]
789781
790782
791class TestWadlDeterminism(WebServiceTestCase):783class TestWadlDeterminism(WebServiceTestCase):

Subscribers

People subscribed via source and target branches