// fileImTestingAgainst.js
import theFuncIWantToMock from 'someModule'
export default function whatever () {
// logging for debugging purposes
console.log(theFuncIWantToMock)
const myVar = theFuncIWantToMock(/* args */)
// ... more stuff
}
// myTest.js
jest.mock('someModule', () => ({
theFuncIWantToMock: jest.fn()
}))
import theFuncIWantToMock from 'someModule'
import whatever from 'fileImTestingAgainst'
test('do my test', () => {
whatever()
expect(theFuncIWantToMock).toHaveBeenCalledWith('cat')
})
Run Code Online (Sandbox Code Playgroud)
我希望我console.log能显示它theFuncIWantToMock是一个mock实例,但我显示的是最初定义的函数。根据 Jest 文档,这就是我应该模拟模块的方式。但这似乎不起作用。
下载.zip文件后我收到此错误:
Traceback (most recent call last):
File "setup.py", line 15, in <module>
from __init__ import __version__
File "/Users/me/Downloads/gnuplot-py-1.8/__init__.py", line 164, in <module>
from gp import GnuplotOpts, GnuplotProcess, test_persist
ImportError: cannot import name GnuplotOpts
Run Code Online (Sandbox Code Playgroud)
我在我的机器上安装了gnuplot,如果我在终端上键入gnuplot,则弹出gnuplot终端.我试图用python调用它,它说它没有安装.这可能是一个路径问题,但我只是想确保安装所需的一切.(道路建议也将受到赞赏)
Mac 10.7 Lion
我正在尝试拆分我正在玩的数据文件中的行.这本来是别人的代码,只是试图"修复它".它们在分号上分裂,但我意识到它们实际上也需要它来分裂多余的空格.我已经把我的问题单独添加到第28行的表达式中.我正在尝试其他用户的一些建议,但是当我使用正则表达式命令时,我会收到invalid literal for int()警告.这很令人困惑,因为如果我不使用正则表达式,它就可以工作.有什么建议?谢谢.
编辑:编辑完整的代码链接.
如何在下面的结果中添加" http://test.url/ " link.get('href'),但前提是它不包含"http"
import urllib2
from bs4 import BeautifulSoup
url1 = "http://www.salatomatic.com/c/Sydney+168"
content1 = urllib2.urlopen(url1).read()
soup = BeautifulSoup(content1)
for link in soup.findAll('a'):
print link.get('href')
Run Code Online (Sandbox Code Playgroud) 有没有办法忽略列表中的值,在迭代脚本中创建除零而不是删除这些问题值?
我正在考虑如果
if(x==0):
break
elif(x!=0):
continue
Run Code Online (Sandbox Code Playgroud)
其中非零值通过脚本继续.
python ×4
python-2.7 ×2
string ×2
gnuplot ×1
javascript ×1
jestjs ×1
macos ×1
osx-lion ×1
reactjs ×1