





"""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 				a__      (	_UpperCAmelCase						)     ->	Union[str, Any]:

 '''simple docstring'''






 snake_case__     				=					tmp_path / "file.jsonl"
 snake_case__     				=					textwrap.dedent(
     "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "						)
 with open(_lowercase						,  "w"						) as f:
  f.write(_lowercase						)
 return str(_lowercase						)





@pytest.fixture
def 				a__      (	_UpperCAmelCase						)     ->	Any:

 '''simple docstring'''






 snake_case__     				=					tmp_path / "file_utf16_encoded.jsonl"
 snake_case__     				=					textwrap.dedent(
     "\\n        {\"col_1\": -1}\n        {\"col_1\": 1, \"col_2\": 2}\n        {\"col_1\": 10, \"col_2\": 20}\n        "						)
 with open(_lowercase						,  "w"						,  encoding="utf-16"						) as f:
  f.write(_lowercase						)
 return str(_lowercase						)





@pytest.fixture
def 				a__      (	_UpperCAmelCase						)     ->	Optional[Any]:

 '''simple docstring'''






 snake_case__     				=					tmp_path / "file_with_list_of_dicts.json"
 snake_case__     				=					textwrap.dedent(
     "\\n        [\n            {\"col_1\": -1},\n            {\"col_1\": 1, \"col_2\": 2},\n            {\"col_1\": 10, \"col_2\": 20}\n        ]\n        "						)
 with open(_lowercase						,  "w"						) as f:
  f.write(_lowercase						)
 return str(_lowercase						)





@pytest.fixture
def 				a__      (	_UpperCAmelCase						)     ->	Optional[int]:

 '''simple docstring'''






 snake_case__     				=					tmp_path / "file_with_list_of_dicts_field.json"
 snake_case__     				=					textwrap.dedent(
     "\\n        {\n            \"field1\": 1,\n            \"field2\": \"aabb\",\n            \"field3\": [\n                {\"col_1\": -1},\n                {\"col_1\": 1, \"col_2\": 2},\n                {\"col_1\": 10, \"col_2\": 20}\n            ]\n        }\n        "						)
 with open(_lowercase						,  "w"						) as f:
  f.write(_lowercase						)
 return str(_lowercase						)





@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 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						,  _UpperCAmelCase						)     ->	Optional[int]:

 '''simple docstring'''






 snake_case__     				=					Json(**_lowercase						)
 snake_case__     				=					json._generate_tables([[request.getfixturevalue(_lowercase						)]]						)
 snake_case__     				=					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 				a__      (	_UpperCAmelCase						,  _UpperCAmelCase						,  _UpperCAmelCase						)     ->	int:

 '''simple docstring'''






 snake_case__     				=					Json(**_lowercase						)
 snake_case__     				=					json._generate_tables([[request.getfixturevalue(_lowercase						)]]						)
 snake_case__     				=					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]}









import json

import requests

from .fetch_github_info import AUTHENTICATED_USER_ENDPOINT, fetch_github_info
def 							UpperCAmelCase   ( _lowercase   ):


    '''simple docstring'''



    class        snake_case_				:







       """simple docstring"""



       def __init__(     self:						Tuple ,							snake_case__:						Optional[int]						)	->		None:


           """simple docstring"""



           assert isinstance(snake_case__ ,							(bytes, str)						)
           _lowercase     			=						content

       def       SCREAMING_SNAKE_CASE__					(     self:						Tuple						)	->		str:


           """simple docstring"""



           return json.loads(self.content						)

    def mock_response(*_lowercase,   **_lowercase   ):
        assert args[0] == AUTHENTICATED_USER_ENDPOINT
        assert "Authorization" in kwargs["headers"]
        assert kwargs["headers"]["Authorization"].startswith('token '   )
        assert "Accept" in kwargs["headers"]
        return FakeResponse(b'{"login":"test","id":1}'   )

    monkeypatch.setattr(_lowercase,   'get',   _lowercase   )
    _lowercase     			=						fetch_github_info('token'   )
    assert result["login"] == "test"
    assert result["id"] == 1
