• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python testfixtures.Replacer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中testfixtures.Replacer的典型用法代码示例。如果您正苦于以下问题:Python Replacer类的具体用法?Python Replacer怎么用?Python Replacer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Replacer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_cleanup_properly

    def test_cleanup_properly(self):
        r = Replacer()
        try:
            m = Mock()
            d = mkdtemp()
            m.return_value = d
            r.replace('testfixtures.tempdirectory.mkdtemp',m)

            self.failUnless(os.path.exists(d))

            self.assertFalse(m.called)
            
            @tempdir()
            def test_method(d):
                d.write('something', b'stuff')
                d.check('something', )

            self.assertFalse(m.called)
            compare(os.listdir(d),[])

            test_method()
            
            self.assertTrue(m.called)
            self.failIf(os.path.exists(d))
            
        finally:
            r.restore()
            if os.path.exists(d):
                # only runs if the test fails!
                rmtree(d) # pragma: no cover
开发者ID:jonflusspferd,项目名称:testfixtures,代码行数:30,代码来源:test_tempdir.py


示例2: TestCommandTaskWithMockPopen

class TestCommandTaskWithMockPopen(MockLoggerMixin, unittest.TestCase):
    """ Run command tasks with a mocked popen """

    def setUp(self):
        self.global_config = BaseGlobalConfig()
        self.project_config = BaseProjectConfig(
            self.global_config, config={"noyaml": True}
        )
        self.task_config = TaskConfig()

        self._task_log_handler.reset()
        self.task_log = self._task_log_handler.messages

        self.Popen = MockPopen()
        self.r = Replacer()
        self.r.replace("cumulusci.tasks.command.subprocess.Popen", self.Popen)
        self.addCleanup(self.r.restore)

    def test_functional_mock_command(self):
        """ Functional test that runs a command with mocked
        popen results and checks the log.
        """

        self.task_config.config["options"] = {"command": "ls -la"}

        self.Popen.set_command("ls -la", stdout=b"testing testing 123", stderr=b"e")

        task = Command(self.project_config, self.task_config)
        task()

        self.assertTrue(any("testing testing" in s for s in self.task_log["info"]))
开发者ID:SalesforceFoundation,项目名称:CumulusCI,代码行数:31,代码来源:test_command.py


示例3: setUp

 def setUp(self):
     self.dir = TempDirectory()
     self.addCleanup(self.dir.cleanup)
     self.Popen = MockPopen()
     r = Replacer()
     r.replace('archivist.helpers.Popen', self.Popen)
     self.addCleanup(r.restore)
开发者ID:Simplistix,项目名称:archivist,代码行数:7,代码来源:helpers.py


示例4: test_replacer_del

 def test_replacer_del(self):
     r = Replacer()
     r.replace('testfixtures.tests.sample1.left_behind',
               object(), strict=False)
     with catch_warnings(record=True) as w:
         del r
         self.assertTrue(len(w), 1)
         compare(str(w[0].message),
                 "Replacer deleted without being restored, ""originals left:"
                 " {'testfixtures.tests.sample1.left_behind': <not_there>}")
开发者ID:jonflusspferd,项目名称:testfixtures,代码行数:10,代码来源:test_replace.py


示例5: SavedSearchFormTests

class SavedSearchFormTests(TestCase):
    def setUp(self):
        super(SavedSearchFormTests, self).setUp()
        self.user = UserFactory()
        self.data = {'url': 'http://www.my.jobs/jobs',
                     'feed': 'http://www.my.jobs/jobs/feed/rss?',
                     'email': '[email protected]',
                     'frequency': 'D',
                     'label': 'All jobs from www.my.jobs',
                     'sort_by': 'Relevance'}

        self.r = Replacer()
        self.r.replace('urllib2.urlopen', return_file)

    def tearDown(self):
        self.r.restore()

    def test_successful_form(self):
        form = SavedSearchForm(user=self.user,data=self.data)
        self.assertTrue(form.is_valid())

    def test_invalid_url(self):
        self.data['url'] = 'http://google.com'
        form = SavedSearchForm(user=self.user,data=self.data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['url'][0], 'This URL is not valid.')

    def test_day_of_week(self):
        self.data['frequency'] = 'W'
        form = SavedSearchForm(user=self.user,data=self.data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['day_of_week'][0], 'This field is required.')

        self.data['day_of_week'] = '1'
        form = SavedSearchForm(user=self.user,data=self.data)        
        self.assertTrue(form.is_valid())

    def test_day_of_month(self):
        self.data['frequency'] = 'M'
        form = SavedSearchForm(user=self.user,data=self.data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['day_of_month'][0], 'This field is required.')

        self.data['day_of_month'] = '1'
        form = SavedSearchForm(user=self.user,data=self.data)        
        self.assertTrue(form.is_valid())

    def test_duplicate_url(self):
        original = SavedSearchFactory(user=self.user)
        form = SavedSearchForm(user=self.user,data=self.data)

        self.assertFalse(form.is_valid())
        self.assertEqual(form.errors['url'][0], 'URL must be unique.')
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:53,代码来源:forms.py


示例6: test_import_and_obtain_with_lists

    def test_import_and_obtain_with_lists(self):

        t = test_datetime(None)
        t.add(2002, 1, 1, 1, 0, 0)
        t.add(2002, 1, 1, 2, 0, 0)

        from testfixtures import Replacer
        r = Replacer()
        r.replace('testfixtures.tests.sample1.now', t.now)
        try:
            compare(sample1.str_now_2(), '2002-01-01 01:00:00')
            compare(sample1.str_now_2(), '2002-01-01 02:00:00')
        finally:
            r.restore()
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:14,代码来源:test_datetime.py


示例7: test_import_and_obtain_with_lists

    def test_import_and_obtain_with_lists(self):

        t = test_date(None)
        t.add(2002, 1, 1)
        t.add(2002, 1, 2)

        from testfixtures import Replacer
        r = Replacer()
        r.replace('testfixtures.tests.sample1.today', t.today)
        try:
            compare(sample1.str_today_2(), '2002-01-01')
            compare(sample1.str_today_2(), '2002-01-02')
        finally:
            r.restore()
开发者ID:Alexhuszagh,项目名称:XLDiscoverer,代码行数:14,代码来源:test_date.py


示例8: PopenCommandsTest

class PopenCommandsTest(unittest.TestCase):

    def setUp(self):
        self.Popen = MockPopen()
        self.r = Replacer()
        self.r.replace('swabbie.utils.command.subprocess.Popen', self.Popen)
        self.addCleanup(self.r.restore)

    def test_call_cmd(self):
        self.Popen.set_command('cmd1', stdout='foo')
        command_result = Command._call_cmd('cmd1')
        expected_command_result = CommandResult(output='foo', return_code=0)
        self.assertEqual(command_result.output, expected_command_result.output)
        self.assertEqual(command_result.return_code, expected_command_result.return_code)
        self.assertFalse(command_result.err)
开发者ID:cgallag,项目名称:swabbie,代码行数:15,代码来源:test_command.py


示例9: test_function

    def test_function(self):
        from testfixtures.tests import sample1
        assert sample1.z() == 'original z'

        def test_z():
          return 'replacement z'

        r = Replacer()
        r.replace('testfixtures.tests.sample1.z',test_z)

        assert sample1.z() == 'replacement z'

        r.restore()

        assert sample1.z() == 'original z'
开发者ID:Simplistix,项目名称:testfixtures,代码行数:15,代码来源:test_replacer.py


示例10: test_method

    def test_method(self):
        from testfixtures.tests import sample1
        assert sample1.X().y() == 'original y'

        def test_y(self):
          return 'replacement y'

        r = Replacer()
        r.replace('testfixtures.tests.sample1.X.y',test_y)

        assert sample1.X().y()[:38] == 'replacement y'

        r.restore()

        assert sample1.X().y() == 'original y'
开发者ID:Simplistix,项目名称:testfixtures,代码行数:15,代码来源:test_replacer.py


示例11: setUp

    def setUp(self):
        super(MySearchViewTests, self).setUp()
        self.client = TestClient()
        self.user = UserFactory()
        self.client.login_user(self.user)
        self.new_form_data = {
            'url': 'www.my.jobs/jobs',
            'feed': 'http://www.my.jobs/jobsfeed/rss?',
            'label': 'Jobs Label',
            'email': self.user.email,
            'frequency': 'D',
            'is_active': 'True',
            'sort_by': 'Relevance',
        }
        self.new_digest_data = {
            'is_active': 'True',
            'user': self.user,
            'email': self.user.email,
            'frequency': 'M',
            'day_of_month': 1,
        }
        self.new_form = forms.SavedSearchForm(user=self.user,
                                              data=self.new_form_data)

        self.r = Replacer()
        self.r.replace('urllib2.urlopen', return_file)
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:26,代码来源:views.py


示例12: setUp

    def setUp(self):
        self.redirect_guid = JOB['guid']
        self.redirect = RedirectFactory(buid=JOB['buid'],
                                        guid='{%s}' %
                                             uuid.UUID(self.redirect_guid))

        self.password = 'secret'
        self.user = User.objects.create(email='[email protected]')
        self.user.set_password(self.password)
        self.user.save()

        self.contact = CompanyEmail.objects.create(
            buid=self.redirect.buid,
            email=self.user.email)

        self.email = self.user.email.replace('@', '%40')
        self.auth = {
            'bad': [
                '',
                'Basic %s' % base64.b64encode('bad%40email:wrong_pass')],
            'good':
                'Basic %s' % base64.b64encode('%s:%s' % (self.user.email.\
                                                         replace('@', '%40'),
                                                         self.password))}
        self.post_dict = {'to': '[email protected]',
                          'from': '[email protected]',
                          'text': 'This address does not contain a valid guid',
                          'html': '',
                          'subject': 'Bad Email',
                          'attachments': 0}

        self.r = Replacer()
        self.r.replace('pysolr.Solr.search', mock_search)
开发者ID:DirectEmployers,项目名称:MyJobs-urls,代码行数:33,代码来源:test_views.py


示例13: setUp

 def setUp(self):
     self.r = Replacer()
     # test values for author info, requiring less setup
     self.r.replace('opencore.views.people.get_author_info',
                    lambda id,request: { 
             'title'  : 'Author title',
             'country' : 'Author country',
             'organization' : 'author org',
             'url' : 'author-url',
             'photo_url' : 'author-photo-url',
             })
     self.r.replace('opencore.views.forms.get_current_request',
                    lambda :self.request)
     self.r.replace('opencore.views.forms.authenticated_userid',
                    lambda request:'auth_user_id')
     
     testing.cleanUp()
     sessions = DummySessions()
     context = DummyProfile(sessions=sessions, **profile_data)
     context.title = 'title'
     context.__name__='admin'
     context.users = DummyUsers()
     context.users.add('admin','admin','password',())
     self.context = context
     request = testing.DummyRequest()
     request.api = get_template_api(context, request)
     request.context = context
     self.request = request
开发者ID:junkafarian,项目名称:opencore,代码行数:28,代码来源:test_people.py


示例14: setUp

 def setUp(self):
     super(SavedSearchHelperTests, self).setUp()
     self.user = UserFactory()
     self.valid_url = 'http://www.my.jobs/search?location=chicago&q=nurse'
     
     self.r = Replacer()
     self.r.replace('urllib2.urlopen', return_file)
开发者ID:panyang,项目名称:MyJobs,代码行数:7,代码来源:helpers.py


示例15: setUp

    def setUp(self):
        self.replacer = Replacer()

        self.mock_a = MagicMock()
        self.mock_b = MagicMock()

        self.replacer.replace('test_hello.RealClassA', self.mock_a)
        self.replacer.replace('test_hello.RealClassB', self.mock_b)
开发者ID:yhchan,项目名称:taipei.py-2013-05-slides,代码行数:8,代码来源:test_hello.py


示例16: setUp

 def setUp(self):
     self.config = {
         "authorize_url": "localhost:8080/goauth/authorize",
         "cache": {"class": "nexus.token_utils.InMemoryCache", "args": []},
         "server": "graph.api.globusonline.org",
         "api_key": "I am not a key",
         "api_secret": "I am not a secret",
     }
     self.replacer = Replacer()
开发者ID:kbase,项目名称:auth_service,代码行数:9,代码来源:client_tests.py


示例17: test_class

    def test_class(self):
        from testfixtures.tests import sample1
        x = sample1.X()
        assert x.__class__.__name__ == 'X'

        class XReplacement(sample1.X): pass

        r = Replacer()
        r.replace('testfixtures.tests.sample1.X', XReplacement)

        x = sample1.X()
        assert x.__class__.__name__ == 'XReplacement'
        assert sample1.X().y() == 'original y'

        r.restore()

        x = sample1.X()
        assert x.__class__.__name__ == 'X'
开发者ID:Simplistix,项目名称:testfixtures,代码行数:18,代码来源:test_replacer.py


示例18: test_class_method

    def test_class_method(self):
        from testfixtures.tests import sample1
        c = sample1.X
        assert sample1.X.aMethod() is c

        def rMethod(cls):
          return cls, 1

        r = Replacer()
        r.replace('testfixtures.tests.sample1.X.aMethod',rMethod)

        sample1.X.aMethod()
        assert sample1.X.aMethod() == (c, 1)

        r.restore()

        sample1.X.aMethod()
        assert sample1.X.aMethod() is c
开发者ID:Simplistix,项目名称:testfixtures,代码行数:18,代码来源:test_replacer.py


示例19: TestCheck

class TestCheck(TestCase):
    def setUp(self):
        self.r = Replacer()
        self.l = LogCapture()

    def tearDown(self):
        self.l.uninstall()
        self.r.restore()

    def checker_returns(self, output):
        resolve = Mock()
        self.r.replace("checker.check.resolve", resolve)

        def the_checker(config_folder, param):
            return output

        resolve.return_value = the_checker
        return resolve

    def test_bad_checker(self):
        with ShouldRaise(ImportError("No module named unknown")):
            check("/config", "unknown", None)

    def test_normal(self):
        m = self.checker_returns("some output")
        check("/config", "achecker", None)
        compare(m.call_args_list, [(("checker.checkers.achecker.check",), {})])

    def test_log_newline(self):
        self.checker_returns("some output\n")
        check("/config", "achecker", "aparam")
        self.l.check(("root", "INFO", "some output"))

    def test_log_no_newline(self):
        self.checker_returns("some output")
        check("/config", "achecker", "aparam")
        self.l.check(("root", "INFO", "some output"))

    def test_no_log_empty(self):
        self.checker_returns("")
        check("/config", "achecker", "aparam")
        self.l.check()
开发者ID:Simplistix,项目名称:checker,代码行数:42,代码来源:test_main.py


示例20: setUp

    def setUp(self):
        super(SavedSearchResourceTests, self).setUp()
        self.user = UserFactory()
        self.client = TestClient()
        self.data = {'email':'[email protected]', 'url':'www.my.jobs/jobs'}
        create_api_key(User, instance=self.user, created=True)

        self.credentials = (self.user.email, self.user.api_key.key)

        self.r = Replacer()
        self.r.replace('urllib2.urlopen', return_file)
开发者ID:jpaezsa,项目名称:MyJobs,代码行数:11,代码来源:api.py



注:本文中的testfixtures.Replacer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testfixtures.TempDirectory类代码示例发布时间:2022-05-27
下一篇:
Python testfixtures.LogCapture类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap