Merge lp:~tribaal/landscape-client/remove-mocker-process into lp:~landscape/landscape-client/trunk

Proposed by Chris Glass
Status: Merged
Merged at revision: 847
Proposed branch: lp:~tribaal/landscape-client/remove-mocker-process
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 60 lines (+16/-15)
1 file modified
landscape/lib/tests/test_process.py (+16/-15)
To merge this branch: bzr merge lp:~tribaal/landscape-client/remove-mocker-process
Reviewer Review Type Date Requested Status
🤖 Landscape Builder test results Approve
Free Ekanayaka (community) Approve
Benji York (community) Approve
Review via email: mp+297496@code.launchpad.net

Commit message

s/mocker/mock/

Description of the change

Replaced some mocking, etc.

Testing instructions:

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This branch looks good with one small comment inline.

review: Approve
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:~tribaal/landscape-client/remove-mocker-process
Jenkins: https://ci.lscape.net/job/latch-test/5030/

review: Approve (test results)
Revision history for this message
Chris Glass (tribaal) :
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

+1

review: Approve
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: 846
Branch: lp:~tribaal/landscape-client/remove-mocker-process
Jenkins: https://ci.lscape.net/job/latch-test/5037/

review: Approve (test results)
Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
Download full text (178.8 KiB)

The attempt to merge lp:~tribaal/landscape-client/remove-mocker-process into lp:landscape-client failed. Below is the output from the failed tests.

python setup.py build_ext -i
running build_ext
landscape.broker.tests.test_amp
  RemoteBrokerTest
    test_call_if_accepted ... [OK]
    test_call_if_accepted_with_not_accepted ... [OK]
    test_call_on_events ... [OK]
    test_exit ... [OK]
    test_fire_event ... [OK]
    test_get_accepted_message_types ... [OK]
    test_get_server_uuid ... [OK]
    test_is_message_pending ... [OK]
    test_listen_events ... [OK]
    test_method_call_error ... [OK]
    test_ping ... [OK]
    test_register ... [OK]
    test_register_client ... [OK]
    test_register_client_accepted_message_type ... [OK]
    test_reload_configuration ... [OK]
    test_send_message ... [OK]
    test_send_message_with_urgent ... [OK]
    test_stop_clients ... [OK]
  RemoteClientTest
    test_exit ... [OK]
    test_fire_event ... [OK]
    test_message ... [OK]
    test_method_call_error ... [OK]
    test_ping ... [OK]
landscape.broker.tests.test_client
  BrokerClientTest
    test_add ... [OK]
    test_dispatch_message ... [OK]
    test_dispatch_message_with_exception ... [OK]
    test_dispatch_message_with_no_handler ... [OK]
    test_exchange ... [OK]
    test_exchange_logs_errors_and_continues ... [OK]
    test_exchange_on_plugin_without_exchange_method ... [OK]
    test_exit ... [OK]
    test_fire_event ... [OK]
    test_fire_event_with_acceptance_changed ... [OK]
    test_fire_event_with_arguments ... [OK]
    test_fire_event_with_mixed_results ... [OK]
    test_get_named_plugin ... [OK]
...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/lib/tests/test_process.py'
2--- landscape/lib/tests/test_process.py 2012-10-10 13:32:10 +0000
3+++ landscape/lib/tests/test_process.py 2016-06-15 17:28:32 +0000
4@@ -1,4 +1,5 @@
5 import unittest
6+import mock
7 import os
8
9 from landscape.tests.helpers import LandscapeTest
10@@ -39,15 +40,14 @@
11 stat = " ".join(stat_array)
12 create_file(os.path.join(process_dir, "stat"), stat)
13
14- def test_missing_process_race(self):
15+ @mock.patch("landscape.lib.process.detect_jiffies", return_value=1)
16+ @mock.patch("os.listdir")
17+ def test_missing_process_race(self, list_dir_mock, jiffies_mock):
18 """
19 We use os.listdir("/proc") to get the list of active processes, if a
20 process ends before we attempt to read the process' information, then
21 this should not trigger an error.
22 """
23- listdir_mock = self.mocker.replace("os.listdir")
24- listdir_mock("/proc")
25- self.mocker.result(["12345"])
26
27 class FakeFile(object):
28
29@@ -67,20 +67,21 @@
30 def close(self):
31 self.closed = True
32
33- open_mock = self.mocker.replace("__builtin__.open")
34- open_mock("/proc/12345/cmdline", "r")
35+ list_dir_mock.return_value = ["12345"]
36 fakefile1 = FakeFile("test-binary")
37- self.mocker.result(fakefile1)
38-
39- open_mock("/proc/12345/status", "r")
40 fakefile2 = FakeFile(None)
41- self.mocker.result(fakefile2)
42-
43- self.mocker.replay()
44-
45- process_info = ProcessInformation("/proc")
46- processes = list(process_info.get_all_process_info())
47+
48+ with mock.patch("__builtin__.open", mock.mock_open()) as open_mock:
49+ # This means "return fakefile1, then fakefile2"
50+ open_mock.side_effect = [fakefile1, fakefile2]
51+ process_info = ProcessInformation("/proc")
52+ processes = list(process_info.get_all_process_info())
53+ calls = [
54+ mock.call("/proc/12345/cmdline", "r"),
55+ mock.call("/proc/12345/status", "r")]
56+ open_mock.assert_has_calls(calls)
57 self.assertEqual(processes, [])
58+ list_dir_mock.assert_called_with("/proc")
59 self.assertTrue(fakefile1.closed)
60 self.assertTrue(fakefile2.closed)
61

Subscribers

People subscribed via source and target branches

to all changes: