From 432db17eed1264d31535fdbedb0e022657fe6ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Mon, 27 Feb 2017 18:32:58 +0100 Subject: [PATCH] Rewrite test without mock. --- pyramid/tests/test_scripts/test_pserve.py | 45 ++++++++++++++++------- setup.py | 1 - 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index f681eaedbc..2e785ef366 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -1,8 +1,8 @@ -import mock import os import unittest from pyramid.tests.test_scripts import dummy + here = os.path.abspath(os.path.dirname(__file__)) @@ -81,18 +81,37 @@ def test_config_file_finds_watch_files(self): ]) def test_reload_call_hupper_with_correct_args(self): - with mock.patch('pyramid.scripts.pserve.hupper') as hupper_mock: - hupper_mock.is_active.side_effect = [False, True] - inst = self._makeOne('--reload', 'development.ini') - inst.loadserver = mock.MagicMock() - inst.loadapp = mock.MagicMock() - inst.run() - hupper_mock.start_reloader.assert_called_with( - 'pyramid.scripts.pserve.main', - reload_interval=1, - verbose=1, - worker_kwargs={'argv': ['pserve', '--reload', 'development.ini'], - 'quiet': False}) + from pyramid.scripts import pserve + hupper_start_reloader_args = None + hupper_start_reloader_kwargs = None + + class AttrDict(dict): + def __init__(self, *args, **kwargs): + super(AttrDict, self).__init__(*args, **kwargs) + self.__dict__ = self + + def dummy_is_active(): + return False + + def dummy_start_reloader(*args, **kwargs): + self.assertEquals(args, ('pyramid.scripts.pserve.main',)) + self.assertEquals(kwargs, { + 'reload_interval': 1, + 'verbose': 1, + 'worker_kwargs': {'argv': ['pserve', '--reload', 'development.ini'], + 'quiet': False}}) + + def dummy_function(*args, **kwargs): + pass + + pserve.hupper = AttrDict(is_active=dummy_is_active, + start_reloader=dummy_start_reloader) + + inst = self._makeOne('--reload', 'development.ini') + inst.loadserver = dummy_function + inst.loadapp = dummy_function + inst.run() + class Test_main(unittest.TestCase): diff --git a/setup.py b/setup.py index bd0e7f4d7e..ab2170fecb 100644 --- a/setup.py +++ b/setup.py @@ -65,7 +65,6 @@ ] testing_extras = tests_require + [ - 'mock', 'nose', 'coverage', 'virtualenv', # for scaffolding tests