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

Proposed by Steffen Allner
Status: Merged
Approved by: Данило Шеган
Approved revision: 974
Merged at revision: 958
Proposed branch: lp:~gocept/landscape-client/py3-sysinfo
Merge into: lp:~landscape/landscape-client/trunk
Prerequisite: lp:~gocept/landscape-client/py3-fs
Diff against target: 98 lines (+21/-36)
2 files modified
landscape/sysinfo/tests/test_deployment.py (+19/-14)
py3_ready_tests (+2/-22)
To merge this branch: bzr merge lp:~gocept/landscape-client/py3-sysinfo
Reviewer Review Type Date Requested Status
Michael Howitz (community) Approve
Данило Шеган (community) Approve
🤖 Landscape Builder test results Approve
Review via email: mp+319803@code.launchpad.net

Commit message

Update landscape.sysinfo tests to work with python 2.x and 3.x.

Description of the change

We are on the journey to Python 2/3 compatibility.

This MP considers landscape.sysinfo module, where only a few tests had to be ported. First, mocking builtins works different now. Second, SystemExit lost his .message attribute, .code can be used instead.

To post a comment you must log in.
971. By Steffen Allner

In Python 3 we have to give the full python path for mocking builtins, also generalize assertions and move them outside the mocking with statement to make it clearer what is mocked.

972. By Steffen Allner

SystemExit lost its .message but kept its .code attribute.

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: 972
Branch: lp:~gocept/landscape-client/py3-sysinfo
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3620/

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

Looks good, I'd just start adding tests to py3_ready_test as we go along.

review: Approve
973. By Steffen Allner

Backmerge from trunk

974. By Steffen Allner

Increase tests executed with Python 3.

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

I am happy to do that her too. We have no the complete landscape.lib covered \O/.

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: 974
Branch: lp:~gocept/landscape-client/py3-sysinfo
Jenkins: https://ci.lscape.net/job/latch-test-xenial/3624/

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

Please make sure Daniel (or someone else) from Gocept does a review too so we can get this landed.

review: Approve
Revision history for this message
Michael Howitz (mh-gocept) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/sysinfo/tests/test_deployment.py'
2--- landscape/sysinfo/tests/test_deployment.py 2017-03-13 15:15:46 +0000
3+++ landscape/sysinfo/tests/test_deployment.py 2017-03-15 08:40:47 +0000
4@@ -62,6 +62,7 @@
5 """
6 Something that's simpler and more reusable than a bunch of mocked objects.
7 """
8+
9 def __init__(self):
10 self.queued_calls = []
11 self.scheduled_calls = []
12@@ -135,6 +136,7 @@
13 # thus firing the callback and writing sysinfo out to stdout.
14 sysinfo = SysInfoPluginRegistry()
15 original_sysinfo_run = sysinfo.run
16+
17 def wrapped_sysinfo_run(*args, **kwargs):
18 original_sysinfo_run(*args, **kwargs)
19 return deferred
20@@ -252,23 +254,26 @@
21
22 def test_setup_logging_logs_to_var_log_if_run_as_root(self):
23 with mock.patch.object(os, "getuid", return_value=0) as mock_getuid, \
24- mock.patch.object(
25- os.path, "isdir", return_value=False) as mock_isdir, \
26- mock.patch.object(os, "mkdir") as mock_mkdir, \
27- mock.patch("__builtin__.open") as mock_open:
28+ mock.patch.object(
29+ os.path, "isdir", return_value=False) as mock_isdir, \
30+ mock.patch.object(os, "mkdir") as mock_mkdir, \
31+ mock.patch("logging.open") as mock_open:
32 logger = getLogger("landscape-sysinfo")
33 self.assertEqual(logger.handlers, [])
34
35 setup_logging()
36- mock_getuid.assert_called_with()
37- mock_isdir.assert_called_with("/var/log/landscape")
38- mock_mkdir.assert_called_with("/var/log/landscape")
39- mock_open.assert_called_with("/var/log/landscape/sysinfo.log", "a")
40
41- handler = logger.handlers[0]
42- self.assertTrue(isinstance(handler, RotatingFileHandler))
43- self.assertEqual(handler.baseFilename,
44- "/var/log/landscape/sysinfo.log")
45+ mock_getuid.assert_called_with()
46+ mock_isdir.assert_called_with("/var/log/landscape")
47+ mock_mkdir.assert_called_with("/var/log/landscape")
48+ self.assertEqual(
49+ mock_open.call_args_list[0][0],
50+ ("/var/log/landscape/sysinfo.log", "a")
51+ )
52+ handler = logger.handlers[0]
53+ self.assertTrue(isinstance(handler, RotatingFileHandler))
54+ self.assertEqual(handler.baseFilename,
55+ "/var/log/landscape/sysinfo.log")
56
57 def test_create_log_dir(self):
58 log_dir = self.makeFile()
59@@ -287,8 +292,8 @@
60 io_error = IOError("Read-only filesystem.")
61 with mock.patch(
62 "landscape.sysinfo.deployment.setup_logging",
63- side_effect=io_error) as setup_logging_mock:
64+ side_effect=io_error):
65 error = self.assertRaises(
66 SystemExit, run, ["--sysinfo-plugins", "TestPlugin"])
67 self.assertEqual(
68- error.message, "Unable to setup logging. Read-only filesystem.")
69+ error.code, "Unable to setup logging. Read-only filesystem.")
70
71=== modified file 'py3_ready_tests'
72--- py3_ready_tests 2017-03-13 12:37:19 +0000
73+++ py3_ready_tests 2017-03-15 08:40:47 +0000
74@@ -1,22 +1,2 @@
75-landscape/lib/tests/test_scriptcontent.py
76-landscape/lib/tests/test_amp.py
77-landscape/lib/tests/test_gpg.py
78-landscape/lib/tests/test_sequenceranges.py
79-landscape/lib/tests/test_bootstrap.py
80-landscape/lib/tests/test_juju.py
81-landscape/lib/tests/test_sysstats.py
82-landscape/lib/tests/test_bpickle.py
83-landscape/lib/tests/test_lock.py
84-landscape/lib/tests/test_tag.py
85-landscape/lib/tests/test_lsb_release.py
86-landscape/lib/tests/test_timestamp.py
87-landscape/lib/tests/test_disk.py
88-landscape/lib/tests/test_monitor.py
89-landscape/lib/tests/test_encoding.py
90-landscape/lib/tests/test_versioning.py
91-landscape/lib/tests/test_fd.py
92-landscape/lib/tests/test_persist.py
93-landscape/lib/tests/test_vm_info.py
94-landscape/lib/tests/test_fetch.py
95-landscape/lib/tests/test_process.py
96-landscape/lib/tests/test_warning.py
97+landscape.lib.tests
98+landscape.sysinfo.tests

Subscribers

People subscribed via source and target branches

to all changes: