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

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 991
Merged at revision: 969
Proposed branch: lp:~gocept/landscape-client/py3-package-changer
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-package-store-reporter
Diff against target: 168 lines (+24/-23)
5 files modified
landscape/lib/tests/test_fs.py (+12/-12)
landscape/package/facade.py (+2/-1)
landscape/package/tests/test_changer.py (+7/-7)
landscape/tests/helpers.py (+2/-3)
py3_ready_tests (+1/-0)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-package-changer
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Daniel Havlik (community) Approve
Данило Шеган (community) Approve
Review via email: mp+320538@code.launchpad.net

Commit message

Update tests for landscape.package.changer and improve landscape.lib.tests.test_fs tests to cover Unicode strings too.

Description of the change

This MP considers the tests for landscape.package.changer, stressing the fact that hashes are bytes in tests and make the outcome of a function more deterministic with sorting.

Additionally, changed the self.assertFileContent to open the files explicitly in binary mode, which made me realise that tests in l.l.t.test_fs were insufficient. Now they test properly.

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: 990
Branch: lp:~gocept/landscape-client/py3-package-changer
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3691/

review: Approve (test results)
Revision history for this message
Steffen Allner (sallner) wrote :

Add some inline comments.

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

Thanks for the fixes, looks good.

Answer to your where-do-you-put-sorted question inline.

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

+1

review: Approve
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

Attempt to merge into lp:landscape-client failed due to conflicts:

text conflict in py3_ready_tests

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :

No approved revision specified.

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

Ugh, each of the branches is now going to have conflicts in py3_ready_tests: it's going to be a bit annoying, but we'll have to land them one-by-one and re-merge trunk to keep the diffs nice (i.e. add a test to py3_ready_tests in a commit that fixes it). If that sounds too annoying, you can drop changes to py3_ready_tests and do a small branch after everything else lands.

Revision history for this message
Steffen Allner (sallner) wrote :

> Ugh, each of the branches is now going to have conflicts in py3_ready_tests:
> it's going to be a bit annoying, but we'll have to land them one-by-one and
> re-merge trunk to keep the diffs nice (i.e. add a test to py3_ready_tests in a
> commit that fixes it). If that sounds too annoying, you can drop changes to
> py3_ready_tests and do a small branch after everything else lands.

Yes, I tried to separate it a bit beforehand, but it did not work. I will do the merges. Then I can also combine it for the last merge to landscape.package.test.

Will Do a separate branch next time.

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

Not at all: I like it when the test that should now pass is in the branch as well.

You would probably just have to do them all by depending on each other in a series. There's a bzr plugin that helps with that (bzr pipelines), but it's badly documented so you probably don't want to deal with that :-)

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

Please merge trunk into this branch so I can get it landed.

Revision history for this message
Steffen Allner (sallner) wrote :

> Please merge trunk into this branch so I can get it landed.

I have merged the trunk into the py3-facade branch, please merge it, then I will continue here.

991. By Steffen Allner

Backmerge from trunk.

Revision history for this message
Steffen Allner (sallner) wrote :

Conflicts resolved.

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: Fail
Revno: 991
Branch: lp:~gocept/landscape-client/py3-package-changer
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3702/

review: Needs Fixing (test results)
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: 991
Branch: lp:~gocept/landscape-client/py3-package-changer
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3704/

review: Approve (test results)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/tests/test_fs.py'
2--- landscape/lib/tests/test_fs.py 2017-03-14 14:45:53 +0000
3+++ landscape/lib/tests/test_fs.py 2017-03-22 15:14:59 +0000
4@@ -8,7 +8,7 @@
5
6 from landscape.tests.helpers import LandscapeTest
7
8-from landscape.lib.fs import append_text_file, touch_file
9+from landscape.lib.fs import append_text_file, append_binary_file, touch_file
10 from landscape.lib.fs import read_text_file, read_binary_file
11
12
13@@ -98,7 +98,7 @@
14 path = self.makeFile()
15 touch_file(path)
16 utime_mock.assert_called_once_with(path, None)
17- self.assertFileContent(path, "")
18+ self.assertFileContent(path, b"")
19
20 def test_touch_file_multiple_times(self):
21 """
22@@ -107,7 +107,7 @@
23 path = self.makeFile()
24 touch_file(path)
25 touch_file(path)
26- self.assertFileContent(path, "")
27+ self.assertFileContent(path, b"")
28
29 def test_touch_file_with_offset_seconds(self):
30 """
31@@ -127,7 +127,7 @@
32 utime_mock.assert_called_once_with(
33 path, (expected_time, expected_time))
34
35- self.assertFileContent(path, "")
36+ self.assertFileContent(path, b"")
37
38
39 class AppendFileTest(LandscapeTest):
40@@ -137,8 +137,8 @@
41 The L{append_text_file} function appends contents to an existing file.
42 """
43 existing_file = self.makeFile("foo bar")
44- append_text_file(existing_file, " baz")
45- self.assertFileContent(existing_file, "foo bar baz")
46+ append_text_file(existing_file, u" baz ☃")
47+ self.assertFileContent(existing_file, b"foo bar baz \xe2\x98\x83")
48
49 def test_append_text_no_file(self):
50 """
51@@ -146,16 +146,16 @@
52 exist already.
53 """
54 new_file = os.path.join(self.makeDir(), "new_file")
55- append_text_file(new_file, "contents")
56- self.assertFileContent(new_file, "contents")
57+ append_text_file(new_file, u"contents ☃")
58+ self.assertFileContent(new_file, b"contents \xe2\x98\x83")
59
60 def test_append_existing_binary_file(self):
61 """
62 The L{append_text_file} function appends contents to an existing file.
63 """
64 existing_file = self.makeFile("foo bar")
65- append_text_file(existing_file, " baz")
66- self.assertFileContent(existing_file, "foo bar baz")
67+ append_binary_file(existing_file, b" baz \xe2\x98\x83")
68+ self.assertFileContent(existing_file, b"foo bar baz \xe2\x98\x83")
69
70 def test_append_binary_no_file(self):
71 """
72@@ -163,5 +163,5 @@
73 exist already.
74 """
75 new_file = os.path.join(self.makeDir(), "new_file")
76- append_text_file(new_file, "contents")
77- self.assertFileContent(new_file, "contents")
78+ append_binary_file(new_file, b"contents \xe2\x98\x83")
79+ self.assertFileContent(new_file, b"contents \xe2\x98\x83")
80
81=== modified file 'landscape/package/facade.py'
82--- landscape/package/facade.py 2017-03-21 10:21:50 +0000
83+++ landscape/package/facade.py 2017-03-22 15:14:59 +0000
84@@ -186,7 +186,8 @@
85
86 def get_package_holds(self):
87 """Return the name of all the packages that are on hold."""
88- return [version.package.name for version in self.get_locked_packages()]
89+ return sorted([version.package.name
90+ for version in self.get_locked_packages()])
91
92 def _set_dpkg_selections(self, selection):
93 """Set the dpkg selection.
94
95=== modified file 'landscape/package/tests/test_changer.py'
96--- landscape/package/tests/test_changer.py 2017-03-13 15:38:09 +0000
97+++ landscape/package/tests/test_changer.py 2017-03-22 15:14:59 +0000
98@@ -196,27 +196,27 @@
99 self.assertTrue(self.store.get_next_task("changer"))
100
101 def test_install_unknown_package(self):
102- self.store.set_hash_ids({"hash": 456})
103+ self.store.set_hash_ids({b"hash": 456})
104 self.store.add_task("changer",
105 {"type": "change-packages", "install": [456],
106 "operation-id": 123})
107
108 self.changer.handle_tasks()
109
110- self.assertIn("Package data not yet synchronized with server ('hash')",
111- self.logfile.getvalue())
112+ self.assertIn("Package data not yet synchronized with server (%r)" %
113+ b"hash", self.logfile.getvalue())
114 self.assertTrue(self.store.get_next_task("changer"))
115
116 def test_remove_unknown_package(self):
117- self.store.set_hash_ids({"hash": 456})
118+ self.store.set_hash_ids({b"hash": 456})
119 self.store.add_task("changer",
120 {"type": "change-packages", "remove": [456],
121 "operation-id": 123})
122
123 self.changer.handle_tasks()
124
125- self.assertIn("Package data not yet synchronized with server ('hash')",
126- self.logfile.getvalue())
127+ self.assertIn("Package data not yet synchronized with server (%r)" %
128+ b"hash", self.logfile.getvalue())
129 self.assertTrue(self.store.get_next_task("changer"))
130
131 def test_unknown_data_timeout(self):
132@@ -972,7 +972,7 @@
133
134 def assert_result(result):
135 self.facade.reload_channels()
136- self.assertEqual(["foo", "bar"], self.facade.get_package_holds())
137+ self.assertEqual(["bar", "foo"], self.facade.get_package_holds())
138
139 result = self.changer.handle_tasks()
140 return result.addCallback(assert_result)
141
142=== modified file 'landscape/tests/helpers.py'
143--- landscape/tests/helpers.py 2017-03-10 15:19:26 +0000
144+++ landscape/tests/helpers.py 2017-03-22 15:14:59 +0000
145@@ -178,9 +178,8 @@
146 return deferred.addCallback(self.assertEqual, result)
147
148 def assertFileContent(self, filename, expected_content):
149- fd = open(filename)
150- actual_content = fd.read()
151- fd.close()
152+ with open(filename, "rb") as fd:
153+ actual_content = fd.read()
154 self.assertEqual(expected_content, actual_content)
155
156 def assertConfigEqual(self, first, second):
157
158=== modified file 'py3_ready_tests'
159--- py3_ready_tests 2017-03-22 13:09:11 +0000
160+++ py3_ready_tests 2017-03-22 15:14:59 +0000
161@@ -2,6 +2,7 @@
162 landscape.sysinfo.tests
163 landscape.package.tests.test_store
164 landscape.package.tests.test_reporter
165+landscape.package.tests.test_changer
166
167 landscape.package.tests.test_facade
168 landscape.package.tests.test_skeleton

Subscribers

People subscribed via source and target branches

to all changes: