本文整理汇总了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()
示例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()
示例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
示例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
示例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()
示例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()
示例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()
示例8: teardown_method
def teardown_method(self, method):
mockfs.restore_builtins()
示例9: tearDown
def tearDown(self):
mockfs.restore_builtins()
示例10: mockfs
def mockfs(request):
mfs = replace_builtins()
request.addfinalizer(lambda: restore_builtins())
return mfs