我很好奇是否有任何好的解决方案可以准确地建立公元1000年之前的日期 - 特别是公元1 - 100年.
例如,如果我想建立一个千禧年开始的日期,我不能只做...
new Date(Date.UTC(1,0,1,0,0,0,0));
Run Code Online (Sandbox Code Playgroud)
因为它试图"聪明"并假设1是1901年,这让我...
Sun Dec 31 1900 18:00:00 GMT-0600 (CST)
Run Code Online (Sandbox Code Playgroud)
同样的事情发生在99年......
new Date(Date.UTC(99,0,1,0,0,0,0));
Run Code Online (Sandbox Code Playgroud)
变成了
Thu Dec 31 1998 18:00:00 GMT-0600 (CST)
Run Code Online (Sandbox Code Playgroud)
思考?
我正在尝试在flask中测试自定义错误页面(404在本例中).
我已经定义了我的自定义404页面:
@app.errorhandler(404)
def page_not_found(e):
print "Custom 404!"
return render_template('404.html'), 404
Run Code Online (Sandbox Code Playgroud)
当在浏览器中访问未知页面时,这非常有效(我Custom 404!在stdout中看到并且我的自定义内容可见).但是,当尝试触发404 via unittest时nose,标准/服务器404页面呈现.我没有收到日志消息或我试图测试的自定义内容.
我的测试用例定义如下:
class MyTestCase(TestCase):
def setUp(self):
self.app = create_app()
self.app_context = self.app.app_context()
self.app.config.from_object('config.TestConfiguration')
self.app.debug = False # being explicit to debug what's going on...
self.app_context.push()
self.client = self.app.test_client()
def tearDown(self):
self.app_context.pop()
def test_custom_404(self):
path = '/non_existent_endpoint'
response = self.client.get(path)
self.assertEqual(response.status_code, 404)
self.assertIn(path, response.data)
Run Code Online (Sandbox Code Playgroud)
我app.debug明确设置了False我的测试应用程序.还有其他我必须明确设置的东西吗?