Merge lp:~cjwatson/lazr.restful/py3-doctest-trivial into lp:lazr.restful

Proposed by Colin Watson
Status: Merged
Merged at revision: 278
Proposed branch: lp:~cjwatson/lazr.restful/py3-doctest-trivial
Merge into: lp:lazr.restful
Diff against target: 237 lines (+34/-30)
9 files modified
src/lazr/restful/docs/interface.rst (+1/-1)
src/lazr/restful/docs/webservice-declarations.rst (+1/-1)
src/lazr/restful/docs/webservice.rst (+14/-14)
src/lazr/restful/example/base/tests/entry.txt (+5/-3)
src/lazr/restful/example/base/tests/root.txt (+2/-2)
src/lazr/restful/example/base/tests/test_integration.py (+1/-1)
src/lazr/restful/example/base/tests/wadl.txt (+3/-2)
src/lazr/restful/example/multiversion/tests/introduction.txt (+3/-2)
src/lazr/restful/example/multiversion/tests/wadl.txt (+4/-4)
To merge this branch: bzr merge lp:~cjwatson/lazr.restful/py3-doctest-trivial
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+396432@code.launchpad.net

Commit message

Fix various simple doctest failures on Python 3.

Description of the change

These are mainly bytes/text issues, with a couple of other small adjustments.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/restful/docs/interface.rst'
--- src/lazr/restful/docs/interface.rst 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/docs/interface.rst 2021-01-18 12:01:41 +0000
@@ -173,7 +173,7 @@
173If the value for an overridden field is invalid, an exception will be173If the value for an overridden field is invalid, an exception will be
174raised:174raised:
175175
176 >>> copy_field(MyModel['age'], title='This should be unicode')176 >>> copy_field(MyModel['age'], title=b'This should be unicode')
177 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2177 ... # doctest: +IGNORE_EXCEPTION_MODULE_IN_PYTHON2
178 Traceback (most recent call last):178 Traceback (most recent call last):
179 ...179 ...
180180
=== modified file 'src/lazr/restful/docs/webservice-declarations.rst'
--- src/lazr/restful/docs/webservice-declarations.rst 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/docs/webservice-declarations.rst 2021-01-18 12:01:41 +0000
@@ -227,7 +227,7 @@
227 ... pass227 ... pass
228 Traceback (most recent call last):228 Traceback (most recent call last):
229 ...229 ...
230 TypeError: __init__() takes exactly 2 arguments (1 given)230 TypeError: __init__() ...
231231
232 >>> @exported_as_webservice_collection("not an interface")232 >>> @exported_as_webservice_collection("not an interface")
233 ... class InvalidEntrySchema(Interface):233 ... class InvalidEntrySchema(Interface):
234234
=== modified file 'src/lazr/restful/docs/webservice.rst'
--- src/lazr/restful/docs/webservice.rst 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/docs/webservice.rst 2021-01-18 12:01:41 +0000
@@ -1124,7 +1124,7 @@
1124 >>> wadl_request = create_web_service_request(1124 >>> wadl_request = create_web_service_request(
1125 ... '/beta/', environ=wadl_headers)1125 ... '/beta/', environ=wadl_headers)
1126 >>> wadl_resource = wadl_request.traverse(app)1126 >>> wadl_resource = wadl_request.traverse(app)
1127 >>> print(wadl_resource(wadl_request))1127 >>> print(wadl_resource(wadl_request).decode('UTF-8'))
1128 <?xml version="1.0"?>1128 <?xml version="1.0"?>
1129 <!DOCTYPE...1129 <!DOCTYPE...
1130 <wadl:application ...>1130 <wadl:application ...>
@@ -1169,7 +1169,7 @@
11691169
1170 >>> def load_json(s):1170 >>> def load_json(s):
1171 ... """Convert a JSON string to Unicode and then load it."""1171 ... """Convert a JSON string to Unicode and then load it."""
1172 ... return simplejson.loads(six.text_type(s))1172 ... return simplejson.loads(six.ensure_text(s))
11731173
1174 >>> representation = load_json(collection())1174 >>> representation = load_json(collection())
1175 >>> print(representation['resource_type_link'])1175 >>> print(representation['resource_type_link'])
@@ -1682,7 +1682,7 @@
1682 ... headers['HTTP_IF_NONE_MATCH'] = etag1682 ... headers['HTTP_IF_NONE_MATCH'] = etag
1683 ... get_request = create_web_service_request(1683 ... get_request = create_web_service_request(
1684 ... julia_url, environ=headers)1684 ... julia_url, environ=headers)
1685 ... entity_body = get_request.traverse(app)()1685 ... entity_body = six.ensure_text(get_request.traverse(app)())
1686 ... return dict(entity_body=entity_body,1686 ... return dict(entity_body=entity_body,
1687 ... response=get_request.response)1687 ... response=get_request.response)
16881688
@@ -1824,8 +1824,8 @@
1824 >>> body = simplejson.dumps(author).encode('UTF-8')1824 >>> body = simplejson.dumps(author).encode('UTF-8')
1825 >>> put_request = create_web_service_request(1825 >>> put_request = create_web_service_request(
1826 ... beard_url, body=body, environ=headers, method='PUT')1826 ... beard_url, body=body, environ=headers, method='PUT')
1827 >>> put_request.traverse(app)()1827 >>> print(six.ensure_text(put_request.traverse(app)()))
1828 '{...}'1828 {...}
18291829
1830And since no special permission is necessary to _change_ a person's1830And since no special permission is necessary to _change_ a person's
1831'favorite_recipe', it's possible to set it to a visible recipe using1831'favorite_recipe', it's possible to set it to a visible recipe using
@@ -1837,8 +1837,8 @@
1837 >>> body = simplejson.dumps(author).encode('UTF-8')1837 >>> body = simplejson.dumps(author).encode('UTF-8')
1838 >>> put_request = create_web_service_request(1838 >>> put_request = create_web_service_request(
1839 ... beard_url, body=body, environ=headers, method='PUT')1839 ... beard_url, body=body, environ=headers, method='PUT')
1840 >>> put_request.traverse(app)()1840 >>> print(six.ensure_text(put_request.traverse(app)()))
1841 '{...}'1841 {...}
18421842
1843After that PUT, James Beard's 'favorite_recipe' attribute is no longer1843After that PUT, James Beard's 'favorite_recipe' attribute is no longer
1844redacted. It's the value set by the PUT request.1844redacted. It's the value set by the PUT request.
@@ -1901,8 +1901,8 @@
1901 >>> file_resource = put_request.traverse(app)1901 >>> file_resource = put_request.traverse(app)
1902 >>> file_resource()1902 >>> file_resource()
19031903
1904 >>> C2.cover.representation1904 >>> print(six.ensure_str(C2.cover.representation))
1905 'Pretend...'1905 Pretend...
19061906
1907At this point it exists:1907At this point it exists:
19081908
@@ -1938,7 +1938,7 @@
19381938
1939 >>> field_resource = create_web_service_request(1939 >>> field_resource = create_web_service_request(
1940 ... '/beta/cookbooks/The%20Joy%20of%20Cooking/name').traverse(app)1940 ... '/beta/cookbooks/The%20Joy%20of%20Cooking/name').traverse(app)
1941 >>> print(field_resource())1941 >>> print(six.ensure_text(field_resource()))
1942 "The Joy of Cooking"1942 "The Joy of Cooking"
19431943
1944Requesting non available resources1944Requesting non available resources
@@ -2063,11 +2063,11 @@
2063 ... '/beta/cookbooks/The%20Joy%20of%20Cooking',2063 ... '/beta/cookbooks/The%20Joy%20of%20Cooking',
2064 ... body=simplejson.dumps(representation).encode('UTF-8'),2064 ... body=simplejson.dumps(representation).encode('UTF-8'),
2065 ... environ=headers, method='PATCH', hostname=host).traverse(app)2065 ... environ=headers, method='PATCH', hostname=host).traverse(app)
2066 ... return resource()2066 ... return six.ensure_text(resource())
2067 >>> path = '/beta/authors/Julia%20Child'2067 >>> path = '/beta/authors/Julia%20Child'
20682068
2069 >>> change_joy_author(u'http://api.cookbooks.dev' + path)2069 >>> print(change_joy_author(u'http://api.cookbooks.dev' + path))
2070 '{...}'2070 {...}
20712071
2072 >>> joy_resource = create_web_service_request(2072 >>> joy_resource = create_web_service_request(
2073 ... '/beta/cookbooks/The%20Joy%20of%20Cooking').traverse(app)2073 ... '/beta/cookbooks/The%20Joy%20of%20Cooking').traverse(app)
@@ -2126,7 +2126,7 @@
21262126
2127 >>> resource = create_web_service_request(2127 >>> resource = create_web_service_request(
2128 ... recipe_url, method='GET').traverse(app)2128 ... recipe_url, method='GET').traverse(app)
2129 >>> print(resource())2129 >>> print(six.ensure_text(resource()))
2130 {...}2130 {...}
21312131
2132 >>> resource = create_web_service_request(2132 >>> resource = create_web_service_request(
21332133
=== modified file 'src/lazr/restful/example/base/tests/entry.txt'
--- src/lazr/restful/example/base/tests/entry.txt 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/example/base/tests/entry.txt 2021-01-18 12:01:41 +0000
@@ -31,8 +31,8 @@
31convert it into Unicode.31convert it into Unicode.
3232
33 >>> construsions_url = quote("/cookbooks/Construsions un repas")33 >>> construsions_url = quote("/cookbooks/Construsions un repas")
34 >>> webservice.get(construsions_url).jsonBody()['cuisine']34 >>> print(webservice.get(construsions_url).jsonBody()['cuisine'])
35 u'Fran\xe7aise'35 Française
3636
37Content negotiation37Content negotiation
38===================38===================
@@ -118,7 +118,9 @@
118Getting the XHTML representation works correctly even when some of the fields118Getting the XHTML representation works correctly even when some of the fields
119have non-ascii values.119have non-ascii values.
120120
121 >>> print(webservice.get(construsions_url, 'application/xhtml+xml'))121 >>> import six
122 >>> print(six.text_type(
123 ... webservice.get(construsions_url, 'application/xhtml+xml')))
122 HTTP/1.1 200 Ok124 HTTP/1.1 200 Ok
123 ...125 ...
124 <dl ...>126 <dl ...>
125127
=== modified file 'src/lazr/restful/example/base/tests/root.txt'
--- src/lazr/restful/example/base/tests/root.txt 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/example/base/tests/root.txt 2021-01-18 12:01:41 +0000
@@ -80,8 +80,8 @@
80 ... '/', headers={'If-None-Match' : etag})80 ... '/', headers={'If-None-Match' : etag})
81 >>> conditional_response.status81 >>> conditional_response.status
82 30482 304
83 >>> conditional_response.body83 >>> print(conditional_response.body.decode('UTF-8'))
84 ''84 <BLANKLINE>
8585
86 >>> conditional_response = webservice.get(86 >>> conditional_response = webservice.get(
87 ... '/', headers={'If-None-Match' : '"a-very-old-etag"'})87 ... '/', headers={'If-None-Match' : '"a-very-old-etag"'})
8888
=== modified file 'src/lazr/restful/example/base/tests/test_integration.py'
--- src/lazr/restful/example/base/tests/test_integration.py 2020-08-21 16:16:09 +0000
+++ src/lazr/restful/example/base/tests/test_integration.py 2021-01-18 12:01:41 +0000
@@ -58,7 +58,7 @@
58 }58 }
59 suite = doctest.DocFileSuite(59 suite = doctest.DocFileSuite(
60 *doctest_files, optionflags=DOCTEST_FLAGS, globs=globs,60 *doctest_files, optionflags=DOCTEST_FLAGS, globs=globs,
61 checker=checker)61 encoding='UTF-8', checker=checker)
62 suite.layer = WSGILayer62 suite.layer = WSGILayer
63 tests.addTest(suite)63 tests.addTest(suite)
64 return tests64 return tests
6565
=== modified file 'src/lazr/restful/example/base/tests/wadl.txt'
--- src/lazr/restful/example/base/tests/wadl.txt 2020-09-02 22:25:01 +0000
+++ src/lazr/restful/example/base/tests/wadl.txt 2021-01-18 12:01:41 +0000
@@ -21,7 +21,7 @@
2121
22It's an XML document.22It's an XML document.
2323
24 >>> print(wadl)24 >>> print(wadl.decode('UTF-8'))
25 <?xml version="1.0"?>25 <?xml version="1.0"?>
26 <wadl:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"26 <wadl:application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27 xmlns="http://research.sun.com/wadl/2006/10"27 xmlns="http://research.sun.com/wadl/2006/10"
@@ -35,7 +35,8 @@
35 >>> from lxml import etree35 >>> from lxml import etree
36 >>> from lazr.restful import WADL_SCHEMA_FILE36 >>> from lazr.restful import WADL_SCHEMA_FILE
3737
38 >>> wadl_schema = etree.XMLSchema(etree.parse(open(WADL_SCHEMA_FILE)))38 >>> with open(WADL_SCHEMA_FILE) as wadl_schema_file:
39 ... wadl_schema = etree.XMLSchema(etree.parse(wadl_schema_file))
39 >>> from io import StringIO40 >>> from io import StringIO
40 >>> def validate(body):41 >>> def validate(body):
41 ... res = wadl_schema.validate(42 ... res = wadl_schema.validate(
4243
=== modified file 'src/lazr/restful/example/multiversion/tests/introduction.txt'
--- src/lazr/restful/example/multiversion/tests/introduction.txt 2020-09-07 09:54:10 +0000
+++ src/lazr/restful/example/multiversion/tests/introduction.txt 2021-01-18 12:01:41 +0000
@@ -245,8 +245,9 @@
245If an entry field is not published in a certain version, the245If an entry field is not published in a certain version, the
246corresponding field resource does not exist for that version.246corresponding field resource does not exist for that version.
247247
248 >>> print(webservice.get('/pairs/foo/deleted', api_version='beta').body)248 >>> print(webservice.get(
249 Object: <...>, name: u'deleted'249 ... '/pairs/foo/deleted', api_version='beta').body.decode('UTF-8'))
250 Object: <...>, name: ...'deleted'
250251
251 >>> print(webservice.get(252 >>> print(webservice.get(
252 ... '/pairs/foo/deleted', api_version='3.0').jsonBody())253 ... '/pairs/foo/deleted', api_version='3.0').jsonBody())
253254
=== modified file 'src/lazr/restful/example/multiversion/tests/wadl.txt'
--- src/lazr/restful/example/multiversion/tests/wadl.txt 2020-02-04 11:52:59 +0000
+++ src/lazr/restful/example/multiversion/tests/wadl.txt 2021-01-18 12:01:41 +0000
@@ -111,13 +111,13 @@
111Now if we request the WADL for 3.0 it will include a description of111Now if we request the WADL for 3.0 it will include a description of
112total_size_link.112total_size_link.
113113
114 >>> webservice.get('/', media_type='application/vnd.sun.wadl+xml',114 >>> print(webservice.get('/', media_type='application/vnd.sun.wadl+xml',
115 ... api_version='3.0').body115 ... api_version='3.0').body.decode('UTF-8'))
116 '...<wadl:param style="plain" name="total_size_link"...'116 <?xml version="1.0"?>...<wadl:param style="plain" name="total_size_link"...
117117
118If we request an earlier version, total_size_link is not described.118If we request an earlier version, total_size_link is not described.
119119
120 >>> wadl = webservice.get('/', media_type='application/vnd.sun.wadl+xml',120 >>> wadl = webservice.get('/', media_type='application/vnd.sun.wadl+xml',
121 ... api_version='2.0').body121 ... api_version='2.0').body.decode('UTF-8')
122 >>> 'total_size_link' in wadl122 >>> 'total_size_link' in wadl
123 False123 False

Subscribers

People subscribed via source and target branches