當前位置: 首頁>>代碼示例>>Python>>正文


Python Mock.name方法代碼示例

本文整理匯總了Python中asynctest.Mock.name方法的典型用法代碼示例。如果您正苦於以下問題:Python Mock.name方法的具體用法?Python Mock.name怎麽用?Python Mock.name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asynctest.Mock的用法示例。


在下文中一共展示了Mock.name方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_matrix_build

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_matrix_build(mocker, SETTINGS):
    JENKINS = mocker.patch('jenkins_epo.jenkins.JENKINS')
    from jenkins_epo.jenkins import MatrixJob, JobSpec

    SETTINGS.DRY_RUN = 0

    api_instance = Mock()
    api_instance.name = 'matrix'
    api_instance._data = {'url': 'https://jenkins/job'}
    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    spec = JobSpec(api_instance.name)
    spec.config['parameters'] = {'PARAM': 1}

    job = MatrixJob(api_instance)
    job._node_axis = job._revision_param = None
    job._combination_param = 'C'
    job._revision_param = 'R'

    yield from job.build(
        Mock(url='url://', fullref='refs/heads/master'), spec, 'matrix',
    )

    assert JENKINS.rest.job().buildWithParameters.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:28,代碼來源:test_jenkins.py

示例2: test_update_job

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_update_job(mocker, SETTINGS):
    aget_job = mocker.patch(
        'jenkins_epo.jenkins.JENKINS.aget_job',
        CoroutineMock(),
    )
    rest = mocker.patch('jenkins_epo.jenkins.JENKINS.rest')

    url = rest.job()
    url.api.python.aget = CoroutineMock()
    url().aget = CoroutineMock()
    url().apost = CoroutineMock()

    from jenkins_epo.jenkins import Job

    SETTINGS.DRY_RUN = 1

    spec = Mock(config=dict())
    spec.name = 'job'

    job = Job(Mock(_data=dict()))
    new_job = yield from job.update(spec)
    assert new_job is job

    SETTINGS.DRY_RUN = 0
    new_job = yield from job.update(spec)
    assert new_job is not job
    assert aget_job.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:29,代碼來源:test_jenkins.py

示例3: test_create_job

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_create_job(mocker, SETTINGS):
    from jenkins_epo.jenkins import LazyJenkins

    JENKINS = LazyJenkins(Mock())
    JENKINS.rest = Mock()
    JENKINS.rest.createItem.apost = CoroutineMock()
    JENKINS.rest.job().api.python.aget = CoroutineMock(return_value=dict(
        url='url://', name='job',
    ))
    JENKINS.rest.job()('config.xml').aget = CoroutineMock(
        return_value=Mock(data='<project/>')
    )

    spec = Mock(config=dict())
    spec.name = 'job'

    SETTINGS.DRY_RUN = 1
    job = yield from JENKINS.create_job(spec)

    assert job is None
    assert 'updated_at' in spec.config['description']
    assert not JENKINS.rest.createItem.apost.mock_calls

    SETTINGS.DRY_RUN = 0
    job = yield from JENKINS.create_job(spec)

    assert job
    assert JENKINS.rest.createItem.apost.mock_calls
    assert JENKINS.rest.job().api.python.aget.mock_calls
    assert JENKINS.rest.job()().aget.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:32,代碼來源:test_jenkins.py

示例4: test_matrix_list_context_node

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_matrix_list_context_node():
    from jenkins_yml import Job
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict(activeConfigurations=[
        {'name': 'NODE=slave-legacy,P=a'},
        {'name': 'NODE=slave-ng,P=a'},
        {'name': 'NODE=slave-legacy,P=b'},
        {'name': 'NODE=slave-ng,P=b'},
    ])

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    job = MatrixJob(api_instance)
    job._node_axis = 'NODE'

    spec = Job('matrix', dict(
        node='slave-ng',
        axis={'P': ['a', 'b', 4.3]},
    ))
    contexts = [c for c in job.list_contexts(spec)]

    assert 2 == len(contexts)
    assert 'NODE=slave-legacy' not in ''.join(contexts)
    assert 'NODE=slave-ng' in ''.join(contexts)
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:31,代碼來源:test_jenkins.py

示例5: test_matrix_list_context_superset

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_matrix_list_context_superset(JobSpec):
    from jenkins_yml import Job
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict(activeConfigurations=[
        {'name': 'A=0,B=a'},
        {'name': 'A=1,B=a'},
        {'name': 'A=0,B=b'},
        {'name': 'A=1,B=b'},
        {'name': 'A=0,B=c'},
        {'name': 'A=1,B=c'},
    ])

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    jenkins_spec = JobSpec.from_xml.return_value
    jenkins_spec.config = dict(axis={'A': [0, 1], 'B': 'abc'})

    job = MatrixJob(api_instance)
    spec = Job('matrix', dict(axis={'B': 'acd'}))

    contexts = [c for c in job.list_contexts(spec)]

    haystack = '\n'.join(contexts)
    assert 'A=0' in haystack
    assert 'A=1' not in haystack
    assert 'B=b' not in haystack
    assert 2 == len(contexts)
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:34,代碼來源:test_jenkins.py

示例6: test_run_extension

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_run_extension(mocker):
    pkg_resources = mocker.patch('jenkins_epo.bot.pkg_resources')

    from jenkins_epo.bot import Bot

    ep = Mock()
    ep.name = 'ext'
    pkg_resources.iter_entry_points.return_value = [ep]
    ext = ep.resolve.return_value.return_value
    ext.DEFAULTS = {}
    ext.SETTINGS = {}
    ext.run.return_value = []

    bot = Bot()
    assert 'ext' in bot.extensions_map

    pr = Mock(name='pr', payload=dict())
    pr.fetch_commits = CoroutineMock()
    commits = [Mock()]
    pr.repository.process_commits.return_value = commits
    pr.fetch_comments = CoroutineMock(return_value=[])
    commits[0].fetch_statuses = CoroutineMock()

    yield from bot.run(pr)

    assert pr.fetch_commits.mock_calls
    assert pr.fetch_comments.mock_calls
    assert ext.begin.mock_calls
    assert ext.run.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:31,代碼來源:test_bot.py

示例7: test_filter_extension

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_filter_extension(iter_entry_points):
    loaded = Mock()
    loaded.name = 'loaded'
    ext = loaded.resolve.return_value.return_value
    ext.SETTINGS = {}
    skipped = Mock()
    skipped.name = 'skipped'

    iter_entry_points.return_value = [loaded, skipped]

    from jenkins_epo.bot import Bot

    Bot.ext_patterns.extend(['*', '-skip*'])

    bot = Bot()

    assert 'loaded' in bot.extensions_map
    assert 'skipped' not in bot.extensions_map
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:20,代碼來源:test_bot.py

示例8: test_fetch_builds

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_fetch_builds(mocker):
    Client = mocker.patch('jenkins_epo.jenkins.rest.Client')
    Client().api.python.aget = aget = CoroutineMock(
        return_value=dict(builds=[])
    )
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)
    yield from job.fetch_builds()

    assert aget.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:16,代碼來源:test_jenkins.py

示例9: test_process_builds

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_process_builds():
    from jenkins_epo.jenkins import Job

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'

    job = Job(api_instance)

    builds = list(job.process_builds([
        {'number': 1, 'url': 'url://'},
        {'number': 2, 'url': 'url://'},
    ]))

    assert 2 == len(builds)
    assert 2 == builds[0].number
    assert 1 == builds[1].number
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:18,代碼來源:test_jenkins.py

示例10: test_freestyle_node_param

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_freestyle_node_param():
    from jenkins_epo.jenkins import FreestyleJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance._data = dict()
    api_instance.name = 'freestyle'
    api_instance.get_params.return_value = [
        {'name': 'P', 'type': 'StringParameter'},
        {'name': 'N', 'type': 'LabelParameterDefinition'},
    ]
    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    job = FreestyleJob(api_instance)
    assert 'N' == job.node_param
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:18,代碼來源:test_jenkins.py

示例11: test_compat

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_compat():
    from jenkins_epo.extensions.core import ReportExtension

    ext = ReportExtension('merger', Mock())
    ext.current = Mock()
    ext.current.issue_url = None

    instruction = Mock(name='instruction', args='https://...')
    instruction.name = 'report-done'
    ext.process_instruction(instruction)
    assert ext.current.issue_url

    yield from ext.run()

    assert not ext.current.head.comment.mock_calls
    assert not ext.current.repository.report_issue.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:18,代碼來源:test_report.py

示例12: test_matrix_combination_param

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_matrix_combination_param():
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict()
    api_instance.get_params.return_value = [
        {'name': 'P', 'type': 'StringParameter'},
        {'name': 'C', 'type': 'MatrixCombinationsParameterDefinition'},
    ]

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    job = MatrixJob(api_instance)
    assert 'C' == job.combination_param
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:19,代碼來源:test_jenkins.py

示例13: test_matrix_node_axis

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_matrix_node_axis():
    from jenkins_epo.jenkins import MatrixJob

    api_instance = Mock(spec=['_get_config_element_tree', 'get_params'])
    api_instance.name = 'matrix'
    api_instance._data = dict()

    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    job = MatrixJob(api_instance)

    name_element = Mock()
    name_element.text = 'NODE'
    xml.findall.return_value = [name_element]

    assert 'NODE' == job.node_axis
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:20,代碼來源:test_jenkins.py

示例14: test_freestyle_build_dry

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_freestyle_build_dry(mocker, SETTINGS):
    JENKINS = mocker.patch('jenkins_epo.jenkins.JENKINS')

    from jenkins_epo.jenkins import FreestyleJob

    api_instance = Mock(_data=dict())
    api_instance.name = 'freestyle'
    xml = api_instance._get_config_element_tree.return_value
    xml.findall.return_value = []
    xml.find.return_value = None

    pr = Mock(url='url://')
    spec = Mock()
    spec.config = {}
    job = FreestyleJob(api_instance)
    job._node_param = None
    job._revision_param = None

    SETTINGS.DRY_RUN = 1

    yield from job.build(pr, spec, 'freestyle')

    assert not JENKINS.rest.job().buildWithParameters.apost.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:25,代碼來源:test_jenkins.py

示例15: test_run_skip_head

# 需要導入模塊: from asynctest import Mock [as 別名]
# 或者: from asynctest.Mock import name [as 別名]
def test_run_skip_head(mocker):
    pkg_resources = mocker.patch('jenkins_epo.bot.pkg_resources')

    from jenkins_epo.bot import Bot, SkipHead

    ep = Mock()
    ep.name = 'ext'
    pkg_resources.iter_entry_points.return_value = [ep]
    ext = ep.resolve.return_value.return_value
    ext.DEFAULTS = {}
    ext.SETTINGS = {}
    ext.run.side_effect = SkipHead()

    pr = Mock(name='pr', payload=dict())
    pr.fetch_commits = CoroutineMock()
    commits = [Mock()]
    pr.repository.process_commits.return_value = commits
    pr.fetch_comments = CoroutineMock(return_value=[])
    commits[0].fetch_statuses = CoroutineMock()

    yield from Bot().run(pr)

    assert ext.begin.mock_calls
    assert ext.run.mock_calls
開發者ID:novafloss,項目名稱:jenkins-github-poller,代碼行數:26,代碼來源:test_bot.py


注:本文中的asynctest.Mock.name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。