Merge lp:~benji/landscape-client/new-mock-first-try into lp:~landscape/landscape-client/trunk

Proposed by Benji York
Status: Merged
Approved by: Benji York
Approved revision: 841
Merged at revision: 841
Proposed branch: lp:~benji/landscape-client/new-mock-first-try
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 46 lines (+7/-14)
1 file modified
landscape/lib/tests/test_gpg.py (+7/-14)
To merge this branch: bzr merge lp:~benji/landscape-client/new-mock-first-try
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Benji York (community) Approve
Adam Collard (community) Approve
Review via email: mp+295488@code.launchpad.net

Commit message

This branch is the first baby-step towards replacing Mocker in the
client tests with unittest.mock (more specifically, the Python2
backport "mock").

Description of the change

This branch is the first baby-step towards replacing Mocker in the
client tests with unittest.mock (more specifically, the Python2
backport "mock").

Testing instructions:

Just run the unit tests.

To post a comment you must log in.
Revision history for this message
Alberto Donato (ack) wrote :

+1, nice

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

What's the plan for supporting this on Precise?

I get the following error when running it in a Precise LXD container.

[ERROR]
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/twisted/trial/runner.py", line 572, in loadPackage
    module = modinfo.load()
  File "/usr/lib/python2.7/dist-packages/twisted/python/modules.py", line 383, in load
    return self.pathEntry.pythonPath.moduleLoader(self.name)
  File "/usr/lib/python2.7/dist-packages/twisted/python/reflect.py", line 464, in namedAny
    topLevelPackage = _importAndCheckStack(trialname)
  File "/home/ubuntu/src/new-mock-first-try/landscape/lib/tests/test_gpg.py", line 1, in <module>
    import mock
exceptions.ImportError: No module named mock

review: Needs Information
Revision history for this message
Adam Collard (adam-collard) wrote :

Actually, never mind, I installed python-mock and re-ran the tests to great success!

review: Approve
Revision history for this message
Benji York (benji) wrote :

I did a great job on this branch.

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

The attempt to merge lp:~benji/landscape-client/new-mock-first-try 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]
    t...

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
Download full text (179.1 KiB)

The attempt to merge lp:~benji/landscape-client/new-mock-first-try 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]
    t...

Revision history for this message
🤖 Landscape Builder (landscape-builder) wrote :
Download full text (179.1 KiB)

The attempt to merge lp:~benji/landscape-client/new-mock-first-try 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]
    t...

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

No approved revision specified.

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

No approved revision specified.

Revision history for this message
Alberto Donato (ack) 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/lib/tests/test_gpg.py'
2--- landscape/lib/tests/test_gpg.py 2011-07-05 05:09:11 +0000
3+++ landscape/lib/tests/test_gpg.py 2016-05-23 14:40:51 +0000
4@@ -1,3 +1,4 @@
5+import mock
6 import os
7
8 from twisted.internet import reactor
9@@ -20,15 +21,11 @@
10 "echo -n $@ > %s\n" % gpg_options)
11 os.chmod(gpg, 0755)
12 gpg_home = self.makeDir()
13- mkdtemp_mock = self.mocker.replace("tempfile.mkdtemp")
14- mkdtemp_mock()
15- self.mocker.result(gpg_home)
16- self.mocker.replay()
17-
18 deferred = Deferred()
19
20- def do_test():
21-
22+ @mock.patch("tempfile.mkdtemp")
23+ def do_test(mkdtemp_mock):
24+ mkdtemp_mock.return_value = gpg_home
25 result = gpg_verify("/some/file", "/some/signature", gpg=gpg)
26
27 def check_result(ignored):
28@@ -53,15 +50,11 @@
29 gpg = self.makeFile("#!/bin/sh\necho out; echo err >&2; exit 1\n")
30 os.chmod(gpg, 0755)
31 gpg_home = self.makeDir()
32- mkdtemp_mock = self.mocker.replace("tempfile.mkdtemp")
33- mkdtemp_mock()
34- self.mocker.result(gpg_home)
35- self.mocker.replay()
36-
37 deferred = Deferred()
38
39- def do_test():
40-
41+ @mock.patch("tempfile.mkdtemp")
42+ def do_test(mkdtemp_mock):
43+ mkdtemp_mock.return_value = gpg_home
44 result = gpg_verify("/some/file", "/some/signature", gpg=gpg)
45
46 def check_failure(failure):

Subscribers

People subscribed via source and target branches

to all changes: