fsspec 2024.3.0__py3-none-any.whl → 2024.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. fsspec/__init__.py +2 -3
  2. fsspec/_version.py +14 -19
  3. fsspec/caching.py +83 -14
  4. fsspec/compression.py +1 -0
  5. fsspec/core.py +31 -6
  6. fsspec/exceptions.py +1 -0
  7. fsspec/generic.py +1 -1
  8. fsspec/gui.py +1 -1
  9. fsspec/implementations/arrow.py +0 -2
  10. fsspec/implementations/cache_mapper.py +1 -2
  11. fsspec/implementations/cache_metadata.py +7 -7
  12. fsspec/implementations/dirfs.py +2 -2
  13. fsspec/implementations/http.py +9 -9
  14. fsspec/implementations/local.py +97 -48
  15. fsspec/implementations/memory.py +9 -0
  16. fsspec/implementations/smb.py +3 -1
  17. fsspec/implementations/tests/__init__.py +0 -0
  18. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_file_listing.yaml +112 -0
  19. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_mkdir.yaml +582 -0
  20. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_read_pyarrow_non_partitioned.yaml +873 -0
  21. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_read_range.yaml +458 -0
  22. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_read_range_chunked.yaml +1355 -0
  23. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_write_and_read.yaml +795 -0
  24. fsspec/implementations/tests/cassettes/test_dbfs/test_dbfs_write_pyarrow_non_partitioned.yaml +613 -0
  25. fsspec/implementations/tests/conftest.py +39 -0
  26. fsspec/implementations/tests/local/__init__.py +0 -0
  27. fsspec/implementations/tests/local/local_fixtures.py +18 -0
  28. fsspec/implementations/tests/local/local_test.py +14 -0
  29. fsspec/implementations/tests/memory/__init__.py +0 -0
  30. fsspec/implementations/tests/memory/memory_fixtures.py +27 -0
  31. fsspec/implementations/tests/memory/memory_test.py +14 -0
  32. fsspec/implementations/tests/out.zip +0 -0
  33. fsspec/implementations/tests/test_archive.py +382 -0
  34. fsspec/implementations/tests/test_arrow.py +259 -0
  35. fsspec/implementations/tests/test_cached.py +1306 -0
  36. fsspec/implementations/tests/test_common.py +35 -0
  37. fsspec/implementations/tests/test_dask.py +29 -0
  38. fsspec/implementations/tests/test_data.py +20 -0
  39. fsspec/implementations/tests/test_dbfs.py +268 -0
  40. fsspec/implementations/tests/test_dirfs.py +588 -0
  41. fsspec/implementations/tests/test_ftp.py +178 -0
  42. fsspec/implementations/tests/test_git.py +76 -0
  43. fsspec/implementations/tests/test_http.py +577 -0
  44. fsspec/implementations/tests/test_jupyter.py +57 -0
  45. fsspec/implementations/tests/test_libarchive.py +33 -0
  46. fsspec/implementations/tests/test_local.py +1285 -0
  47. fsspec/implementations/tests/test_memory.py +382 -0
  48. fsspec/implementations/tests/test_reference.py +720 -0
  49. fsspec/implementations/tests/test_sftp.py +233 -0
  50. fsspec/implementations/tests/test_smb.py +139 -0
  51. fsspec/implementations/tests/test_tar.py +243 -0
  52. fsspec/implementations/tests/test_webhdfs.py +197 -0
  53. fsspec/implementations/tests/test_zip.py +134 -0
  54. fsspec/implementations/webhdfs.py +1 -3
  55. fsspec/mapping.py +2 -2
  56. fsspec/parquet.py +0 -8
  57. fsspec/registry.py +4 -0
  58. fsspec/spec.py +21 -4
  59. fsspec/tests/__init__.py +0 -0
  60. fsspec/tests/abstract/mv.py +57 -0
  61. fsspec/tests/conftest.py +188 -0
  62. fsspec/tests/data/listing.html +1 -0
  63. fsspec/tests/test_api.py +498 -0
  64. fsspec/tests/test_async.py +230 -0
  65. fsspec/tests/test_caches.py +255 -0
  66. fsspec/tests/test_callbacks.py +89 -0
  67. fsspec/tests/test_compression.py +164 -0
  68. fsspec/tests/test_config.py +129 -0
  69. fsspec/tests/test_core.py +466 -0
  70. fsspec/tests/test_downstream.py +40 -0
  71. fsspec/tests/test_file.py +200 -0
  72. fsspec/tests/test_fuse.py +147 -0
  73. fsspec/tests/test_generic.py +90 -0
  74. fsspec/tests/test_gui.py +23 -0
  75. fsspec/tests/test_mapping.py +228 -0
  76. fsspec/tests/test_parquet.py +140 -0
  77. fsspec/tests/test_registry.py +134 -0
  78. fsspec/tests/test_spec.py +1167 -0
  79. fsspec/tests/test_utils.py +478 -0
  80. fsspec/utils.py +0 -2
  81. fsspec-2024.5.0.dist-info/METADATA +273 -0
  82. fsspec-2024.5.0.dist-info/RECORD +111 -0
  83. {fsspec-2024.3.0.dist-info → fsspec-2024.5.0.dist-info}/WHEEL +1 -2
  84. fsspec-2024.3.0.dist-info/METADATA +0 -167
  85. fsspec-2024.3.0.dist-info/RECORD +0 -54
  86. fsspec-2024.3.0.dist-info/top_level.txt +0 -1
  87. {fsspec-2024.3.0.dist-info → fsspec-2024.5.0.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,134 @@
1
+ import sys
2
+ from importlib.metadata import EntryPoint
3
+ from unittest.mock import create_autospec, patch
4
+
5
+ import pytest
6
+
7
+ import fsspec
8
+ from fsspec.implementations.zip import ZipFileSystem
9
+ from fsspec.registry import (
10
+ _registry,
11
+ filesystem,
12
+ get_filesystem_class,
13
+ known_implementations,
14
+ register_implementation,
15
+ registry,
16
+ )
17
+ from fsspec.spec import AbstractFileSystem
18
+
19
+
20
+ @pytest.fixture()
21
+ def clear_registry():
22
+ try:
23
+ yield
24
+ finally:
25
+ _registry.clear()
26
+ known_implementations.pop("test", None)
27
+
28
+
29
+ @pytest.fixture()
30
+ def clean_imports():
31
+ try:
32
+ real_module = sys.modules["fsspec"]
33
+ del sys.modules["fsspec"]
34
+ yield
35
+ finally:
36
+ sys.modules["fsspec"] = real_module
37
+
38
+
39
+ def test_registry_readonly():
40
+ get_filesystem_class("file")
41
+ assert "file" in registry
42
+ assert "file" in list(registry)
43
+ with pytest.raises(TypeError):
44
+ del registry["file"]
45
+ with pytest.raises(TypeError):
46
+ registry["file"] = None
47
+ with pytest.raises(AttributeError):
48
+ registry.clear()
49
+
50
+
51
+ def test_register_cls(clear_registry):
52
+ with pytest.raises(ValueError):
53
+ get_filesystem_class("test")
54
+ register_implementation("test", AbstractFileSystem)
55
+ cls = get_filesystem_class("test")
56
+ assert cls is AbstractFileSystem
57
+
58
+
59
+ def test_register_str(clear_registry):
60
+ with pytest.raises(ValueError):
61
+ get_filesystem_class("test")
62
+ register_implementation("test", "fsspec.AbstractFileSystem")
63
+ assert "test" not in registry
64
+ cls = get_filesystem_class("test")
65
+ assert cls is AbstractFileSystem
66
+ assert "test" in registry
67
+
68
+
69
+ def test_register_fail(clear_registry):
70
+ register_implementation("test", "doesntexist.AbstractFileSystem")
71
+ with pytest.raises(ImportError):
72
+ get_filesystem_class("test")
73
+
74
+ # NOOP
75
+ register_implementation("test", "doesntexist.AbstractFileSystem", clobber=False)
76
+ with pytest.raises(ValueError):
77
+ register_implementation(
78
+ "test", "doesntexist.AbstractFileSystemm", clobber=False
79
+ )
80
+
81
+ # by default we do not allow clobbering
82
+ with pytest.raises(ValueError):
83
+ register_implementation("test", "doesntexist.AbstractFileSystemm")
84
+
85
+ register_implementation(
86
+ "test", "doesntexist.AbstractFileSystem", errtxt="hiho", clobber=True
87
+ )
88
+ with pytest.raises(ImportError) as e:
89
+ get_filesystem_class("test")
90
+ assert "hiho" in str(e.value)
91
+ register_implementation("test", AbstractFileSystem)
92
+
93
+ # NOOP
94
+ register_implementation("test", AbstractFileSystem)
95
+ with pytest.raises(ValueError):
96
+ register_implementation("test", ZipFileSystem)
97
+ register_implementation("test", AbstractFileSystem, clobber=True)
98
+ assert isinstance(fsspec.filesystem("test"), AbstractFileSystem)
99
+
100
+
101
+ def test_entry_points_registered_on_import(clear_registry, clean_imports):
102
+ mock_ep = create_autospec(EntryPoint, module="fsspec.spec.AbstractFileSystem")
103
+ mock_ep.name = "test" # this can't be set in the constructor...
104
+ mock_ep.value = "fsspec.spec.AbstractFileSystem"
105
+ import_location = "importlib.metadata.entry_points"
106
+ with patch(import_location, return_value={"fsspec.specs": [mock_ep]}):
107
+ assert "test" not in registry
108
+ import fsspec # noqa
109
+
110
+ get_filesystem_class("test")
111
+ assert "test" in registry
112
+
113
+
114
+ def test_filesystem_warning_arrow_hdfs_deprecated(clear_registry, clean_imports):
115
+ mock_ep = create_autospec(EntryPoint, module="fsspec.spec.AbstractFileSystem")
116
+ mock_ep.name = "arrow_hdfs" # this can't be set in the constructor...
117
+ mock_ep.value = "fsspec.spec.AbstractFileSystem"
118
+ import_location = "importlib.metadata.entry_points"
119
+ with patch(import_location, return_value={"fsspec.specs": [mock_ep]}):
120
+ import fsspec # noqa
121
+
122
+ with pytest.warns(DeprecationWarning):
123
+ filesystem("arrow_hdfs")
124
+
125
+
126
+ def test_old_s3(monkeypatch):
127
+ from fsspec.registry import _import_class
128
+
129
+ s3fs = pytest.importorskip("s3fs")
130
+ monkeypatch.setattr(s3fs, "__version__", "0.4.2")
131
+ with pytest.warns():
132
+ _import_class("s3fs:S3FileSystem")
133
+ with pytest.warns():
134
+ _import_class("s3fs.S3FileSystem")