TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

FreezeGun: easy mocking of Python datetimes

88 点作者 spulec超过 12 年前

7 条评论

JonnieCache超过 12 年前
Rubyists desiring similar functionality should check out either of the following libs. As far as I can tell they differ only in their pun selection.<p><a href="https://github.com/travisjeffery/timecop" rel="nofollow">https://github.com/travisjeffery/timecop</a><p><a href="https://github.com/bebanjo/delorean" rel="nofollow">https://github.com/bebanjo/delorean</a><p>In the ruby community, disliking someone's choice of science fiction reference is grounds for a rewrite.
评论 #4908132 未加载
评论 #4906536 未加载
ericmoritz超过 12 年前
nice project. I usually avoid this by making my APIs accept a datetime objects and make the client code create the datetime object.<p>Pure functions make tests simple.
评论 #4907937 未加载
marcofucci超过 12 年前
Quick question: why did you need to write FreezeGun?<p>I've always used Mock <a href="http://www.voidspace.org.uk/python/mock/" rel="nofollow">http://www.voidspace.org.uk/python/mock/</a> to patch datetimes and I've never had any problems.<p>You can patch pretty much anything with Mock.
TimothyFitz超过 12 年前
Cool, but unfortunately it breaks if the code your testing does from datetime import datetime :(<p><a href="https://gist.github.com/4261936" rel="nofollow">https://gist.github.com/4261936</a>
评论 #4906743 未加载
ekimekim超过 12 年前
What about those of us who prefer the simpler time module (which works mostly in epoch time)? It would be a simple change to extend FreezeGun to cover that module in a similar way, surely?
manish_gill超过 12 年前
I don't really have much experience in datetimes I guess. What is this really good for? Can someone provide some use cases where this library might be helpful?<p>Thanks
评论 #4907743 未加载
davepeck超过 12 年前
How well does this handle aware (non-naive) datetimes?