
'''simple docstring'''





# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


a__		: Optional[int]  							=							{
    "configuration_convnextv2": [
        "CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "ConvNextV2Config",
    ]
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a__		: Tuple  							=							[
     "CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST",
     "ConvNextV2ForImageClassification",
     "ConvNextV2Model",
     "ConvNextV2PreTrainedModel",
     "ConvNextV2Backbone",
 ]


if TYPE_CHECKING:
 from .configuration_convnextva import (
     CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
     ConvNextVaConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_convnextva import (
      CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
      ConvNextVaBackbone,
      ConvNextVaForImageClassification,
      ConvNextVaModel,
      ConvNextVaPreTrainedModel,
  )

else:
 import sys

 a__		: int  							=							_LazyModule(__name__, globals()["__file__"], _import_structure)














import textwrap

import pyarrow as pa
import pytest

from datasets import Features, Image
from datasets.packaged_modules.text.text import Text

from ..utils import require_pil






@pytest.fixture
def    UpperCamelCase__  (   UpperCAmelCase     )     ->		Union[str, Any]:







							"""simple docstring"""





							_a  :    Tuple			=						tmp_path / '''text.txt'''
							_a  :    Dict			=						textwrap.dedent(
							    '''\
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

        Second paragraph:
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
        Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
        Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        '''     )
							with open(UpperCAmelCase    ,	'''w'''    ,	encoding='''utf-8'''     ) as f:
														f.write(UpperCAmelCase     )
							return str(UpperCAmelCase     )






@pytest.fixture
def    UpperCamelCase__  (   UpperCAmelCase    ,	UpperCAmelCase     )     ->		Optional[int]:







							"""simple docstring"""





							_a  :    List[Any]			=						tmp_path / '''text_with_image.txt'''
							with open(UpperCAmelCase    ,	'''w'''    ,	encoding='''utf-8'''     ) as f:
														f.write(UpperCAmelCase     )
							return str(UpperCAmelCase     )






@pytest.mark.parametrize('''keep_linebreaks'''    ,	[True, False]     )
def    UpperCamelCase__  (   UpperCAmelCase    ,	UpperCAmelCase     )     ->		Any:







							"""simple docstring"""





							with open(UpperCAmelCase    ,	encoding='''utf-8'''     ) as f:
														_a  :    str			=						f.read().splitlines(keepends=UpperCAmelCase     )
							_a  :    Tuple			=						Text(keep_linebreaks=UpperCAmelCase    ,	encoding='''utf-8'''     )
							_a  :    Optional[Any]			=						text._generate_tables([[text_file]]     )
							_a  :    str			=						pa.concat_tables([table for _, table in generator]     ).to_pydict()['''text''']
							assert generated_content == expected_content






@require_pil
def    UpperCamelCase__  (   UpperCAmelCase     )     ->		List[str]:







							"""simple docstring"""





							with open(UpperCAmelCase    ,	encoding='''utf-8'''     ) as f:
														_a  :    str			=						f.read().splitlines()[0]
							_a  :    Dict			=						Text(encoding='''utf-8'''    ,	features=Features({'''image''': Image()}     )     )
							_a  :    str			=						text._generate_tables([[text_file_with_image]]     )
							_a  :    int			=						pa.concat_tables([table for _, table in generator]     )
							assert pa_table.schema.field('''image'''     ).type == Image()()
							_a  :    Optional[int]			=						pa_table.to_pydict()['''image''']
							assert generated_content == [{"path": image_file, "bytes": None}]







@pytest.mark.parametrize('''sample_by'''    ,	['''line''', '''paragraph''', '''document''']     )
def    UpperCamelCase__  (   UpperCAmelCase    ,	UpperCAmelCase     )     ->		Optional[Any]:







							"""simple docstring"""





							with open(UpperCAmelCase    ,	encoding='''utf-8'''     ) as f:
														_a  :    Any			=						f.read()
							if sample_by == "line":
														_a  :    Any			=						expected_content.splitlines()
							elif sample_by == "paragraph":
														_a  :    Tuple			=						expected_content.split('''\n\n'''     )
							elif sample_by == "document":
														_a  :    Dict			=						[expected_content]
							_a  :    Dict			=						Text(sample_by=UpperCAmelCase    ,	encoding='''utf-8'''    ,	chunksize=100     )
							_a  :    Optional[int]			=						text._generate_tables([[text_file]]     )
							_a  :    List[Any]			=						pa.concat_tables([table for _, table in generator]     ).to_pydict()['''text''']
							assert generated_content == expected_content