Merge lp:~gocept/landscape-client/py3-schema into lp:~landscape/landscape-client/trunk

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 973
Merged at revision: 971
Proposed branch: lp:~gocept/landscape-client/py3-schema
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 76 lines (+10/-9)
3 files modified
landscape/schema.py (+1/-1)
landscape/tests/test_schema.py (+8/-8)
py3_ready_tests (+1/-0)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-schema
Reviewer Review Type Date Requested Status
Данило Шеган (community) Approve
Daniel Havlik (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+320772@code.launchpad.net

Commit message

Support py2/3 in landscape.schema module and adapt tests to use bytestrings as appropriate.

Description of the change

This MP ports landscape.schema to Python 3 and adapts the tests to use bytestrings, where it is needed.

Additionally, dict.keys() became an generator and, therefore we need a list to manipulate on the basis of this.

To post a comment you must log in.
Revision history for this message
🤖 Landscape Builder (landscape-builder) :
review: Abstain (executing tests)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Command: TRIAL_ARGS=-j4 make check
Result: Success
Revno: 973
Branch: lp:~gocept/landscape-client/py3-schema
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3710/

review: Approve (test results)
Revision history for this message
Данило Шеган (danilo) :
review: Needs Information
Revision history for this message
Steffen Allner (sallner) wrote :

Yes, it breaks.

Revision history for this message
Daniel Havlik (nilo) wrote :

+1

review: Approve
Revision history for this message
Данило Шеган (danilo) wrote :

Ah, right, thanks for the explanation (wasn't obvious in the diff).

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/schema.py'
2--- landscape/schema.py 2017-03-17 09:07:51 +0000
3+++ landscape/schema.py 2017-03-23 09:04:02 +0000
4@@ -221,7 +221,7 @@
5 super(Message, self).__init__(schema, optional=optional)
6
7 def coerce(self, value):
8- for k in value.keys():
9+ for k in list(value.keys()):
10 if k not in self.schema:
11 # We don't know about this field, just discard it. This
12 # is useful when a client that introduced some new field
13
14=== modified file 'landscape/tests/test_schema.py'
15--- landscape/tests/test_schema.py 2017-03-09 14:36:55 +0000
16+++ landscape/tests/test_schema.py 2017-03-23 09:04:02 +0000
17@@ -67,7 +67,7 @@
18 self.assertRaises(InvalidError, Float().coerce, "3.0")
19
20 def test_string(self):
21- self.assertEqual(Bytes().coerce("foo"), "foo")
22+ self.assertEqual(Bytes().coerce(b"foo"), b"foo")
23
24 def test_string_bad_unicode(self):
25 self.assertRaises(InvalidError, Bytes().coerce, u"foo")
26@@ -83,8 +83,8 @@
27 self.assertRaises(InvalidError, Unicode().coerce, 32)
28
29 def test_unicode_with_str(self):
30- """Unicode accept plain strings and return a unicode."""
31- self.assertEqual(Unicode().coerce("foo"), u"foo")
32+ """Unicode accept byte strings and return a unicode."""
33+ self.assertEqual(Unicode().coerce(b"foo"), u"foo")
34
35 def test_unicode_decodes(self):
36 """Unicode should decode plain strings."""
37@@ -97,7 +97,7 @@
38
39 def test_unicode_or_str_bad_encoding(self):
40 """Decoding errors should be converted to InvalidErrors."""
41- self.assertRaises(InvalidError, Unicode().coerce, "\xff")
42+ self.assertRaises(InvalidError, Unicode().coerce, b"\xff")
43
44 def test_list(self):
45 self.assertEqual(List(Int()).coerce([1]), [1])
46@@ -188,8 +188,8 @@
47 self.assertEqual(schema.coerce({"foo": 32}), {"foo": 32})
48
49 def test_dict(self):
50- self.assertEqual(Dict(Int(), Bytes()).coerce({32: "hello."}),
51- {32: "hello."})
52+ self.assertEqual(Dict(Int(), Bytes()).coerce({32: b"hello."}),
53+ {32: b"hello."})
54
55 def test_dict_coerces(self):
56 self.assertEqual(
57@@ -220,8 +220,8 @@
58 """L{Message} schemas should accept C{api} keys."""
59 schema = Message("baz", {})
60 self.assertEqual(
61- schema.coerce({"type": "baz", "api": "whatever"}),
62- {"type": "baz", "api": "whatever"})
63+ schema.coerce({"type": "baz", "api": b"whatever"}),
64+ {"type": "baz", "api": b"whatever"})
65
66 def test_message_api_None(self):
67 """L{Message} schemas should accept None for C{api}."""
68
69=== modified file 'py3_ready_tests'
70--- py3_ready_tests 2017-03-23 07:28:20 +0000
71+++ py3_ready_tests 2017-03-23 09:04:02 +0000
72@@ -3,6 +3,7 @@
73 landscape.package.tests
74
75
76+landscape.tests.test_schema
77
78
79

Subscribers

People subscribed via source and target branches

to all changes: