




'''simple docstring'''







import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Value
from datasets.packaged_modules.json.json import Json





@pytest.fixture
def 						snake_case_							(_a     :							List[str]					):
    UpperCAmelCase      	=		tmp_path / '''file.jsonl'''
    UpperCAmelCase      	=		textwrap.dedent(
        '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''					)
    with open(_a   ,       '''w'''					) as f:
        f.write(_a					)
    return str(_a					)





@pytest.fixture
def 						snake_case_							(_a     :							int					):
    UpperCAmelCase      	=		tmp_path / '''file_utf16_encoded.jsonl'''
    UpperCAmelCase      	=		textwrap.dedent(
        '''\
        {"col_1": -1}
        {"col_1": 1, "col_2": 2}
        {"col_1": 10, "col_2": 20}
        '''					)
    with open(_a   ,       '''w'''   ,       encoding='''utf-16'''					) as f:
        f.write(_a					)
    return str(_a					)





@pytest.fixture
def 						snake_case_							(_a     :							List[Any]					):
    UpperCAmelCase      	=		tmp_path / '''file_with_list_of_dicts.json'''
    UpperCAmelCase      	=		textwrap.dedent(
        '''\
        [
            {"col_1": -1},
            {"col_1": 1, "col_2": 2},
            {"col_1": 10, "col_2": 20}
        ]
        '''					)
    with open(_a   ,       '''w'''					) as f:
        f.write(_a					)
    return str(_a					)





@pytest.fixture
def 						snake_case_							(_a     :							Optional[int]					):
    UpperCAmelCase      	=		tmp_path / '''file_with_list_of_dicts_field.json'''
    UpperCAmelCase      	=		textwrap.dedent(
        '''\
        {
            "field1": 1,
            "field2": "aabb",
            "field3": [
                {"col_1": -1},
                {"col_1": 1, "col_2": 2},
                {"col_1": 10, "col_2": 20}
            ]
        }
        '''					)
    with open(_a   ,       '''w'''					) as f:
        f.write(_a					)
    return str(_a					)





@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''   ,       [
        ('''jsonl_file''', {}),
        ('''jsonl_file_utf16_encoded''', {'''encoding''': '''utf-16'''}),
        ('''json_file_with_list_of_dicts''', {}),
        ('''json_file_with_list_of_dicts_field''', {'''field''': '''field3'''}),
    ]   ,       )
def 						snake_case_							(_a     :							str   ,       _a     :							Tuple   ,       _a     :							int					):
    UpperCAmelCase      	=		Json(**_a					)
    UpperCAmelCase      	=		json._generate_tables([[request.getfixturevalue(_a					)]]					)
    UpperCAmelCase      	=		pa.concat_tables([table for _, table in generator]					)
    assert pa_table.to_pydict() == {"col_1": [-1, 1, 1_0], "col_2": [None, 2, 2_0]}







@pytest.mark.parametrize(
    '''file_fixture, config_kwargs'''   ,       [
        (
            '''jsonl_file''',
            {'''features''': Features({'''col_1''': Value('''int64'''					), '''col_2''': Value('''int64'''					), '''missing_col''': Value('''string'''					)}					)},
        ),
        (
            '''json_file_with_list_of_dicts''',
            {'''features''': Features({'''col_1''': Value('''int64'''					), '''col_2''': Value('''int64'''					), '''missing_col''': Value('''string'''					)}					)},
        ),
        (
            '''json_file_with_list_of_dicts_field''',
            {
                '''field''': '''field3''',
                '''features''': Features(
                    {'''col_1''': Value('''int64'''					), '''col_2''': Value('''int64'''					), '''missing_col''': Value('''string'''					)}					),
            },
        ),
    ]   ,       )
def 						snake_case_							(_a     :							Optional[Any]   ,       _a     :							Optional[int]   ,       _a     :							List[str]					):
    UpperCAmelCase      	=		Json(**_a					)
    UpperCAmelCase      	=		json._generate_tables([[request.getfixturevalue(_a					)]]					)
    UpperCAmelCase      	=		pa.concat_tables([table for _, table in generator]					)
    assert pa_table.to_pydict() == {"col_1": [-1, 1, 1_0], "col_2": [None, 2, 2_0], "missing_col": [None, None, None]}










'''simple docstring'''







import unittest

from transformers import is_torch_available, load_tool

from .test_tools_common import ToolTesterMixin


if is_torch_available():
   import torch


class       _a  (     unittest.TestCase							,							__a			):
       def    A				(     self						:     str    ):



           '''simple docstring'''

           UpperCAmelCase      	=		load_tool('''speech-to-text'''    )
           self.tool.setup()
       def    A				(     self						:     Dict    ):



           '''simple docstring'''

           UpperCAmelCase      	=		self.tool(torch.ones(3_000    )    )
           self.assertEqual(lowercase       ,    ''' you'''    )







       def    A				(     self						:     Dict    ):



           '''simple docstring'''

           UpperCAmelCase      	=		self.tool(audio=torch.ones(3_000    )    )
           self.assertEqual(lowercase       ,    ''' you'''    )




