我想测试是否有异常,我该怎么办?
在我的models.py我有这个函数,我要测试的那个:
def validate_percent(value):
if not (value >= 0 and value <= 100):
raise ValidationError('error')
Run Code Online (Sandbox Code Playgroud)
在我的tests.py中我试过这个:
def test_validate_percent(self):
self.assertRaises(ValidationError, validate_percent(1000))
Run Code Online (Sandbox Code Playgroud)
测试的输出是:
..E
======================================================================
ERROR: test_validate_percent (tm.tests.models.helpers.HelpersTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/...py", line 21, in test_validate_percent
self.assertRaises(ValidationError, validate_percent(1000))
File "/....py", line 25, in validate_percent
raise ValidationError(u'error' % value)
ValidationError: ['error']
Run Code Online (Sandbox Code Playgroud) 我正在使用nginx和uwsgi运行django应用程序.它工作正常但突然我不知道我改变了什么应用程序停止工作.
问题在于uWsgi的python版本是2.4.3,它是Linux CentOs中的默认版本,我在2.7.3版本中安装了django,webpy和其他python发行版(将更快升级)
我也尝试创建一个从python 2.7路径到usr/bin中只是"python"的符号链接,但是没有用.
如何让uWsgi使用python2.7.3(/ usr/local/bin /)而不是2.4.3?
Django ini:
socket = 127.0.0.1:3031
master = true
processes = 4
env = DJANGO_SETTINGS_MODULE=djtest.settings
module = django.core.handlers.wsgi:WSGIHandler()
Run Code Online (Sandbox Code Playgroud)
当我初始化
./uwsgi --ini django.ini
[uWSGI] getting INI configuration from django.ini
*** Starting uWSGI 1.3 (64bit) on [Sat Nov 24 00:27:55 2012] ***
compiled with version: 4.1.2 20080704 (Red Hat 4.1.2-52) on 23 November 2012 22:37:39
os: Linux-2.6.18-194.17.4.el5xen #1 SMP Mon Oct 25 16:36:31 EDT 2010
nodename: v238545.hostingator.net
machine: x86_64
clock source: unix
detected number of …Run Code Online (Sandbox Code Playgroud) 我有一个JavaScript对象,并希望获得所有条目的最高价值。我已经试过了:
d = {
"A": [ {"value": 10}, {"value": 20}, {"value": 30} ],
"B": [ {"value": 50}, {"value": 60}, {"value": 1000} ],
}
Object.keys(d).map(
function(k) {
Math.max.apply(Math, d[k].map(
function(e) {
console.log(value);
}
))
}
) Run Code Online (Sandbox Code Playgroud)
结果应为1000。
python ×2
arrays ×1
django ×1
javascript ×1
mod-wsgi ×1
nginx ×1
object ×1
unit-testing ×1
uwsgi ×1