<commit_before>import numpy

from glitter import EnumConstant
from glitter.contexts import Context

def check_property(context, name):
    value = getattr(context, name)
    try:
        if isinstance(value, EnumConstant):
            if name in ("draw_buffer", "read_buffer"):
                return # avoid problems with unavailable stereo buffers
            valid_values = value._enum._reverse_dict.values()
            for value in valid_values:
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
        else:
            if type(value) is float:
                value *= 0.5
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
                value += 0.5
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
    except AttributeError:
        pass # "AttributeError: can't set attribute" is okay for read-only attributes

def test_property_generator():
    context = Context()
    properties = [x for x in dir(context) if not x.startswith("_")]

    for p in properties:
        yield check_property, context, p
<commit_msg>fix test_context to use get_current_context<commit_after>import numpy

from glitter import EnumConstant
from glitter.contexts import get_current_context

def check_property(context, name):
    value = getattr(context, name)
    try:
        if isinstance(value, EnumConstant):
            if name in ("draw_buffer", "read_buffer"):
                return # avoid problems with unavailable stereo buffers
            valid_values = value._enum._reverse_dict.values()
            for value in valid_values:
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
        else:
            if type(value) is float:
                value *= 0.5
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
                value += 0.5
                setattr(context, name, value)
                assert numpy.all(getattr(context, name) == value), "property %s is broken" % name
    except AttributeError:
        pass # "AttributeError: can't set attribute" is okay for read-only attributes

def test_property_generator():
    context = get_current_context()
    properties = [x for x in dir(context) if not x.startswith("_")]

    for p in properties:
        yield check_property, context, p

{'fraction_non_alphanumeric': 0.0898876404494382, 'fraction_numerical': 0.00299625468164794, 'mean_word_length': 2.3767383059418457, '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': '4401889', 'n_tokens_mistral': 717, 'n_tokens_neox': 684, 'n_words': 236}