本文整理汇总了Python中mockfs.replace_builtins函数的典型用法代码示例。如果您正苦于以下问题:Python replace_builtins函数的具体用法?Python replace_builtins怎么用?Python replace_builtins使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了replace_builtins函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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
示例2: 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()
示例3: test_cli_call_for_unsecured_conf
def test_cli_call_for_unsecured_conf(self, mock_subp, mock_modules):
with open(security_schema_path, 'r') as f:
mock_security_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jimmy_dir, 'lib', 'schema.yaml'): self.jimmy_schema,
os.path.join(jimmy_dir, 'jimmy.yaml'): self.mock_jimmy_yaml,
security_schema_path: mock_security_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' security:',
' unsecured: true'
])
})
sys.path.insert(0, modules_dir)
import security
import read_source
sys.path.pop(0)
mock_modules.return_value = [security, read_source]
os.chdir(jimmy_dir)
self.runner.invoke(cli)
calls = [call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
modules_dir + '/' + 'security/resources/jenkins.groovy',
'setUnsecured'],
shell=False)]
mock_subp.assert_has_calls(calls, any_order=True)
assert 1 == mock_subp.call_count, "subprocess call should be equal to 1"
示例4: test_valid_repo_data
def test_valid_repo_data(self):
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({jimmy_schema_path: self.jimmy_schema,
jimmy_yaml_path: self.mock_jimmy_yaml})
schema = yaml_reader.read(jimmy_schema_path)
repo_data = yaml_reader.read(jimmy_yaml_path)
jsonschema.validate(repo_data, schema)
示例5: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(pipeline_libraries_schema_path, 'r') as f:
mock_pipeline_libraries_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jimmy_dir, 'lib', 'schema.yaml'): self.jimmy_schema,
os.path.join(jimmy_dir, 'jimmy.yaml'): self.mock_jimmy_yaml,
pipeline_libraries_schema_path: mock_pipeline_libraries_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' pipeline_libraries:',
' libraries:',
' - name: shared-lib',
' git_url: https://github.com/example/shared-lib',
' git_branch: master',
' default_version: release-0.1',
' load_implicitly: true',
' allow_version_override: false',
' - name: shared-lib-dev',
' git_url: https://github.com/example/shared-lib-dev',
' git_branch: master',
' default_version: master',
' load_implicitly: false',
' allow_version_override: true'
])
})
sys.path.insert(0, plugins_dir)
import pipeline_libraries
import read_source
sys.path.pop(0)
mock_modules.return_value = [pipeline_libraries, read_source]
os.chdir(jimmy_dir)
self.runner.invoke(cli)
calls = [call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'pipeline_libraries/resources/jenkins.groovy',
'set_global_library',
'shared-lib',
'https://github.com/example/shared-lib',
'master',
'release-0.1',
'True',
'False'],
shell=False),
call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'pipeline_libraries/resources/jenkins.groovy',
'set_global_library',
'shared-lib-dev',
'https://github.com/example/shared-lib-dev',
'master',
'master',
'False',
'True'],
shell=False)]
print calls
mock_subp.assert_has_calls(calls, any_order=True)
assert 2 == mock_subp.call_count, "subprocess call should be equal to 2"
示例6: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(gearman_schema_path, 'r') as f:
mock_gearman_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jimmy_dir, 'lib', 'schema.yaml'): self.jimmy_schema,
os.path.join(jimmy_dir, 'jimmy.yaml'): self.mock_jimmy_yaml,
gearman_schema_path: mock_gearman_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' gearman:',
' enable: true',
' host: test.infra.mirantis.net',
' port: 4732'
])
})
sys.path.insert(0, plugins_dir)
import gearman
import read_source
sys.path.pop(0)
mock_modules.return_value = [gearman, read_source]
os.chdir(jimmy_dir)
self.runner.invoke(cli)
mock_subp.assert_called_with(
['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080',
'groovy',
plugins_dir + '/' + 'gearman/resources/jenkins.groovy',
'True', '4732', "'test.infra.mirantis.net'"
], shell=False)
assert 1 == mock_subp.call_count, "subprocess call should be equal to 1"
示例7: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(jenkins_schema_path, 'r') as f:
mock_jenkins_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jimmy_dir, 'lib', 'schema.yaml'): self.jimmy_schema,
os.path.join(jimmy_dir, 'jimmy.yaml'): self.mock_jimmy_yaml,
jenkins_schema_path: mock_jenkins_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' git:',
' user:',
' email: [email protected]',
' name: Jenkins'
])
})
sys.path.insert(0, modules_dir)
import git
import read_source
sys.path.pop(0)
mock_modules.return_value = [git, read_source]
os.chdir(jimmy_dir)
self.runner.invoke(cli)
mock_subp.assert_called_with(
['java', '-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
modules_dir + '/' + 'git/resources/jenkins.groovy',
"'[email protected]'", "'Jenkins'"
], shell=False)
assert 1 == mock_subp.call_count, "subproccess call should be equal to 1"
示例8: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(jenkins_schema_path, 'r') as f:
mock_jenkins_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jim_dir, 'lib', 'schema.yaml'): self.jim_schema,
os.path.join(jim_dir, 'jim.yaml'): self.mock_jim_yaml,
jenkins_schema_path: mock_jenkins_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' configuration:',
' admin_email: CI <[email protected]>',
' markup_format: raw-html',
' num_of_executors: 2',
' scm_checkout_retry_count: 1'
])
})
sys.path.insert(0, plugins_dir)
import jenkins_configuration
import read_source
sys.path.pop(0)
mock_modules.return_value = [jenkins_configuration, read_source]
os.chdir(jim_dir)
self.runner.invoke(cli)
mock_subp.assert_called_with(
['java', '-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'jenkins_configuration/resources/jenkins.groovy',
"'CI <[email protected]>'", 'raw-html', '2', '1'
], shell=False)
assert 1 == mock_subp.call_count, "subproccess call should be equal to 1"
示例9: test_cli_call_for_password_conf
def test_cli_call_for_password_conf(self, mock_subp, mock_modules):
with open(security_schema_path, 'r') as f:
mock_security_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jimmy_dir, 'lib', 'schema.yaml'): self.jimmy_schema,
os.path.join(jimmy_dir, 'jimmy.yaml'): self.mock_jimmy_yaml,
security_schema_path: mock_security_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' security:',
' password:',
' access:',
' - name: amihura',
' email: [email protected]',
' password: passwd',
' permissions:',
' - overall',
' - credentials',
' - gerrit',
' cli_user:',
' name: jenkins-manager',
' public_key: sssh-rsa AAAAB3NzaC',
' password: password'
])
})
sys.path.insert(0, modules_dir)
import security
import read_source
sys.path.pop(0)
mock_modules.return_value = [security, read_source]
os.chdir(jimmy_dir)
self.runner.invoke(cli)
calls = [call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
modules_dir + '/' + 'security/resources/jenkins.groovy',
'setSecurityPassword',
'jenkins-manager',
'sssh-rsa AAAAB3NzaC',
'password'],
shell=False),
call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
modules_dir + '/' + 'security/resources/jenkins.groovy',
'setPermissionsMatrix',
'amihura',
'overall,credentials,gerrit',
'[email protected]',
'passwd',
'',
'',
'password'],
shell=False)]
mock_subp.assert_has_calls(calls, any_order=True)
assert 2 == mock_subp.call_count, "subprocess call should be equal to 2"
示例10: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(throttle_schema_path, 'r') as f:
mock_throttle_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jim_dir, 'lib', 'schema.yaml'): self.jim_schema,
os.path.join(jim_dir, 'jim.yaml'): self.mock_jim_yaml,
throttle_schema_path: mock_throttle_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' plugins:',
' throttle:',
' categories:',
' - category_name: category1',
' max_total_concurrent_builds: 1',
' max_concurrent_bulds_per_node: 0',
' max_per_labeled_node:',
' - throttled_node_label: slave-label1',
' max_concurrent_per_labeled: 1',
' - throttled_node_label: slave-label2',
' max_concurrent_per_labeled: 1',
' - category_name: category2',
' max_total_concurrent_builds: 1',
' max_concurrent_bulds_per_node: 0'
])
})
sys.path.insert(0, plugins_dir)
import throttle
import read_source
sys.path.pop(0)
mock_modules.return_value = [throttle, read_source]
os.chdir(jim_dir)
self.runner.invoke(cli)
calls = [call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'throttle/resources/jenkins.groovy',
'clear_categories'],
shell=False),
call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'throttle/resources/jenkins.groovy',
'create_throttle_category',
'category1', '1', '0', 'slave-label1,slave-label2', '1,1'],
shell=False),
call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'throttle/resources/jenkins.groovy',
'create_throttle_category',
'category2', '1', '0', '', ''],
shell=False)
]
mock_subp.assert_has_calls(calls, any_order=True)
assert 3 == mock_subp.call_count, "subprocess call should be equal to 3"
示例11: 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
示例12: test_cli_call
def test_cli_call(self, mock_subp, mock_modules):
with open(gerrit_schema_path, 'r') as f:
mock_gerrit_schema = f.read()
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({os.path.join(jim_dir, 'lib', 'schema.yaml'): self.jim_schema,
os.path.join(jim_dir, 'jim.yaml'): self.mock_jim_yaml,
gerrit_schema_path: mock_gerrit_schema,
jenkins_yaml_path: '\n'.join(
[
'jenkins:',
' plugins:',
' gerrit:',
' servers:',
' - servername: test-gerrit-name',
' hostname: test-hostname',
' username: test-username',
' url: http://test.com',
' auth_key: /var/lib/jenkins/.ssh/id_rsa',
' - servername: test-gerrit-name2',
' hostname: test-hostname2',
' username: test-username2',
' url: http://test.com2',
' auth_key: /var/lib/jenkins/.ssh/id_rsa2'
])
})
sys.path.insert(0, plugins_dir)
import gerrit
import read_source
sys.path.pop(0)
mock_modules.return_value = [gerrit, read_source]
os.chdir(jim_dir)
self.runner.invoke(cli)
calls = [call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'gerrit/resources/jenkins.groovy',
"'test-hostname2'",
"'/var/lib/jenkins/.ssh/id_rsa2'",
"'test-gerrit-name2'",
"'http://test.com2'",
"'test-username2'"],
shell=False),
call(['java',
'-jar', '<< path to jenkins-cli.jar >>',
'-s', 'http://localhost:8080', 'groovy',
plugins_dir + '/' + 'gerrit/resources/jenkins.groovy',
"'test-hostname'",
"'/var/lib/jenkins/.ssh/id_rsa'",
"'test-gerrit-name'",
"'http://test.com'",
"'test-username'"],
shell=False)]
mock_subp.assert_has_calls(calls, any_order=True)
assert 2 == mock_subp.call_count, "subprocess call should be equal to 2"
示例13: 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()
示例14: test_validation_fail_for_envs_required_property
def test_validation_fail_for_envs_required_property(self):
with open(jimmy_yaml_path, 'r') as f:
jimmy_yaml = f.read()
mock_jimmy_yaml = jimmy_yaml.replace("envs:", "")
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({jimmy_yaml_path: mock_jimmy_yaml,
jimmy_schema_path: self.jimmy_schema})
schema = yaml_reader.read(jimmy_schema_path)
jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
with pytest.raises(jsonschema.ValidationError) as excinfo:
jsonschema.validate(jimmy_yaml_data, schema)
assert excinfo.value.message == "'envs' is a required property"
示例15: test_validation_fail_for_additional_properties
def test_validation_fail_for_additional_properties(self):
with open(jimmy_yaml_path, 'r') as f:
jimmy_yaml = f.read()
mock_jimmy_yaml = "\n".join([jimmy_yaml, "test:\n"])
self.mfs = mockfs.replace_builtins()
self.mfs.add_entries({jimmy_yaml_path: mock_jimmy_yaml,
jimmy_schema_path: self.jimmy_schema})
schema = yaml_reader.read(jimmy_schema_path)
jimmy_yaml_data = yaml_reader.read(jimmy_yaml_path)
with pytest.raises(jsonschema.ValidationError) as excinfo:
jsonschema.validate(jimmy_yaml_data, schema)
assert excinfo.value.message == "Additional properties are not allowed ('test' was unexpected)"