commit
f5072cf434
@ -0,0 +1,42 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Timezone utilities
|
||||
|
||||
Just UTC-awareness right now
|
||||
"""
|
||||
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
from datetime import tzinfo, timedelta, datetime
|
||||
|
||||
# constant for zero offset
|
||||
ZERO = timedelta(0)
|
||||
|
||||
class tzUTC(tzinfo):
|
||||
"""tzinfo object for UTC (zero offset)"""
|
||||
|
||||
def utcoffset(self, d):
|
||||
return ZERO
|
||||
|
||||
def dst(self, d):
|
||||
return ZERO
|
||||
|
||||
UTC = tzUTC()
|
||||
|
||||
def utc_aware(unaware):
|
||||
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""
|
||||
def utc_method(*args, **kwargs):
|
||||
dt = unaware(*args, **kwargs)
|
||||
return dt.replace(tzinfo=UTC)
|
||||
return utc_method
|
||||
|
||||
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
|
||||
utcnow = utc_aware(datetime.utcnow)
|
||||
|
||||
def isoformat(dt):
|
||||
"""Return iso-formatted timestamp
|
||||
|
||||
Like .isoformat(), but uses Z for UTC instead of +00:00
|
||||
"""
|
||||
return dt.isoformat().replace('+00:00', 'Z')
|
||||
@ -0,0 +1,32 @@
|
||||
"""Test the basic /api endpoints"""
|
||||
|
||||
import requests
|
||||
|
||||
from notebook._tz import isoformat
|
||||
from notebook.utils import url_path_join
|
||||
from notebook.tests.launchnotebook import NotebookTestBase
|
||||
|
||||
|
||||
class KernelAPITest(NotebookTestBase):
|
||||
"""Test the kernels web service API"""
|
||||
|
||||
def _req(self, verb, path, **kwargs):
|
||||
r = self.request(verb, url_path_join('api', path))
|
||||
r.raise_for_status()
|
||||
return r
|
||||
|
||||
def get(self, path, **kwargs):
|
||||
return self._req('GET', path)
|
||||
|
||||
def test_get_spec(self):
|
||||
r = self.get('spec.yaml')
|
||||
assert r.text
|
||||
|
||||
def test_get_status(self):
|
||||
r = self.get('status')
|
||||
data = r.json()
|
||||
assert data['connections'] == 0
|
||||
assert data['kernels'] == 0
|
||||
assert data['last_activity'].endswith('Z')
|
||||
assert data['started'].endswith('Z')
|
||||
assert data['started'] == isoformat(self.notebook.web_app.settings['started'])
|
||||
@ -1,46 +0,0 @@
|
||||
# encoding: utf-8
|
||||
"""
|
||||
Timezone utilities
|
||||
|
||||
Just UTC-awareness right now
|
||||
"""
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Copyright (C) 2013 The IPython Development Team
|
||||
#
|
||||
# Distributed under the terms of the BSD License. The full license is in
|
||||
# the file COPYING, distributed as part of this software.
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Imports
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
from datetime import tzinfo, timedelta, datetime
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Code
|
||||
#-----------------------------------------------------------------------------
|
||||
# constant for zero offset
|
||||
ZERO = timedelta(0)
|
||||
|
||||
class tzUTC(tzinfo):
|
||||
"""tzinfo object for UTC (zero offset)"""
|
||||
|
||||
def utcoffset(self, d):
|
||||
return ZERO
|
||||
|
||||
def dst(self, d):
|
||||
return ZERO
|
||||
|
||||
UTC = tzUTC()
|
||||
|
||||
def utc_aware(unaware):
|
||||
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""
|
||||
def utc_method(*args, **kwargs):
|
||||
dt = unaware(*args, **kwargs)
|
||||
return dt.replace(tzinfo=UTC)
|
||||
return utc_method
|
||||
|
||||
utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
|
||||
utcnow = utc_aware(datetime.utcnow)
|
||||
Loading…
Reference in new issue