






"""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 _a					(						_snake_case				):







      """simple docstring"""






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

def _a					(						):







      """simple docstring"""






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

def _a					(						):







      """simple docstring"""






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

      UpperCAmelCase							     =			"./local/path"
      UpperCAmelCase							     =			extract_path_from_uri(lowercase__				)
      assert dataset_path == new_dataset_path

def _a					(						_snake_case				):







      """simple docstring"""






      UpperCAmelCase							     =			is_remote_filesystem(lowercase__				)
      assert is_remote is True

      UpperCAmelCase							     =			fsspec.filesystem("""file"""				)

      UpperCAmelCase							     =			is_remote_filesystem(lowercase__				)
      assert is_remote is False

@pytest.mark.parametrize("""compression_fs_class""" ,			lowercase__				)
def _a					(						_snake_case ,			_snake_case ,			_snake_case ,			_snake_case ,			_snake_case ,			_snake_case ,			_snake_case				):







      """simple docstring"""






      UpperCAmelCase							     =			{"gzip": gz_file, "xz": xz_file, "zstd": zstd_file, "bz2": bza_file, "lz4": lza_file}
      UpperCAmelCase							     =			input_paths[compression_fs_class.protocol]
      if input_path is None:
            UpperCAmelCase							     =			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(lowercase__				)
      UpperCAmelCase							     =			fsspec.filesystem(compression_fs_class.protocol ,			fo=lowercase__				)
      assert isinstance(lowercase__ ,			lowercase__				)
      UpperCAmelCase							     =			os.path.basename(lowercase__				)
      UpperCAmelCase							     =			expected_filename[: expected_filename.rindex("""."""				)]
      assert fs.glob("""*"""				) == [expected_filename]
      with fs.open(lowercase__ ,			"""r""" ,			encoding="""utf-8"""				) as f, open(lowercase__ ,			encoding="""utf-8"""				) as expected_file:
            assert f.read() == expected_file.read()

@pytest.mark.parametrize("""protocol""" ,			["""zip""", """gzip"""]				)
def _a					(						_snake_case ,			_snake_case ,			_snake_case				):







      """simple docstring"""






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

@pytest.mark.integration
def _a					(						_snake_case ,			_snake_case ,			_snake_case ,			_snake_case				):







      """simple docstring"""






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






def _a					(						):







      """simple docstring"""






      UpperCAmelCase							     =			"bz2"

      # Import module
      import datasets.filesystems

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

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





'''simple docstring'''





def snake_case_     (					lowercase__		):
  return sum(i for i in range(1   ,       number // 2 + 1		) if number % i == 0		) == number


if __name__ == "__main__":
      print("""Program to check whether a number is a Perfect number or not...""")
      SCREAMING_SNAKE_CASE     =       int(input("""Enter number: """).strip())
      print(F'{number} is {"" if perfect(number) else "not "}a Perfect Number.')



