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
=== modified file 'landscape/package/tests/test_facade.py'
--- landscape/package/tests/test_facade.py 2016-03-15 12:02:53 +0000
+++ landscape/package/tests/test_facade.py 2016-06-15 19:03:32 +0000
@@ -14,7 +14,7 @@
14 TransactionError, DependencyError, ChannelError, AptFacade,14 TransactionError, DependencyError, ChannelError, AptFacade,
15 LandscapeInstallProgress)15 LandscapeInstallProgress)
1616
17from landscape.tests.mocker import ANY17import mock
18from landscape.tests.helpers import LandscapeTest, EnvironSaverHelper18from landscape.tests.helpers import LandscapeTest, EnvironSaverHelper
19from landscape.package.tests.helpers import (19from landscape.package.tests.helpers import (
20 HASH1, HASH2, HASH3, PKGNAME1, PKGNAME2, PKGNAME3,20 HASH1, HASH2, HASH3, PKGNAME1, PKGNAME2, PKGNAME3,
@@ -1178,13 +1178,11 @@
1178 to be printed to stderr.1178 to be printed to stderr.
1179 """1179 """
1180 progress = LandscapeInstallProgress()1180 progress = LandscapeInstallProgress()
1181 sys_except_hook = self.mocker.replace("sys.__excepthook__")1181 with mock.patch("sys.__excepthook__") as sys_except_hook:
1182 error = SystemError("error")1182 error = SystemError("error")
1183 tb = object()1183 tb = object()
1184 sys_except_hook(SystemError, error, tb)1184 progress._prevent_dpkg_apport_error(SystemError, error, tb)
1185 self.mocker.result(None)1185 sys_except_hook.assert_called_once_with(SystemError, error, tb)
1186 self.mocker.replay()
1187 progress._prevent_dpkg_apport_error(SystemError, error, tb)
11881186
1189 def test_prevent_dpkg_apport_error_non_system_error(self):1187 def test_prevent_dpkg_apport_error_non_system_error(self):
1190 """1188 """
@@ -1679,20 +1677,20 @@
1679 old_stdout = os.dup(1)1677 old_stdout = os.dup(1)
1680 old_stderr = os.dup(2)1678 old_stderr = os.dup(2)
1681 fd, outfile = tempfile.mkstemp()1679 fd, outfile = tempfile.mkstemp()
1682 mkstemp = self.mocker.replace("tempfile.mkstemp")1680 mkstemp_patcher = mock.patch("tempfile.mkstemp")
1683 mkstemp()1681 mock_mkstemp = mkstemp_patcher.start()
1684 self.mocker.result((fd, outfile))1682 self.addCleanup(mkstemp_patcher.stop)
1685 dup = self.mocker.replace("os.dup")1683 mock_mkstemp.return_value = (fd, outfile)
1686 dup(1)1684
1687 self.mocker.result(old_stdout)1685 dup_patcher = mock.patch("os.dup")
1688 dup(2)1686 mock_dup = dup_patcher.start()
1689 self.mocker.result(old_stderr)1687 self.addCleanup(dup_patcher.stop)
1690 dup2 = self.mocker.replace("os.dup2")1688 mock_dup.side_effect = lambda fd: {1: old_stdout, 2: old_stderr}[fd]
1691 dup2(old_stdout, 1)1689
1692 self.mocker.passthrough()1690 dup2_patcher = mock.patch("os.dup2", wraps=os.dup2)
1693 dup2(old_stderr, 2)1691 mock_dup2 = dup2_patcher.start()
1694 self.mocker.passthrough()1692 self.addCleanup(dup2_patcher.stop)
1695 return outfile1693 return outfile, mock_dup2
16961694
1697 def test_perform_changes_dpkg_output_reset(self):1695 def test_perform_changes_dpkg_output_reset(self):
1698 """1696 """
@@ -1705,12 +1703,13 @@
1705 [foo] = self.facade.get_packages_by_name("foo")1703 [foo] = self.facade.get_packages_by_name("foo")
1706 self.facade.mark_install(foo)1704 self.facade.mark_install(foo)
17071705
1708 outfile = self._mock_output_restore()1706 outfile, mock_dup2 = self._mock_output_restore()
1709 self.mocker.replay()
1710 self.patch_cache_commit()1707 self.patch_cache_commit()
1711 self.facade.perform_changes()1708 self.facade.perform_changes()
1712 # Make sure we don't leave the tempfile behind.1709 # Make sure we don't leave the tempfile behind.
1713 self.assertFalse(os.path.exists(outfile))1710 self.assertFalse(os.path.exists(outfile))
1711 mock_dup2.assert_any_call(mock.ANY, 1)
1712 mock_dup2.assert_any_call(mock.ANY, 2)
17141713
1715 def test_perform_changes_dpkg_output_reset_error(self):1714 def test_perform_changes_dpkg_output_reset_error(self):
1716 """1715 """
@@ -1724,8 +1723,7 @@
1724 [foo] = self.facade.get_packages_by_name("foo")1723 [foo] = self.facade.get_packages_by_name("foo")
1725 self.facade.mark_install(foo)1724 self.facade.mark_install(foo)
17261725
1727 outfile = self._mock_output_restore()1726 outfile, mock_dup2 = self._mock_output_restore()
1728 self.mocker.replay()
17291727
1730 def commit(fetch_progress, install_progress):1728 def commit(fetch_progress, install_progress):
1731 raise SystemError("Error")1729 raise SystemError("Error")
@@ -1734,6 +1732,8 @@
1734 self.assertRaises(TransactionError, self.facade.perform_changes)1732 self.assertRaises(TransactionError, self.facade.perform_changes)
1735 # Make sure we don't leave the tempfile behind.1733 # Make sure we don't leave the tempfile behind.
1736 self.assertFalse(os.path.exists(outfile))1734 self.assertFalse(os.path.exists(outfile))
1735 mock_dup2.assert_any_call(mock.ANY, 1)
1736 mock_dup2.assert_any_call(mock.ANY, 2)
17371737
1738 def test_reset_marks(self):1738 def test_reset_marks(self):
1739 """1739 """
@@ -2154,12 +2154,12 @@
21542154
2155 [foo] = self.facade.get_packages_by_name("foo")2155 [foo] = self.facade.get_packages_by_name("foo")
2156 self.facade.mark_remove(foo)2156 self.facade.mark_remove(foo)
2157 cache = self.mocker.replace(self.facade._cache)2157 with mock.patch.object(self.facade._cache, "commit") as mock_commit:
2158 cache.commit(fetch_progress=ANY, install_progress=ANY)2158 mock_commit.side_effect = SystemError("Something went wrong.")
2159 self.mocker.throw(SystemError("Something went wrong."))2159 exception = self.assertRaises(TransactionError,
2160 self.mocker.replay()2160 self.facade.perform_changes)
2161 exception = self.assertRaises(TransactionError,2161 mock_commit.assert_called_with(
2162 self.facade.perform_changes)2162 fetch_progress=mock.ANY, install_progress=mock.ANY)
2163 self.assertIn("Something went wrong.", exception.args[0])2163 self.assertIn("Something went wrong.", exception.args[0])
21642164
2165 def test_mark_install_transaction_error(self):2165 def test_mark_install_transaction_error(self):

Subscribers

People subscribed via source and target branches

to all changes: