<commit_before># -*- coding: utf-8 -*-

import pytest
import time
import functools
import zmq
import numpy as np
from ..server import Server
from ..throttle import Throttle
from zeeko.conftest import assert_canrecv

@pytest.fixture
def pull(context):
    """Pull socket."""
    socket = context.socket(zmq.PULL)
    yield socket
    socket.close(linger=0)
    
@pytest.fixture
def sub(context):
    """Pull socket."""
    socket = context.socket(zmq.SUB)
    yield socket
    socket.close(linger=0)
    
@pytest.fixture
def arrays(name, n, shape):
    """The arrays to publish."""
    return [("{:s}{:d}".format(name, i), np.random.randn(*shape)) for i in range(n)]

@pytest.fixture
def outbound_address():
    """Return the outbound address."""
    return "inproc://test-outbound"

@pytest.fixture
def server(context, address, arrays):
    """Make a server object."""
    s = Server(context, address)
    s.frequency = 100
    for k, v in arrays:
        s[k] = v
    s.start()
    yield s
    s.stop()

def test_throttle_attributes(context, address, outbound_address):
    """Test client attributes defaults."""
    t = Throttle(context, address, outbound_address)
    assert t.counter == 0
    assert t.wait_time == 0.0
    assert t.counter == 0
    assert t.delay == 0
    assert t.maxlag == 10.0
    t.frequency = 10.0
    assert t.frequency == 10.0
    t.maxlag = 20
    assert t.maxlag == 20.0
    
def test_throttle_noop(context, address, outbound_address, server, sub):
    """Test full throttle"""
    t = Throttle(context, address, outbound_address)
    t.frequency = 10.0
    t.pause()
    try:
        t.start()
    finally:
        t.stop()

def test_throttle(context, address, outbound_address, server, sub):
    """Test full throttle"""
    t = Throttle(context, address, outbound_address)
    t.frequency = 10.0
    t.pause()
    try:
        sub.connect(outbound_address)
        sub.subscribe("")
        t.start()
        time.sleep(0.3)
        assert_canrecv(sub)
        sub.recv_multipart()
    finally:
        t.stop()
    
<commit_msg>Fix the throttle test<commit_after># -*- coding: utf-8 -*-

import pytest
import time
import functools
import zmq
import numpy as np
from ..server import Server
from ..throttle import Throttle
from zeeko.conftest import assert_canrecv

@pytest.fixture
def pull(context):
    """Pull socket."""
    socket = context.socket(zmq.PULL)
    yield socket
    socket.close(linger=0)
    
@pytest.fixture
def sub(context):
    """Pull socket."""
    socket = context.socket(zmq.SUB)
    yield socket
    socket.close(linger=0)
    
@pytest.fixture
def arrays(name, n, shape):
    """The arrays to publish."""
    return [("{:s}{:d}".format(name, i), np.random.randn(*shape)) for i in range(n)]

@pytest.fixture
def outbound_address():
    """Return the outbound address."""
    return "inproc://test-outbound"

@pytest.fixture
def server(context, address, arrays):
    """Make a server object."""
    s = Server(context, address)
    s.frequency = 100
    for k, v in arrays:
        s[k] = v
    s.start()
    yield s
    s.stop()

def test_throttle_attributes(context, address, outbound_address):
    """Test client attributes defaults."""
    t = Throttle(context, address, outbound_address)
    assert t.counter == 0
    assert t.wait_time == 0.0
    assert t.counter == 0
    assert t.delay == 0
    assert t.maxlag == 10.0
    t.frequency = 10.0
    assert t.frequency == 10.0
    t.maxlag = 20
    assert t.maxlag == 20.0
    
def test_throttle_noop(context, address, outbound_address, server, sub):
    """Test full throttle"""
    t = Throttle(context, address, outbound_address)
    t.frequency = 10.0
    t.pause()
    try:
        t.start()
    finally:
        t.stop()

def test_throttle(context, address, outbound_address, server, sub):
    """Test full throttle"""
    t = Throttle(context, address, outbound_address)
    t.frequency = 10.0
    t.pause()
    try:
        sub.connect(outbound_address)
        sub.subscribe("")
        t.start()
        time.sleep((1.0/t.frequency) + 0.1)
        assert_canrecv(sub)
        sub.recv_multipart()
    finally:
        t.stop()
    

{'fraction_non_alphanumeric': 0.13342967244701348, 'fraction_numerical': 0.016377649325626204, 'mean_word_length': 2.8135904499540865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6026843', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1400, 'n_words': 364}