我有问题让Chai expect.to.throw
在我的node.js应用程序的测试中工作.测试在抛出错误时保持失败,但是如果我在try中包装测试用例并捕获并断言捕获的错误,则它可以工作.
难道expect.to.throw
不喜欢的工作,我认为它应该还是什么?
it('should throw an error if you try to get an undefined property', function (done) {
var params = { a: 'test', b: 'test', c: 'test' };
var model = new TestModel(MOCK_REQUEST, params);
// neither of these work
expect(model.get('z')).to.throw('Property does not exist in model schema.');
expect(model.get('z')).to.throw(new Error('Property does not exist in model schema.'));
// this works
try {
model.get('z');
}
catch(err) {
expect(err).to.eql(new Error('Property does not exist in model schema.'));
}
done();
});
Run Code Online (Sandbox Code Playgroud)
失败:
19 …
Run Code Online (Sandbox Code Playgroud) 尽管安装了插件,我似乎无法使用Nose进行代码覆盖.
有想法该怎么解决这个吗?
12:15:25 ~/sandbox/ec$ nosetests --plugins
Plugin xunit
Plugin deprecated
Plugin skip
Plugin multiprocess
Plugin failuredetail
Plugin capture
Plugin logcapture
Plugin coverage
Plugin attributeselector
Plugin doctest
Plugin profile
Plugin id
Plugin allmodules
Plugin collect-only
Plugin isolation
Plugin pdb
12:15:34 ~/sandbox/ec$ nosetests -v --with-coverage
nose.plugins.cover: ERROR: Coverage not available: unable to import coverage module
tests.edgecast_client_tests.test_log ... ok
----------------------------------------------------------------------
Ran 1 test in 0.206s
OK
Run Code Online (Sandbox Code Playgroud) 假设我有一个非常大的列表,我正在执行这样的操作:
for item in items:
try:
api.my_operation(item)
except:
print 'error with item'
Run Code Online (Sandbox Code Playgroud)
我的问题有两个方面:
我想使用多线程一次启动一堆api.my_operations,这样我就可以同时处理5个或10个甚至100个项目.
如果my_operation()返回一个异常(因为我可能已经处理过该项) - 那没关系.它不会破坏任何东西.循环可以继续到下一个项目.
注意:这适用于Python 2.7.3
我有两个时刻:
var fromDate = moment(new Date('1/1/2014'));
var toDate = moment(new Date('6/1/2014'));
Run Code Online (Sandbox Code Playgroud)
片刻是否提供了枚举这两个日期之间所有日期的方法?
如果没有,除了制作一个增加fromDate
1 的循环直到它到达时,还有更好的解决方案toDate
吗?
编辑:添加日期枚举方法和问题
我已经嘲笑了一个枚举两个日期之间日期的方法,但我遇到了一个问题.
var enumerateDaysBetweenDates = function(startDate, endDate) {
var dates = [];
startDate = startDate.add(1, 'days');
while(startDate.format('M/D/YYYY') !== endDate.format('M/D/YYYY')) {
console.log(startDate.toDate());
dates.push(startDate.toDate());
startDate = startDate.add(1, 'days');
}
return dates;
};
Run Code Online (Sandbox Code Playgroud)
我跑的时候看一下输出 enumerateDaysBetweenDates( moment(new Date('1/1/2014')), moment(new Date('1/5/2014'));
Thu Jan 02 2014 00:00:00 GMT-0800 (PST)
Fri Jan 03 2014 00:00:00 GMT-0800 (PST)
Sat Jan 04 2014 00:00:00 GMT-0800 (PST)
[ Sun Jan …
Run Code Online (Sandbox Code Playgroud) 昨天,我升级到了MacOS Sierra,它在我的tmux + neovim设置中打破了我的剪贴板功能.
这是行为:
每当我在tmux会话中使用vim中的剪贴板时,我都会收到以下vim错误:
clipboard: error:
Run Code Online (Sandbox Code Playgroud)
我.vimrc
是巨大的,但这是我认为可能相关的:
set clipboard=unnamed
Run Code Online (Sandbox Code Playgroud)
在我.tmux.conf
(为了简洁也截断):
set -g prefix ` # use tilde key as prefix
bind ` send-key ` # insert tilde by pressing twice
set -g history-limit 100000 # set buffer size
set -s escape-time 0 # fix escape key in vim
set -g allow-rename off # keep window names static
set -g default-terminal "screen-256color" # set the …
Run Code Online (Sandbox Code Playgroud) 有人可以解释为什么当我使用除00以外的秒设置datetime-local输入的默认值时,浏览器会给出错误"无效值".
这可能是Chrome在datetime-local实现中的一个错误,因为此错误未出现在最新的Firefox和Safari中.
Chrome中的错误:30.0.1599.69
Chrome Canary:32.0.1665.2金丝雀
这有效:
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:00">
Run Code Online (Sandbox Code Playgroud)
但这不是:
<input type="datetime-local" name="pub_date" value="2013-10-09T15:38:15">
Run Code Online (Sandbox Code Playgroud)
根据datetime-local input元素的W3 Spec,value属性应包含"表示本地日期和时间的字符串".
Example:
1985-04-12T23:20:50.52
1996-12-19T16:39:57
Run Code Online (Sandbox Code Playgroud)
我尝试了上面两个例子,但它们也没有用.
更新:确认错误和解决方案
这种行为是一个已知的错误.
截至今天,快速修复是为非零秒添加步骤属性:
<input type="datetime-local"
name="pub_date"
value="2013-10-09T15:38:15"
step="1">
Run Code Online (Sandbox Code Playgroud) 我需要根据加权循环法返回不同的值,以便20中的1得到A,20中的1得到B,其余的转到C.
所以:
A => 5%
B => 5%
C => 90%
Run Code Online (Sandbox Code Playgroud)
这是一个似乎有用的基本版本:
import random
x = random.randint(1, 100)
if x <= 5:
return 'A'
elif x > 5 and x <= 10:
return 'B'
else:
return 'C'
Run Code Online (Sandbox Code Playgroud)
这个算法是否正确?如果是这样,可以改进吗?
我正在使用MongoDB w/Mongoose ORM在Node.js/Express中构建一个基本博客.
我有一个预先'保存'钩子,我想用它为我自动生成一个博客/想法slug.这工作正常,除了我要查询的部分,以查看是否有任何其他现有帖子具有相同的slug继续之前.
但是,它似乎this
无法访问.find或.findOne(),所以我不断收到错误.
什么是最好的方法来解决这个问题?
IdeaSchema.pre('save', function(next) {
var idea = this;
function generate_slug(text) {
return text.toLowerCase().replace(/[^\w ]+/g,'').replace(/ +/g,'-').trim();
};
idea.slug = generate_slug(idea.title);
// this has no method 'find'
this.findOne({slug: idea.slug}, function(err, doc) {
console.log(err);
console.log(doc);
});
//console.log(idea);
next();
});
Run Code Online (Sandbox Code Playgroud) 我正在使用Switchvox,一个Asterisk PBX,我想在EC2上托管它.
Digium Switchvox提供了一个ISO,其中包含托管pbx服务器所需的一切:操作系统,软件等.它基本上是服务器的映像.
如何使用他们提供的自定义ISO实例化新的EC2实例?
我有这个正则表达式:
^(^?)*\?(.*)$
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,这就是它的功能细分:
那么(^?)*是什么意思?
python ×3
javascript ×2
node.js ×2
algorithm ×1
amazon-ec2 ×1
asterisk ×1
chai ×1
coverage.py ×1
ec2-ami ×1
express ×1
html5 ×1
iso ×1
lua ×1
macos-sierra ×1
mocha.js ×1
momentjs ×1
mongodb ×1
mongoose ×1
neovim ×1
nose ×1
pbx ×1
regex ×1
round-robin ×1
tmux ×1
vim ×1