本文整理汇总了Python中unittest.mock.Mock.settings方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.settings方法的具体用法?Python Mock.settings怎么用?Python Mock.settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.settings方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_coldfusion_formatter_fill_custom_options
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_coldfusion_formatter_fill_custom_options(
coldfusionbeautifier, options
):
fake_options = type('fake_obj', (object,), {})
coldfusionbeautifier.default_options = Mock(return_value=fake_options)
from codeformatter.coldfusionformatter import ColdfusionFormatter
mocked_formatter = Mock()
curr_options = {}
for k, v in options:
curr_options[k] = v
mocked_formatter.settings = {
'codeformatter_coldfusion_options': curr_options}
ColdfusionFormatter(mocked_formatter)
keys_tested = []
for k, v in options:
assert getattr(fake_options, k) == v
keys_tested.append(k)
for key, _ in options_to_test:
if key in keys_tested:
continue
assert not getattr(fake_options, key, None)
示例2: testBuild_namespace
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def testBuild_namespace(self):
file_path = ['folder1','folder2','src','folder3','folder4','test.php']
settings = Mock()
settings.get = Mock(return_value=['src','tests'])
view = Mock()
view.settings = Mock(return_value=settings)
view.file_name = Mock(return_value=os.sep.join(file_path))
assert build_namespace(view) == 'folder3\\folder4'
示例3: test_coldfusion_formatter_format_empty_exception
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_coldfusion_formatter_format_empty_exception(coldfusionbeautifier):
coldfusionbeautifier.beautify = Mock(side_effect=Exception(''))
from codeformatter.coldfusionformatter import ColdfusionFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {'codeformatter_coldfusion_options': {}}
input_text = 'test'.encode('utf8')
cff = ColdfusionFormatter(mocked_formatter)
out, err = cff.format(input_text)
assert out == ''
assert err == 'Formatting error!'
示例4: test_coldfusion_formatter_format_on_save_enabled
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_coldfusion_formatter_format_on_save_enabled(
coldfusionbeautifier, options, filename, expected
):
fake_options = type('fake_obj', (object,), {})
coldfusionbeautifier.default_options = Mock(return_value=fake_options)
from codeformatter.coldfusionformatter import ColdfusionFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {'codeformatter_coldfusion_options': options}
cff = ColdfusionFormatter(mocked_formatter)
res = cff.format_on_save_enabled(filename)
assert res is expected
示例5: test_coldfusion_formatter_instance_creation
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_coldfusion_formatter_instance_creation(coldfusionbeautifier):
coldfusionbeautifier.default_options = Mock(
return_value={'singer': 'nina'})
from codeformatter.coldfusionformatter import ColdfusionFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {
'codeformatter_coldfusion_options': 'feeling good'}
with patch.object(ColdfusionFormatter, 'fill_custom_options'):
cff = ColdfusionFormatter(mocked_formatter)
assert cff.formatter == mocked_formatter
assert cff.options == {'singer': 'nina'}
cff.fill_custom_options.assert_called_once_with('feeling good')
示例6: test_css_formatter_instance_creation
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_css_formatter_instance_creation(cssbeautifier):
cssbeautifier.default_options = Mock(
return_value={'band': 'beatles'})
from codeformatter.cssformatter import CssFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {
'codeformatter_css_options': 'a day in the life'}
with patch.object(CssFormatter, 'fill_custom_options'):
cf = CssFormatter(mocked_formatter)
assert cf.formatter == mocked_formatter
assert cf.options == {'band': 'beatles'}
cf.fill_custom_options.assert_called_once_with('a day in the life')
示例7: test_css_formatter_format_exception
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_css_formatter_format_exception(cssbeautifier):
cssbeautifier.beautify = Mock(
side_effect=Exception('looks like it failed'))
from codeformatter.cssformatter import CssFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {'codeformatter_css_options': {}}
input_text = 'test'.encode('utf8')
cff = CssFormatter(mocked_formatter)
out, err = cff.format(input_text)
assert out == ''
assert err == 'looks like it failed'
示例8: test_coldfusion_formatter_format
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_coldfusion_formatter_format(coldfusionbeautifier):
coldfusionbeautifier.default_options = Mock(return_value={})
coldfusionbeautifier.beautify = Mock(return_value='beautified text')
from codeformatter.coldfusionformatter import ColdfusionFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {'codeformatter_coldfusion_options': {}}
input_text = 'test'.encode('utf8')
cff = ColdfusionFormatter(mocked_formatter)
out, err = cff.format(input_text)
assert coldfusionbeautifier.beautify.called_with(
call(input_text.decode('utf-8'), {}))
assert out == 'beautified text'
assert err == ''
示例9: test_css_formatter_format
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_css_formatter_format(cssbeautifier):
cssbeautifier.default_options = Mock(return_value={})
cssbeautifier.beautify = Mock(return_value='graham nash')
from codeformatter.cssformatter import CssFormatter
mocked_formatter = Mock()
mocked_formatter.settings = {'codeformatter_css_options': {}}
input_text = 'test'.encode('utf8')
cff = CssFormatter(mocked_formatter)
out, err = cff.format(input_text)
assert cssbeautifier.beautify.called_with(
call(input_text.decode('utf-8'), {}))
assert out == 'graham nash'
assert err == ''
示例10: test_css_formatter_fill_custom_options_partialy
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_css_formatter_fill_custom_options_partialy(
cssbeautifier, key, value, expected, not_used_scenarios
):
fake_options = type('fake_obj', (object,), {})
cssbeautifier.default_options = Mock(return_value=fake_options)
from codeformatter.cssformatter import CssFormatter
mocked_formatter = Mock()
curr_options = {}
curr_options[key] = value
mocked_formatter.settings = {'codeformatter_css_options': curr_options}
CssFormatter(mocked_formatter)
assert getattr(fake_options, key) == expected
for key, expected in not_used_scenarios:
assert getattr(fake_options, key, None) == expected
示例11: test_css_formatter_fill_custom_options_full
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import settings [as 别名]
def test_css_formatter_fill_custom_options_full(
cssbeautifier, full_options
):
fake_options = type('fake_obj', (object,), {})
cssbeautifier.default_options = Mock(return_value=fake_options)
from codeformatter.cssformatter import CssFormatter
mocked_formatter = Mock()
curr_values = {}
curr_expected = []
for key, value, expected in full_options:
curr_values[key] = value
curr_expected.append((key, expected))
mocked_formatter.settings = {'codeformatter_css_options': curr_values}
CssFormatter(mocked_formatter)
for key, expected in curr_expected:
assert getattr(fake_options, key, None) == expected