<commit_before>import re

import testil

from corehq.extensions.interface import CommCareExtensions, Extension, ExtensionError
from corehq.util.test_utils import generate_cases

extensions = CommCareExtensions()
extension_point = extensions.extension_point


@extension_point
def ext_point_a(arg1, domain):
    pass


class DemoExtension:
    def __init__(self, mock_calls):
        self.mock_calls = {
            args: response for args, response in mock_calls.items()
        }

    def ext_point_a(self, arg1, domain):
        return self.mock_calls[(arg1, domain)]


demo_extension = DemoExtension({
    (1, "d2"): "p1",
})
ext_point_a.extend(domains=["d2"])(demo_extension.ext_point_a)


@ext_point_a.extend()
def demo_extension_2(arg1, domain):
    if arg1 == 1:
        return "p2"
    else:
        raise Exception


@ext_point_a.extend(domains=["d1"])
def demo_extension_3(**kwargs):
    """test that kwargs style functions are acceptable"""
    return "p3"


def setup():
    extensions.add_extension_points(None)
    extensions.load_extensions(["corehq.extensions.tests"])


def test_commcare_extensions():
    def check(kwargs, expected):
        results = extensions.get_extension_point_contributions("ext_point_a", **kwargs)
        testil.eq(results, expected)

    cases = [
        ({"arg1": 1, "domain": "d1"}, ["p2", "p3"]),
        ({"arg1": 2, "domain": "d1"}, ["p3"]),
        ({"arg1": 1, "domain": "d2"}, ["p1", "p2"]),<commit_msg>remove unneeded call to add_extension_points<commit_after>import re

import testil

from corehq.extensions.interface import CommCareExtensions, Extension, ExtensionError
from corehq.util.test_utils import generate_cases

extensions = CommCareExtensions()
extension_point = extensions.extension_point


@extension_point
def ext_point_a(arg1, domain):
    pass


class DemoExtension:
    def __init__(self, mock_calls):
        self.mock_calls = {
            args: response for args, response in mock_calls.items()
        }

    def ext_point_a(self, arg1, domain):
        return self.mock_calls[(arg1, domain)]


demo_extension = DemoExtension({
    (1, "d2"): "p1",
})
ext_point_a.extend(domains=["d2"])(demo_extension.ext_point_a)


@ext_point_a.extend()
def demo_extension_2(arg1, domain):
    if arg1 == 1:
        return "p2"
    else:
        raise Exception


@ext_point_a.extend(domains=["d1"])
def demo_extension_3(**kwargs):
    """test that kwargs style functions are acceptable"""
    return "p3"


def setup():
    extensions.load_extensions(["corehq.extensions.tests"])


def test_commcare_extensions():
    def check(kwargs, expected):
        results = extensions.get_extension_point_contributions("ext_point_a", **kwargs)
        testil.eq(results, expected)

    cases = [
        ({"arg1": 1, "domain": "d1"}, ["p2", "p3"]),
        ({"arg1": 2, "domain": "d1"}, ["p3"]),
        ({"arg1": 1, "domain": "d2"}, ["p1", "p2"]),
{'fraction_non_alphanumeric': 0.14029644950017237, 'fraction_numerical': 0.01999310582557739, 'mean_word_length': 3.9777015437392795, 'pattern_counts': {'":': 12, '<': 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': '4376216', 'n_tokens_mistral': 983, 'n_tokens_neox': 955, 'n_words': 212}