コード例 #1
0
def test_magnitude_too_small():
    install_path, _ = get_config_paths()
    config = queue.get_config(install_path)
    assert queue.magnitude_too_small(2.0, -118.25, 34.0, config) is True
    assert queue.magnitude_too_small(3.6, -118.25, 34.0, config) is False
    assert queue.magnitude_too_small(2.0, -119.25, 35.0, config) is True
    assert queue.magnitude_too_small(3.9, -119.25, 34.6, config) is False
    assert queue.magnitude_too_small(2.0, -129.25, 39.0, config) is True
    assert queue.magnitude_too_small(4.1, -129.25, 39.0, config) is False
コード例 #2
0
def test_get_config():
    install_path, _ = get_config_paths()
    config = queue.get_config(install_path)
    assert len(set(config['servers']) ^ set(['localhost'])) == 0
    assert config['max_process_time'] == 600
    assert config['old_event_age'] == queue.str_to_seconds('1y')
    assert config['future_event_age'] == queue.str_to_seconds('5m')
    assert config['minmag'] == 4.0
    p1 = Polygon([(-116.75, 33.50), (-118.25, 33.50), (-120.25, 34.33),
                  (-120.25, 34.75), (-116.75, 34.75), (-116.75, 33.50)])
    assert config['boxes']['01_my_box']['mag'] == 3.5
    assert config['boxes']['01_my_box']['poly'] == p1
    p2 = Polygon([(-117.75, 34.50), (-119.25, 34.50), (-121.25, 34.33),
                  (-121.25, 34.75), (-117.75, 34.75), (-117.75, 34.50)])
    assert config['boxes']['02_my_box2']['mag'] == 3.8
    assert config['boxes']['02_my_box2']['poly'] == p2
    assert len(set(config['repeats'][0.0]) ^ set([60, 120])) == 0
    assert len(set(config['repeats'][5.0]) ^ set([60, 120, 180])) == 0
コード例 #3
0
def test_send_queue():
    install_path, _ = get_config_paths()
    config = queue.get_config(install_path)
    rsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    rsocket.bind(('', config['port']))
    rsocket.listen(1)

    queue.send_queue('test', {'id': 'testid'}, config['port'])

    (clientsocket, address) = rsocket.accept()
    data = clientsocket.recv(queue.MAX_SIZE)
    clientsocket.close()
    cmd = json.loads(data.decode('utf-8'))
    assert cmd['type'] == 'test'
    assert cmd['data']['id'] == 'testid'

    # Send a too-large data segment
    bigdata = [x for x in range(queue.MAX_SIZE)]
    with pytest.raises(RuntimeError):
        queue.send_queue('test', bigdata)
コード例 #4
0
def test_event_too_old_or_in_future():
    install_path, _ = get_config_paths()
    config = queue.get_config(install_path)
    dt = datetime.utcnow()

    delta = timedelta(days=180)
    dt_past = dt - delta
    event = {'time': dt_past.strftime(constants.TIMEFMT)}
    assert queue.event_too_old_or_in_future(event, config) is False

    delta = timedelta(days=400)
    dt_past = dt - delta
    event = {'time': dt_past.strftime(constants.TIMEFMT)}
    assert queue.event_too_old_or_in_future(event, config) is True

    delta = timedelta(minutes=4)
    dt_future = dt + delta
    event = {'time': dt_future.strftime(constants.TIMEFMT)}
    assert queue.event_too_old_or_in_future(event, config) is False

    delta = timedelta(minutes=10)
    dt_future = dt + delta
    event = {'time': dt_future.strftime(constants.TIMEFMT)}
    assert queue.event_too_old_or_in_future(event, config) is True