我正在使用openstack/bandit进行静态代码分析.有很多存储库,其中一些存在于python 2中的python 2中.如何在不运行代码的情况下检测代码是否在语法上与python 3兼容.
我要求显示过去30天的支出估算.SpendEstimation每天计算多次.这可以使用简单的SQL查询来实现:
SELECT DISTINCT ON (date) date(time) AS date, resource_id , time
FROM spend_estimation
WHERE
  resource_id = '<id>'
  and time > now() - interval '30 days'
ORDER BY date DESC, time DESC;
不幸的是,我似乎无法使用SQLAlchemy做同样的事情.它总是在所有列上创建select distinct.生成的查询不包含distinct on.
query = session.query(
    func.date(SpendEstimation.time).label('date'),
    SpendEstimation.resource_id,
    SpendEstimation.time
).distinct(
    'date'
).order_by(
    'date',
    SpendEstimation.time
)
SELECT DISTINCT
    date(time) AS date,
    resource_id,
    time 
FROM spend
ORDER BY date, time
它缺少ON (date)一点.如果我用户query.group_by- 然后SQLAlchemy添加distinct on.虽然我不能想到使用group by解决给定问题.
尝试使用不同部分的功能和按部件顺序.
query = session.query(
    func.date(SpendEstimation.time).label('date'),
    SpendEstimation.resource_id,
    SpendEstimation.time
).distinct( …是否可以将django grappeli和django管理工具菜单一起运行?
我已经安装了两个,但只能看到grappeli或管理工具(取决于INSTALLED_APPS中的顺序).
我发现老源说django管理工具和grappelli一起工作http://code.google.com/p/django-grappelli-admin-tools/,但是给出的文档没有帮助.
如果我向线程发送 SIGTSTP 信号,线程会停止吗?或者换句话说,它的行为会像 SIGTSTP 和 SIGCONT 上的进程一样吗?
提前致谢。
我想测试提交后消息是否发送给用户。我正在使用django.contrib.messages。在手动测试(运行服务器)期间一切似乎都正常,但在单元测试中我没有收到消息。
存储消息的代码:
messages.success(request, _('Internationalized evil message.'))
应测试消息的代码:
from django.contrib.messages.api import get_messages
...
def test_message_should_sent_to_user(self):
    """After successful phone number submit, message should be displayed."""
    response = self.client.post(
        reverse('evil.views.evil_data_submit'), self.valid_data)
    messages = get_messages(response.request)
    self.assertNotEqual(len(messages), 0)
看起来在测试客户端 post 方法调用期间没有调用任何中间件。
@Tisho回答后更新
消息应该可以在 中找到response.context,甚至我的直觉说它应该有效,但事实并非如此。我已将其放入import pdb; pdb.set_trace()django/contrib/messages/context_processors.py 中以查看其是否在测试期间被调用client.post,否则不会。
我已经仔细检查过TEMPLATE_CONTEXT_PROCESSORS,MIDDLEWARE_CLASSES并且INSTALLED_APPS- 也许明天我会发现我错过了一些东西。
重要细节
忘记提及,如果成功提交,视图将返回HttpResponseRedirect,因此response.context为空。
解决方案
View 返回重定向(没有上下文数据),为了解决这个问题,我们可以传递follow=True给 client.post 方法(@Tisho 建议的方法)。
我们有一个集成测试套件,可以在开始任何测试用例之前启动容器.我们曾经在执行任何测试之前等待端口可用,这表明应用程序已准备好接收请求.但是,在应用程序甚至在容器内部启动之前,1.7.1版本的端口立即可用.
是否可以选择推迟停靠端口转发,直到端口在容器内打开?
或者是否有其他可靠的方法来检查应用程序是否已在容器内启动?
是否可以使gnu make正在执行的进程输出目标名称?这将极大地帮助调试构建过程。
> make a
building b
building c
building a
最好不要echo $@在每个目标中添加语句。
我简直不敢相信,但可以在python代码中混合制表符和空格:
if __name__ == '__main__':
    for a in range(3): # indented with 4 spaces
        print(a)       # indented with 4 spaces and one tab
这背后的原因是什么?
测试:
注意:似乎stackoverflow用空格更改选项卡!
python ×2
c ×1
django ×1
docker ×1
flask ×1
indentation ×1
makefile ×1
postgresql ×1
pthreads ×1
sigkill ×1
sqlalchemy ×1
testing ×1