




'''simple docstring'''

import importlib
import os

import fsspec
import pytest
from fsspec import register_implementation
from fsspec.registry import _registry as _fsspec_registry

from datasets.filesystems import COMPRESSION_FILESYSTEMS, HfFileSystem, extract_path_from_uri, is_remote_filesystem

from .utils import require_lza, require_zstandard


def 						__magic_name__       (      __UpperCAmelCase      )						->   Optional[Any]:

					'''simple docstring'''

					assert "mock" in _fsspec_registry
					assert "bz2" in _fsspec_registry


def 						__magic_name__       (      )						->   Optional[int]:

					'''simple docstring'''

					assert "mock" not in _fsspec_registry
					assert "bz2" in _fsspec_registry


def 						__magic_name__       (      )						->   Dict:

					'''simple docstring'''

					snake_case_		     =							'''mock-s3-bucket'''
					snake_case_		     =							F"s3://{mock_bucket}"
					snake_case_		     =							extract_path_from_uri(__UpperCAmelCase      )
					assert dataset_path.startswith('''s3://'''      ) is False

					snake_case_		     =							'''./local/path'''
					snake_case_		     =							extract_path_from_uri(__UpperCAmelCase      )
					assert dataset_path == new_dataset_path


def 						__magic_name__       (      __UpperCAmelCase      )						->   List[Any]:

					'''simple docstring'''

					snake_case_		     =							is_remote_filesystem(__UpperCAmelCase      )
					assert is_remote is True

					snake_case_		     =							fsspec.filesystem('''file'''      )

					snake_case_		     =							is_remote_filesystem(__UpperCAmelCase      )
					assert is_remote is False


@pytest.mark.parametrize('''compression_fs_class''', __UpperCAmelCase      )
def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase      )						->   List[Any]:

					'''simple docstring'''

					snake_case_		     =							{'''gzip''': gz_file, '''xz''': xz_file, '''zstd''': zstd_file, '''bz2''': bza_file, '''lz4''': lza_file}
					snake_case_		     =							input_paths[compression_fs_class.protocol]
					if input_path is None:
										snake_case_		     =							F"for '{compression_fs_class.protocol}' compression protocol, "
										if compression_fs_class.protocol == "lz4":
															reason += require_lza.kwargs["reason"]
										elif compression_fs_class.protocol == "zstd":
															reason += require_zstandard.kwargs["reason"]
										pytest.skip(__UpperCAmelCase      )
					snake_case_		     =							fsspec.filesystem(compression_fs_class.protocol, fo=__UpperCAmelCase      )
					assert isinstance(__UpperCAmelCase, __UpperCAmelCase      )
					snake_case_		     =							os.path.basename(__UpperCAmelCase      )
					snake_case_		     =							expected_filename[: expected_filename.rindex('''.'''      )]
					assert fs.glob('''*'''      ) == [expected_filename]
					with fs.open(__UpperCAmelCase, '''r''', encoding='''utf-8'''      ) as f, open(__UpperCAmelCase, encoding='''utf-8'''      ) as expected_file:
										assert f.read() == expected_file.read()


@pytest.mark.parametrize('''protocol''', ['''zip''', '''gzip''']      )
def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase      )						->   Tuple:

					'''simple docstring'''

					snake_case_		     =							{'''zip''': zip_jsonl_path, '''gzip''': jsonl_gz_path}
					snake_case_		     =							compressed_file_paths[protocol]
					snake_case_		     =							'''dataset.jsonl'''
					snake_case_		     =							F"{protocol}://{member_file_path}::{compressed_file_path}"
					snake_case_     ,*snake_case_		     =							fsspec.get_fs_token_paths(__UpperCAmelCase      )
					assert fs.isfile(__UpperCAmelCase      )
					assert not fs.isfile('''non_existing_''' + member_file_path      )


@pytest.mark.integration
def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase, __UpperCAmelCase      )						->   Union[str, Any]:

					'''simple docstring'''

					snake_case_		     =							hf_api.dataset_info(__UpperCAmelCase, token=__UpperCAmelCase      )
					snake_case_		     =							HfFileSystem(repo_info=__UpperCAmelCase, token=__UpperCAmelCase      )
					assert sorted(hffs.glob('''*'''      )      ) == [".gitattributes", "data"]
					assert hffs.isdir('''data'''      )
					assert hffs.isfile('''.gitattributes'''      ) and hffs.isfile('''data/text_data.txt'''      )
					with open(__UpperCAmelCase      ) as f:
										assert hffs.open('''data/text_data.txt''', '''r'''      ).read() == f.read()


def 						__magic_name__       (      )						->   Optional[Any]:

					'''simple docstring'''

					snake_case_		     =							'''bz2'''

					# Import module
					import datasets.filesystems

					# Overwrite protocol and reload
					register_implementation(__UpperCAmelCase, __UpperCAmelCase, clobber=__UpperCAmelCase      )
					with pytest.warns(__UpperCAmelCase      ) as warning_info:
										importlib.reload(datasets.filesystems      )

					assert len(__UpperCAmelCase      ) == 1
					assert (
					    str(warning_info[0].message      )
					    == F"A filesystem protocol was already set for {protocol} and will be overwritten."
					)







'''simple docstring'''

def 						__magic_name__       (      __UpperCAmelCase, __UpperCAmelCase      )						->   int:

					'''simple docstring'''

					return int((input_a, input_a).count(0      ) == 0      )


def 						__magic_name__       (      )						->   None:

					'''simple docstring'''

					assert and_gate(0, 0      ) == 0
					assert and_gate(0, 1      ) == 0
					assert and_gate(1, 0      ) == 0
					assert and_gate(1, 1      ) == 1


if __name__ == "__main__":
							test_and_gate()
							print(and_gate(1, 0))
							print(and_gate(0, 0))
							print(and_gate(0, 1))
							print(and_gate(1, 1))

