Merge lp:~simpoir/landscape-client/mocker_to_mock_test_facade into lp:~landscape/landscape-client/trunk

Proposed by Simon Poirier
Status: Merged
Approved by: Simon Poirier
Approved revision: 844
Merged at revision: 861
Proposed branch: lp:~simpoir/landscape-client/mocker_to_mock_test_facade
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 120 lines (+32/-32)
1 file modified
landscape/package/tests/test_facade.py (+32/-32)
To merge this branch: bzr merge lp:~simpoir/landscape-client/mocker_to_mock_test_facade
Reviewer Review Type Date Requested Status
Bogdana Vereha (community) Approve
🤖 Landscape Builder test results Approve
Данило Шеган (community) Approve
Review via email: mp+297514@code.launchpad.net

Commit message

This branches migrates to mock l/p/t/test_facade

Description of the change

This branches migrates to mock l/p/t/test_facade

Testing instructions:

run unit tests

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: make check
Result: Success
Revno: 843
Branch: lp:~simpoir/landscape-client/mocker_to_mock_test_facade
Jenkins: https://ci.lscape.net/job/latch-test/5041/

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

You should make use of the wraps=os.dup2 in mock.patch("os.dup2") call. I've got a few other inline suggestions regarding naming.

review: Approve
Revision history for this message
Simon Poirier (simpoir) :
844. By Simon Poirier

address the comments of danilo

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

Command: make check
Result: Success
Revno: 844
Branch: lp:~simpoir/landscape-client/mocker_to_mock_test_facade
Jenkins: https://ci.lscape.net/job/latch-test/5052/

review: Approve (test results)
Revision history for this message
Bogdana Vereha (bogdana) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/package/tests/test_facade.py'
2--- landscape/package/tests/test_facade.py 2016-03-15 12:02:53 +0000
3+++ landscape/package/tests/test_facade.py 2016-06-15 19:03:32 +0000
4@@ -14,7 +14,7 @@
5 TransactionError, DependencyError, ChannelError, AptFacade,
6 LandscapeInstallProgress)
7
8-from landscape.tests.mocker import ANY
9+import mock
10 from landscape.tests.helpers import LandscapeTest, EnvironSaverHelper
11 from landscape.package.tests.helpers import (
12 HASH1, HASH2, HASH3, PKGNAME1, PKGNAME2, PKGNAME3,
13@@ -1178,13 +1178,11 @@
14 to be printed to stderr.
15 """
16 progress = LandscapeInstallProgress()
17- sys_except_hook = self.mocker.replace("sys.__excepthook__")
18- error = SystemError("error")
19- tb = object()
20- sys_except_hook(SystemError, error, tb)
21- self.mocker.result(None)
22- self.mocker.replay()
23- progress._prevent_dpkg_apport_error(SystemError, error, tb)
24+ with mock.patch("sys.__excepthook__") as sys_except_hook:
25+ error = SystemError("error")
26+ tb = object()
27+ progress._prevent_dpkg_apport_error(SystemError, error, tb)
28+ sys_except_hook.assert_called_once_with(SystemError, error, tb)
29
30 def test_prevent_dpkg_apport_error_non_system_error(self):
31 """
32@@ -1679,20 +1677,20 @@
33 old_stdout = os.dup(1)
34 old_stderr = os.dup(2)
35 fd, outfile = tempfile.mkstemp()
36- mkstemp = self.mocker.replace("tempfile.mkstemp")
37- mkstemp()
38- self.mocker.result((fd, outfile))
39- dup = self.mocker.replace("os.dup")
40- dup(1)
41- self.mocker.result(old_stdout)
42- dup(2)
43- self.mocker.result(old_stderr)
44- dup2 = self.mocker.replace("os.dup2")
45- dup2(old_stdout, 1)
46- self.mocker.passthrough()
47- dup2(old_stderr, 2)
48- self.mocker.passthrough()
49- return outfile
50+ mkstemp_patcher = mock.patch("tempfile.mkstemp")
51+ mock_mkstemp = mkstemp_patcher.start()
52+ self.addCleanup(mkstemp_patcher.stop)
53+ mock_mkstemp.return_value = (fd, outfile)
54+
55+ dup_patcher = mock.patch("os.dup")
56+ mock_dup = dup_patcher.start()
57+ self.addCleanup(dup_patcher.stop)
58+ mock_dup.side_effect = lambda fd: {1: old_stdout, 2: old_stderr}[fd]
59+
60+ dup2_patcher = mock.patch("os.dup2", wraps=os.dup2)
61+ mock_dup2 = dup2_patcher.start()
62+ self.addCleanup(dup2_patcher.stop)
63+ return outfile, mock_dup2
64
65 def test_perform_changes_dpkg_output_reset(self):
66 """
67@@ -1705,12 +1703,13 @@
68 [foo] = self.facade.get_packages_by_name("foo")
69 self.facade.mark_install(foo)
70
71- outfile = self._mock_output_restore()
72- self.mocker.replay()
73+ outfile, mock_dup2 = self._mock_output_restore()
74 self.patch_cache_commit()
75 self.facade.perform_changes()
76 # Make sure we don't leave the tempfile behind.
77 self.assertFalse(os.path.exists(outfile))
78+ mock_dup2.assert_any_call(mock.ANY, 1)
79+ mock_dup2.assert_any_call(mock.ANY, 2)
80
81 def test_perform_changes_dpkg_output_reset_error(self):
82 """
83@@ -1724,8 +1723,7 @@
84 [foo] = self.facade.get_packages_by_name("foo")
85 self.facade.mark_install(foo)
86
87- outfile = self._mock_output_restore()
88- self.mocker.replay()
89+ outfile, mock_dup2 = self._mock_output_restore()
90
91 def commit(fetch_progress, install_progress):
92 raise SystemError("Error")
93@@ -1734,6 +1732,8 @@
94 self.assertRaises(TransactionError, self.facade.perform_changes)
95 # Make sure we don't leave the tempfile behind.
96 self.assertFalse(os.path.exists(outfile))
97+ mock_dup2.assert_any_call(mock.ANY, 1)
98+ mock_dup2.assert_any_call(mock.ANY, 2)
99
100 def test_reset_marks(self):
101 """
102@@ -2154,12 +2154,12 @@
103
104 [foo] = self.facade.get_packages_by_name("foo")
105 self.facade.mark_remove(foo)
106- cache = self.mocker.replace(self.facade._cache)
107- cache.commit(fetch_progress=ANY, install_progress=ANY)
108- self.mocker.throw(SystemError("Something went wrong."))
109- self.mocker.replay()
110- exception = self.assertRaises(TransactionError,
111- self.facade.perform_changes)
112+ with mock.patch.object(self.facade._cache, "commit") as mock_commit:
113+ mock_commit.side_effect = SystemError("Something went wrong.")
114+ exception = self.assertRaises(TransactionError,
115+ self.facade.perform_changes)
116+ mock_commit.assert_called_with(
117+ fetch_progress=mock.ANY, install_progress=mock.ANY)
118 self.assertIn("Something went wrong.", exception.args[0])
119
120 def test_mark_install_transaction_error(self):

Subscribers

People subscribed via source and target branches

to all changes: