小编bsl*_*ima的帖子

UnitTest Python模拟只有一个函数多次调用

我正在使用Mock(http://www.voidspace.org.uk/python/mock/mock.html),并遇到了一个特定的模拟案例,我无法找出解决方案.

我有一个函数,多次调用some_function正在被模拟.

def function():
    some_function(1)
    some_function(2)
    some_function(3)
Run Code Online (Sandbox Code Playgroud)

我只想嘲笑some_function的第一次和第三次调用.第二个电话我想成为真正的some_function.

我在http://www.voidspace.org.uk/python/mock/mock.html#mock.Mock.mock_calls尝试了一些替代方案,但没有成功.

在此先感谢您的帮助.

python unit-testing mocking

13
推荐指数
2
解决办法
6135
查看次数

XPath选择<div>的所有文本内容,但特定标记<h5>除外

我搜索并尝试了几个解决这个问题的方法,但没有一个工作:我有这个HTML

<div class="detalhes_colunadados">
   <div class="detalhescolunadados_blocos">
     <h5>Descrição completa</h5>
    Sala de estar/jantar,2 vagas de garagem cobertas.<br>
    </div>
    <div class="detalhescolunadados_blocos">
      <h5>Valores</h5>
            Venda: R$ 600.000,00<br>
          Condomínio: R$ 660,00<br>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

并且想要通过XPath仅提取第一个div class ="detalhescolunadados_blocos"中不是h5标签的文本内容.

我试过:// div [@ class ='detalhescolunadados_blocos']/[1]/*[not(self :: h5)]

html xpath siblings

9
推荐指数
1
解决办法
2万
查看次数

XML-RPC python客户端引发xml.parsers.expat.ExpatError异常

我正在尝试使用xmlrpclib python的lib执行XMP-RPC,但是我正在

xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 1, column 1
Run Code Online (Sandbox Code Playgroud)

这是带有参数的字典:

{'cliente_chave': 'hUi238sh328sjk37Hms8Kisjeg9',
     'cliente_codigo': 164,
     'imovel_bairro': u'Renascen\xe7a',
     'imovel_banheiros': u'5',
     'imovel_cidade': u'S\xe3o Lu\xeds - MA',
     'imovel_codigo_imobiliaria': u'757',
     'imovel_descricao': u'\n\t\t\t\n\t\t\tCasa em otima localiza\xe7\xe3o ideal tanto para empresas quanto para moradia tendo:\r\nTerra\xe7o\r\nSala Ampla para 03 ambientes\r\nLavabo\r\nHall\r\n03 su\xedtes\r\nEscritorio\r\nCozinha\r\nQuintaL\r\n\xc1rea de Servi\xe7o\r\nDCE\r\nGaragem coberta para 02 carros\r\nPort\xe3o eletronico\r\nCisterna\r\nNascente',
     'imovel_estado': 'MA',
     'imovel_negociacao': 'venda',
     'imovel_novo': False,
     'imovel_quartos': u'3',
     'imovel_subtipo': u'padr\xe3o',
     'imovel_suites': u'3',
     'imovel_tipo': u'casa',
     'imovel_vagas': u'2',
     'imovel_valor': u' 480.000,00',
     'url': 'http://www.estiloma.com.br/imoveis/para-venda/em-sao-luis/no-bairro-renascenca/casa-padrao/id-774.html'}
Run Code Online (Sandbox Code Playgroud)

这是对异常的追溯:

Traceback …
Run Code Online (Sandbox Code Playgroud)

python xml rpc xml-rpc xmlrpclib

1
推荐指数
1
解决办法
3094
查看次数

标签 统计

python ×2

html ×1

mocking ×1

rpc ×1

siblings ×1

unit-testing ×1

xml ×1

xml-rpc ×1

xmlrpclib ×1

xpath ×1