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

Python mockfs.restore_builtins函数代码示例

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

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



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

示例1: test_get_telegram_key

    def test_get_telegram_key(self):
        print("Testing get_telegram_key()")

        from stallmanbot import read_configuration, get_telegram_key
        import os
        import configparser

        fs = mockfs.replace_builtins()
        SESSION = "TELEGRAM"
        fs.add_entries({"configuration.conf" : "[TELEGRAM]\n" + \
            "STALLBOT = abc:123456\n" + \
            "STALLBOTADM = HelioLoureiro\n"})
        sys = Mock()
        error = Mock()
        debug = Mock()

        cfg = read_configuration("configuration.conf")
        print(" * testing existent values")
        result = get_telegram_key(cfg, "STALLBOT")
        self.assertEqual(result, "abc:123456", "Resulting is mismatching expected value.")

        print(" * testing non-existent values")
        result = get_telegram_key(cfg, "ROCKNROLL")
        self.assertIsNone(result, "Command returned value (expected empty).")

        mockfs.restore_builtins()
开发者ID:helioloureiro,项目名称:homemadescripts,代码行数:26,代码来源:unittests_stallmanbot.py


示例2: test_save_file

    def test_save_file(self):
        print("Testing check_if_run()")
        from stallmanbot import save_file

        fs = mockfs.replace_builtins()
        fs.add_entries({"/tmp/testing" : ""})
        save_file("12345", "/tmp/testing")

        self.assertEqual("12345", fs.read("/tmp/testing"), "Saving data failed")

        mockfs.restore_builtins()
开发者ID:helioloureiro,项目名称:homemadescripts,代码行数:11,代码来源:unittests_stallmanbot.py


示例3: fs

def fs(request):
    mfs = mockfs.replace_builtins()

    os.path.lexists = mfs.exists
    glob.iglob = mfs.glob

    mfs.add_entries({
        "jasmine.yml": """
            src_files:
              - src/player.js
              - src/**/*.js
              - http://cdn.jquery.com/jquery.js
              - vendor/test.js
              - vendor/**/*.{js,coffee}
            """,
        "/spec/javascripts/helpers/spec_helper.js": '',
        "/lib/jams/jam_spec.js": '',
        "/src/player.js": '',
        "/src/mixer/mixer.js": '',
        "/src/tuner/fm/fm_tuner.js": '',
        "/spec/javascripts/player_spec.js": '',
        "/spec/javascripts/mixer/mixer_spec.js": '',
        "/spec/javascripts/tuner/fm/fm_tuner_spec.js": '',
        "/spec/javascripts/tuner/am/AMSpec.js": '',
        "/vendor/test.js": '',
        "/vendor/pants.coffee": '',
        "/vendor_spec/pantsSpec.js": '',
        "/main.css": '',
    })

    request.addfinalizer(lambda: mockfs.restore_builtins())

    return mfs
开发者ID:opg7371,项目名称:jasmine-py,代码行数:33,代码来源:config_test.py


示例4: mockfs

def mockfs(request):
    mfs = replace_builtins()
    mfs.add_entries({
        "/spec/javascripts/support/jasmine.yml": """
        src_dir: src
        spec_dir: spec
        """
    })
    request.addfinalizer(lambda: restore_builtins())
    return mfs
开发者ID:Fedorof,项目名称:jasmine-py,代码行数:10,代码来源:standalone_test.py


示例5: test_read_configuration

    def test_read_configuration(self):
        print("Testing read_configuration()")
        from stallmanbot import read_configuration
        import sys
        import time
        import os
        import configparser

        fs = mockfs.replace_builtins()
        SESSION = "TELEGRAM"
        fs.add_entries({"configuration.conf" : "[TELEGRAM]\n" + \
            "STALLBOT = abc:123456\n" + \
            "STALLBOTADM = HelioLoureiro\n"})
        sys.exit = MagicMock()
        error = MagicMock()

        print(" * correct configuration")
        cfg = read_configuration("configuration.conf")
        self.assertEqual(cfg.get(SESSION, "STALLBOT"), "abc:123456", "Parameter didn't match.")
        self.assertEqual(cfg.get(SESSION, "STALLBOTADM"), "HelioLoureiro", "Parameter didn't match.")

        print(" * missing session")
        SESSION = "FAKE"
        self.assertRaises(configparser.NoSectionError,
                          cfg.get,
                          SESSION,
                          "STALLBOT")
        print(" * missing session using utf-8")
        SESSION = "FåKEçÉ"
        self.assertRaises(configparser.NoSectionError,
                          cfg.get,
                          SESSION,
                          "STÁLLBÖT")

        print(" * missing parameter")
        SESSION = "TELEGRAM"
        self.assertRaises(configparser.NoOptionError,
                          cfg.get,
                          SESSION,
                          "WHATEVER")
        mockfs.restore_builtins()
开发者ID:helioloureiro,项目名称:homemadescripts,代码行数:41,代码来源:unittests_stallmanbot.py


示例6: test_read_file

    def test_read_file(self):
        print("Testing read_file()")
        from stallmanbot import read_file, error

        fs = mockfs.replace_builtins()
        fs.add_entries({ "/etc/python" : "zen of python",
                        "/étç/två" : "ett två três"})

        print(" * file exists and it is ASCII")
        result = read_file("/etc/python")
        self.assertEqual(result, "zen of python", "Failed to read content")

        print(" * file exists and it is UTF-8")
        result = read_file("/étç/två")
        self.assertEqual(result, "ett två três", "Failed to read content")

        print(" * file doesn't exist")
        result = read_file("/etc/helio_loureiro")
        self.assertEqual(result, None, "None return failed from non-existent file")

        mockfs.restore_builtins()
开发者ID:helioloureiro,项目名称:homemadescripts,代码行数:21,代码来源:unittests_stallmanbot.py


示例7: test_check_if_run

    def test_check_if_run(self):
        print("Testing check_if_run()")
        from stallmanbot import check_if_run, PIDFILE
        import sys
        import time
        import os

        fs = mockfs.replace_builtins()
        fs.add_entries({"%s/.stallmanbot.pid" % os.environ["HOME"] : "12345",
                       "/proc/12345/running" : "yes"})
        sys.exit = MagicMock(return_value="exiting")
        os.getpid = MagicMock(return_value=12345)
        log = MagicMock()

        print(" * process exists and is running")
        print("mypid=%d" % os.getpid())
        check_if_run()
        #sys.exit.assert_called_with(os.EX_OK)

        #print(" * process doesn't exist and isn't running")
        #fs.remove("%s/.stallmanbot.pid" % os.environ["HOME"])
        #check_if_run()

        mockfs.restore_builtins()
开发者ID:helioloureiro,项目名称:homemadescripts,代码行数:24,代码来源:unittests_stallmanbot.py


示例8: teardown_method

 def teardown_method(self, method):
     mockfs.restore_builtins()
开发者ID:fuel-infra,项目名称:jimmy,代码行数:2,代码来源:test_gearman.py


示例9: tearDown

 def tearDown(self):
     mockfs.restore_builtins()
开发者ID:ogsy,项目名称:mockfs,代码行数:2,代码来源:storage_test.py


示例10: mockfs

def mockfs(request):
    mfs = replace_builtins()
    request.addfinalizer(lambda: restore_builtins())
    return mfs
开发者ID:opg7371,项目名称:jasmine-py,代码行数:4,代码来源:entry_points_test.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python mockito.any函数代码示例发布时间:2022-05-27
下一篇:
Python mockfs.replace_builtins函数代码示例发布时间: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