<commit_before>import re
import unittest
from collections import namedtuple, OrderedDict

from model.array import Array
from model.boolean import Boolean
from model.enum import Enum
from model.enum_element import EnumElement
from model.float import Float
from model.function import Function
from model.integer import Integer
from model.param import Param
from model.string import String
from model.struct import Struct
from transformers.functions_producer import FunctionsProducer
from generator import Generator


class TestFunctionsProducer(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None
        Paths = namedtuple('Prop',
                           'enums_package structs_package functions_package request_class response_class '
                           'notification_class')
        paths = Paths(enums_package='com.smartdevicelink.proxy.rpc.enums',
                      structs_package='com.smartdevicelink.proxy.rpc',
                      functions_package='com.smartdevicelink.proxy.rpc',
                      request_class='com.smartdevicelink.proxy.RPCRequest',
                      response_class='com.smartdevicelink.proxy.RPCResponse',
                      notification_class='com.smartdevicelink.proxy.RPCNotification')
        self.expected_template = OrderedDict()
        self.expected_template['package_name'] = 'com.smartdevicelink.proxy.rpc'
        self.expected_template['since'] = None
        self.expected_template['deprecated'] = None
        enum_names = ('FileType', 'Language')
        struct_names = ('SdlMsgVersion', 'TemplateColorScheme', 'TTSChunk', 'Choice')
        keywords = Generator().get_key_words()
        self.producer = FunctionsProducer(paths, enum_names, struct_names, keywords)

    def comparison(self, expected, actual):
        actual_params = dict(zip(map(lambda k: k.title, actual['params']), actual['params']))
        for param in expected['params']:
            for field in self.producer.params._fields:
                self.assertEqual(getattr(param, field), getattr(actual_params[param.title], field, None))
        expected_filtered = dict(filter(lambda e: e[0] != 'params', expected.items()))
        actual_filtered = dict(filter(lambda e: e[0] != 'params', actual.items()))

        self.assertDictEqual(expected_filtered, actual_filtered)

    def test_Version(self):
        version = self.producer.get_version
        self.assertIsNotNone(version)
        self.assertTrue(re.match(r'^\d*\.\d*\.\d*$', version))

    def test_GetVehicleDataResponse(self):
        params = OrderedDict()
        params['speed'] = Param(name='speed', param_type=Float(max_value=700.0, min_value=0.0))
        item = Function(name='GetVehicleData', function_id=None,
                        message_type=EnumElement(name='response'), params=params)
        expected = self.expected_template.copy()
        expected['kind'] = 'response'
        expected['function_id'] = 'GET_VEHICLE_DATA'
        expected['class_name'] = 'GetVehicleDataResponse'
        expected['extends_class'] = 'RPCResponse'
        expected['imports'] = ['androidx.annotation.NonNull', '',
                               'com.smartdevicelink.protocol.enums.FunctionID',
                               'com.smartdevicelink.proxy.RPCResponse',
                               'com.smartdevicelink.proxy.rpc.enums.Result',
                               'com.smartdevicelink.util.SdlDataTypeConverter', '',
                               'java.util.Hashtable']
        expected['params'] = (self.producer.params(deprecated=None, key='KEY_SPEED', description=None,
                                                   last='speed', mandatory=True, SuppressWarnings=None,
                                                   origin='speed', return_type='Float',
                                                   since=None, title='Speed', param_doc=None, name=None),)
        actual = self.producer.transform(item)
        self.comparison(expected, actual)

    def test_RegisterAppInterfaceResponse(self):
        params = OrderedDict()<commit_msg>Fix the broken generator test<commit_after>import re
import unittest
from collections import namedtuple, OrderedDict

from model.array import Array
from model.boolean import Boolean
from model.enum import Enum
from model.enum_element import EnumElement
from model.float import Float
from model.function import Function
from model.integer import Integer
from model.param import Param
from model.string import String
from model.struct import Struct
from transformers.functions_producer import FunctionsProducer
from generator import Generator


class TestFunctionsProducer(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None
        Paths = namedtuple('Prop',
                           'enums_package structs_package functions_package request_class response_class '
                           'notification_class')
        paths = Paths(enums_package='com.smartdevicelink.proxy.rpc.enums',
                      structs_package='com.smartdevicelink.proxy.rpc',
                      functions_package='com.smartdevicelink.proxy.rpc',
                      request_class='com.smartdevicelink.proxy.RPCRequest',
                      response_class='com.smartdevicelink.proxy.RPCResponse',
                      notification_class='com.smartdevicelink.proxy.RPCNotification')
        self.expected_template = OrderedDict()
        self.expected_template['package_name'] = 'com.smartdevicelink.proxy.rpc'
        self.expected_template['since'] = None
        self.expected_template['deprecated'] = None
        enum_names = ('FileType', 'Language')
        struct_names = ('SdlMsgVersion', 'TemplateColorScheme', 'TTSChunk', 'Choice')
        keywords = Generator().get_key_words()
        self.producer = FunctionsProducer(paths, enum_names, struct_names, keywords)

    def comparison(self, expected, actual):
        actual_params = dict(zip(map(lambda k: k.title, actual['params']), actual['params']))
        for param in expected['params']:
            for field in self.producer.params._fields:
                self.assertEqual(getattr(param, field), getattr(actual_params[param.title], field, None))
        expected_filtered = dict(filter(lambda e: e[0] != 'params', expected.items()))
        actual_filtered = dict(filter(lambda e: e[0] != 'params', actual.items()))

        self.assertDictEqual(expected_filtered, actual_filtered)

    def test_Version(self):
        version = self.producer.get_version
        self.assertIsNotNone(version)
        self.assertTrue(re.match(r'^\d*\.\d*\.\d*$', version))

    def test_GetVehicleDataResponse(self):
        params = OrderedDict()
        params['speed'] = Param(name='speed', param_type=Float(max_value=700.0, min_value=0.0))
        item = Function(name='GetVehicleData', function_id=None,
                        message_type=EnumElement(name='response'), params=params)
        expected = self.expected_template.copy()
        expected['kind'] = 'response'
        expected['function_id'] = 'GET_VEHICLE_DATA'
        expected['class_name'] = 'GetVehicleDataResponse'
        expected['extends_class'] = 'RPCResponse'
        expected['history'] = None
        expected['imports'] = ['androidx.annotation.NonNull', '',
                               'com.smartdevicelink.protocol.enums.FunctionID',
                               'com.smartdevicelink.proxy.RPCResponse',
                               'com.smartdevicelink.proxy.rpc.enums.Result',
                               'com.smartdevicelink.util.SdlDataTypeConverter', '',
                               'java.util.Hashtable']
        expected['params'] = (self.producer.params(deprecated=None, key='KEY_SPEED', description=None,
                                                   last='speed', mandatory=True, SuppressWarnings=None,
                                                   origin='speed', return_type='Float',
                                                   since=None, title='Speed', param_doc=None, name=None),)
        actual = self.producer.transform(item)
        self.comparison(expected, actual)

    def test_RegisterAppInterfaceResponse(self):
        params = OrderedDict()
{'fraction_non_alphanumeric': 0.10713851392435851, 'fraction_numerical': 0.0019457618873890308, 'mean_word_length': 2.6293027360988526, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5503467', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2138, 'n_words': 397}