草庐IT

test_home

全部标签

python - 如何在sklearn中获得一个非混洗的train_test_split

如果我想要随机训练/测试拆分,我使用sklearn辅助函数:In[1]:fromsklearn.model_selectionimporttrain_test_split...:train_test_split([1,2,3,4,5,6])...:Out[1]:[[1,6,4,2],[5,3]]获得非混洗训练/测试拆分的最简洁方法是什么,即[[1,2,3,4],[5,6]]编辑目前我正在使用train,test=data[:int(len(data)*0.75)],data[int(len(data)*0.75):]但希望有更好的东西。我在sklearn上开了一个问题https://g

python - 让 `python setup.py test` 语法起作用?

如何让pythonsetup.pytest工作?-当前输出:$pythonsetup.pytest#alsotried:`pythonsetup.pytests`/usr/lib/python2.7/distutils/dist.py:267:\UserWarning:Unknowndistributionoption:'test_suite'warnings.warn(msg)usage:setup.py[global_opts]cmd1[cmd1_opts][cmd2[cmd2_opts]...]or:setup.py--help[cmd1cmd2...]or:setup.py--

python - 如何使用 Flask test_client 设置请求参数?

我必须测试从request.args获取特定信息的特定View。我不能模拟这个,因为View中的很多东西都使用请求对象。我能想到的唯一替代方法是手动设置request.args。我可以用test_request_context()做到这一点,例如:withself.app.test_request_context()asreq:req.request.args={'code':'mockedaccesstoken'}MyView()现在此View中的请求将具有我设置的参数。但是我需要调用我的View,而不仅仅是初始化它,所以我使用这个:withself.app.test_client(

python - 安装rpy2时遇到错误: Tried to guess R's HOME but no R command in the PATH

我在这里和其他地方看到了很多关于此错误的帖子,但所提议的解决方案似乎都不相关。我在Python2.7.9,我有anRexecutableinmypath,我正在尝试将它安装在RHEL服务器上,而不是在Windows上。这是我看到的具体错误。有谁知道是什么原因造成的或如何解决?谢谢!$pipinstallrpy2Downloading/unpackingrpy2Downloadingrpy2-2.5.6.tar.gz(165kB):165kBdownloadedRunningsetup.py(path:/tmp/pip_build_my520/rpy2/setup.py)egg_info

python - 让 Nose 忽略名称中带有 'test' 的函数

nose发现过程会找到名称以test开头的所有模块,以及其中所有名称中包含test的函数,并尝试将它们作为单元测试运行。参见http://nose.readthedocs.org/en/latest/man.html我在文件accounts.py中有一个名为make_test_account的函数。我想在名为test_account的测试模块中测试该功能。所以在那个文件的开头我做了:fromfoo.accountsimportmake_test_account但现在我发现nose将函数make_test_account视为单元测试并尝试运行它(失败是因为它没有传递任何必需的参数)。如何

python - Flask test_client 去除查询字符串参数

我正在使用Flask创建几个非常简单的服务。从外部测试(使用HTTPie)参数通过查询字符串获取服务。但是如果我使用类似的东西。data={'param1':'somevalue1','param2':'somevalue2'}response=self.client.get(url_for("api.my-service",**data))我可以看到正在创建正确的URI:http://localhost:5000/api1.0/my-service?param1=somevalue1¶m2=somevalue2当我断点进入服务时:request.args实际上是空的。self

python - 启用覆盖时如何在 PyCharm 中调试 py.test

启用覆盖后如何在PyCharm中调试py.test?使用--cov=project--cov-report=term-missing启用覆盖,删除它并命中断点。版本:pycharm5.0.3,pytest==2.8.5,pytest-cache==1.0,pytest-cov==2.2.0,pytest-pep8==1.0.6,pytest-xdist==1.13.1,python-coveralls==2.6.0.(感谢jon对进一步诊断问题的建议) 最佳答案 现在有一个flaginpy.test禁用从PyCharm运行测试时可以

python - Airflow 没有以 airflow_home 目录中的目录命名的模块

我正在使用virtualenv。我正在尝试使用DAG文件夹中的包。airflow_home目录的当前状态是:airflow_home/airflow.cfgairflow_home/airflow.dbairflow_home/dags/__init__.pyairflow_home/dags/hello_world.pyairflow_home/dags/support/inner.pyairflow_home/dags/support/__init__.pyhello_world.py有代码:fromdatetimeimportdatetimefromairflowimportDA

python - Nose 、unittest.TestCase 和元类 : auto-generated test_* methods not discovered

这是unittestandmetaclass:automatictest_*methodgeneration的后续问题:对于这个(固定的)unittest.TestCase布局:#!/usr/bin/envpythonimportunittestclassTestMaker(type):def__new__(cls,name,bases,attrs):callables=dict([(meth_name,meth)for(meth_name,meth)inattrs.items()ifmeth_name.startswith('_test')])formeth_name,methinc

python - ConfigParser 和带有环境变量的字符串插值

我有点不懂python语法,我在读取带有内插值的.ini文件时遇到问题。这是我的ini文件:[DEFAULT]home=$HOMEtest_home=$home[test]test_1=$test_home/foo.csvtest_2=$test_home/bar.csv那些线fromConfigParserimportSafeConfigParserparser=SafeConfigParser()parser.read('config.ini')printparser.get('test','test_1')是否输出$test_home/foo.csv在我怀孕的时候/Users/n