def test_timestamp_from_isodate(): ts = timestamp_from_isodate('2009-06-09T10:57:00') assert (1244537820.0 - 14 * 3600) < ts < (1244537820.0 + 14 * 3600) try: timestamp_from_isodate('2009-06-09T10:57') except ValueError: pass else: assert False, 'expected ValueError'
def before_timestamp_from_options(conf): """ >>> import time >>> t = before_timestamp_from_options({'hours': 4}) >>> time.time() - t - 4 * 60 * 60 < 1 True """ if 'time' in conf: try: return timestamp_from_isodate(conf['time']) except ValueError: raise SeedConfigurationError( "can't parse time '%s'. should be ISO time string" % (conf["time"], )) if 'mtime' in conf: datasource = abspath(conf['mtime']) try: return os.path.getmtime(datasource) except OSError as ex: raise SeedConfigurationError( "can't parse last modified time from file '%s'." % (datasource, ), ex) deltas = {} for delta_type in ('weeks', 'days', 'hours', 'minutes', 'seconds'): deltas[delta_type] = conf.get(delta_type, 0) return timestamp_before(**deltas)
def before_timestamp_from_options(conf): """ >>> import time >>> t = before_timestamp_from_options({'hours': 4}) >>> time.time() - t - 4 * 60 * 60 < 1 True """ if 'time' in conf: try: return timestamp_from_isodate(conf['time']) except ValueError: raise SeedConfigurationError( "can't parse time '%s'. should be ISO time string" % (conf["time"], )) if 'mtime' in conf: datasource = abspath(conf['mtime']) try: return os.path.getmtime(datasource) except OSError, ex: raise SeedConfigurationError( "can't parse last modified time from file '%s'." % (datasource, ), ex)
def test_refresh_tile_mtime(self, app, cache_dir): with tmp_image((256, 256), format="jpeg") as img: expected_req = ( { "path": r"/service?LAYERs=bar&SERVICE=WMS&FORMAT=image%2Fjpeg" "&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A900913&styles=" "&VERSION=1.1.1&BBOX=-20037508.3428,-20037508.3428,0.0,0.0" "&WIDTH=256" }, { "body": img.read(), "headers": { "content-type": "image/jpeg" } }, ) with mock_httpd(("localhost", 42423), [expected_req], bbox_aware_query_comparator=True): resp = app.get("/tiles/wms_cache_isotime/1/0/0.jpeg") assert resp.content_type == "image/jpeg" file_path = cache_dir.join( "wms_cache_isotime_EPSG900913/01/000/000/000/000/000/000.jpeg" ) assert file_path.check() timestamp = timestamp_from_isodate("2009-02-15T23:31:30") file_path.setmtime(timestamp + 1.2) t1 = file_path.mtime() resp = app.get("/tiles/wms_cache_isotime/1/0/0.jpeg") assert resp.content_type == "image/jpeg" t2 = file_path.mtime() file_path.setmtime(timestamp - 1.2) with mock_httpd(("localhost", 42423), [expected_req], bbox_aware_query_comparator=True): resp = app.get("/tiles/wms_cache_isotime/1/0/0.jpeg") assert resp.content_type == "image/jpeg" assert file_path.check() t3 = file_path.mtime() assert t2 == t1 assert t3 > t2
def test_timestamp_from_isodate(): ts = timestamp_from_isodate("2009-06-09T10:57:00") assert (1244537820.0 - 14 * 3600) < ts < (1244537820.0 + 14 * 3600) with pytest.raises(ValueError): timestamp_from_isodate("2009-06-09T10:57")