Skip to content

Commit c228788

Browse files
committed
Using black formatter
1 parent 662e8f3 commit c228788

30 files changed

+1446
-1420
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ insert_final_newline = true
1313
end_of_line = lf
1414
indent_style = space
1515
indent_size = 4
16-
max_line_length = 80
16+
max_line_length = 88

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
2+
13
# zappend
24

3-
Tool to create and update a Zarr dataset from smaller slices
5+
Tool for creating and updating a Zarr dataset from smaller slices
46

57
The objective of **zappend** is to address recurring memory issues when
68
generating large geospatial data cubes using the

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ install_requires =
1414
test =
1515
pytest
1616
pytest-cov
17+
black
18+
flake8
19+
flake8-bugbear
1720

1821
[options.entry_points]
1922
console_scripts =
2023
zappend = zappend.cli:zappend
24+
25+
[flake8]
26+
max-line-length = 88
27+
extend-ignore = E203

tests/fsutil/test_fileobj.py

Lines changed: 43 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,24 @@
1313

1414

1515
class FileObjTest(unittest.TestCase):
16-
1716
def test_str(self):
17+
self.assertEqual("memory://test.zarr", str(FileObj("memory://test.zarr")))
1818
self.assertEqual(
1919
"memory://test.zarr",
20-
str(FileObj("memory://test.zarr"))
21-
)
22-
self.assertEqual(
23-
"memory://test.zarr",
24-
str(FileObj("memory://test.zarr",
25-
storage_options=dict(asynchronous=False)))
20+
str(
21+
FileObj("memory://test.zarr", storage_options=dict(asynchronous=False))
22+
),
2623
)
2724

2825
def test_repr(self):
2926
self.assertEqual(
30-
"FileObj('memory://test.zarr')",
31-
repr(FileObj("memory://test.zarr"))
27+
"FileObj('memory://test.zarr')", repr(FileObj("memory://test.zarr"))
3228
)
3329
self.assertEqual(
34-
"FileObj('memory://test.zarr',"
35-
" storage_options={'asynchronous': False})",
36-
repr(FileObj("memory://test.zarr",
37-
storage_options=dict(asynchronous=False)))
30+
"FileObj('memory://test.zarr'," " storage_options={'asynchronous': False})",
31+
repr(
32+
FileObj("memory://test.zarr", storage_options=dict(asynchronous=False))
33+
),
3834
)
3935

4036
def test_memory_protocol(self):
@@ -51,17 +47,15 @@ def test_file_protocol(self):
5147
self.assertEqual(None, zarr_dir.storage_options)
5248
self.assertIsInstance(zarr_dir.fs, fsspec.AbstractFileSystem)
5349
self.assertEqual("file", to_protocol(zarr_dir.fs))
54-
self.assertEqual(os.path.abspath("test.zarr").replace("\\", "/"),
55-
zarr_dir.path)
50+
self.assertEqual(os.path.abspath("test.zarr").replace("\\", "/"), zarr_dir.path)
5651

5752
def test_local_protocol(self):
5853
zarr_dir = FileObj("test.zarr")
5954
self.assertEqual("test.zarr", zarr_dir.uri)
6055
self.assertEqual(None, zarr_dir.storage_options)
6156
self.assertIsInstance(zarr_dir.fs, fsspec.AbstractFileSystem)
6257
self.assertEqual("file", to_protocol(zarr_dir.fs))
63-
self.assertEqual(os.path.abspath("test.zarr").replace("\\", "/"),
64-
zarr_dir.path)
58+
self.assertEqual(os.path.abspath("test.zarr").replace("\\", "/"), zarr_dir.path)
6559

6660
def test_s3_protocol(self):
6761
zarr_dir = FileObj("s3://eo-data/test.zarr")
@@ -87,19 +81,22 @@ def test_truediv_override(self):
8781
root = FileObj("s3://eo-data/test.zarr")
8882

8983
derived = root / ""
90-
self.assert_derived_ok(root, derived,
91-
"s3://eo-data/test.zarr",
92-
"eo-data/test.zarr")
84+
self.assert_derived_ok(
85+
root, derived, "s3://eo-data/test.zarr", "eo-data/test.zarr"
86+
)
9387

9488
derived = root / ".zgroup"
95-
self.assert_derived_ok(root, derived,
96-
"s3://eo-data/test.zarr/.zgroup",
97-
"eo-data/test.zarr/.zgroup")
89+
self.assert_derived_ok(
90+
root, derived, "s3://eo-data/test.zarr/.zgroup", "eo-data/test.zarr/.zgroup"
91+
)
9892

9993
derived = root / "chl" / ".zarray"
100-
self.assert_derived_ok(root, derived,
101-
"s3://eo-data/test.zarr/chl/.zarray",
102-
"eo-data/test.zarr/chl/.zarray")
94+
self.assert_derived_ok(
95+
root,
96+
derived,
97+
"s3://eo-data/test.zarr/chl/.zarray",
98+
"eo-data/test.zarr/chl/.zarray",
99+
)
103100

104101
def test_parent(self):
105102
file = FileObj("s3://eo-data/test.zarr/.zmetadata")
@@ -123,8 +120,7 @@ def test_parent(self):
123120
self.assertEqual("", parent.path)
124121
self.assertIs(fs, parent.fs)
125122

126-
with pytest.raises(ValueError,
127-
match="cannot get parent of empty path"):
123+
with pytest.raises(ValueError, match="cannot get parent of empty path"):
128124
# noinspection PyUnusedLocal
129125
parent = parent.parent
130126

@@ -134,8 +130,9 @@ def test_parent(self):
134130
parent = file.parent
135131
self.assertIsInstance(parent, FileObj)
136132
self.assertEqual("test.zarr/chl", parent.uri)
137-
self.assertEqual(os.path.abspath("test.zarr/chl").replace("\\", "/"),
138-
parent.path)
133+
self.assertEqual(
134+
os.path.abspath("test.zarr/chl").replace("\\", "/"), parent.path
135+
)
139136
self.assertIs(fs, parent.fs)
140137

141138
def test_parent_with_chained_uri(self):
@@ -153,35 +150,34 @@ def test_parent_with_chained_uri(self):
153150
parent = file.parent
154151
self.assertIsInstance(parent, FileObj)
155152
self.assertEqual("test.zarr/chl::/eo-data/test.zarr", parent.uri)
156-
self.assertEqual(os.path.abspath("test.zarr/chl").replace("\\", "/"),
157-
parent.path)
153+
self.assertEqual(
154+
os.path.abspath("test.zarr/chl").replace("\\", "/"), parent.path
155+
)
158156
self.assertIs(fs, parent.fs)
159157

160158
def test_for_path(self):
161159
root = FileObj("s3://eo-data/test.zarr")
162160

163161
derived = root.for_path("")
164-
self.assert_derived_ok(root, derived,
165-
"s3://eo-data/test.zarr",
166-
"eo-data/test.zarr")
162+
self.assert_derived_ok(
163+
root, derived, "s3://eo-data/test.zarr", "eo-data/test.zarr"
164+
)
167165

168166
derived = root.for_path(".zgroup")
169-
self.assert_derived_ok(root, derived,
170-
"s3://eo-data/test.zarr/.zgroup",
171-
"eo-data/test.zarr/.zgroup")
167+
self.assert_derived_ok(
168+
root, derived, "s3://eo-data/test.zarr/.zgroup", "eo-data/test.zarr/.zgroup"
169+
)
172170

173171
def test_for_path_with_chained_uri(self):
174172
root = FileObj("dir://chl::file:/eo-data/test.zarr")
175173
derived = root.for_path(".zarray")
176-
self.assert_derived_ok(root, derived,
177-
"dir://chl/.zarray::file:/eo-data/test.zarr",
178-
"chl/.zarray")
179-
180-
def assert_derived_ok(self,
181-
root: FileObj,
182-
derived: FileObj,
183-
expected_uri: str,
184-
expected_path: str):
174+
self.assert_derived_ok(
175+
root, derived, "dir://chl/.zarray::file:/eo-data/test.zarr", "chl/.zarray"
176+
)
177+
178+
def assert_derived_ok(
179+
self, root: FileObj, derived: FileObj, expected_uri: str, expected_path: str
180+
):
185181
self.assertEqual(expected_uri, derived.uri)
186182
self.assertEqual(expected_path, derived.path)
187183
self.assertIs(root.fs, derived.fs)

tests/fsutil/test_path.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ def test_empty_path(self):
1818

1919
def test_split_filename_1c(self):
2020
self.assertEqual(("", ""), split_filename("/"))
21-
self.assertEqual(('', 'a'), split_filename("a"))
22-
self.assertEqual(('', 'a'), split_filename("/a"))
23-
self.assertEqual(('a', ''), split_filename("a/"))
24-
self.assertEqual(('/a', ''), split_filename("/a/"))
21+
self.assertEqual(("", "a"), split_filename("a"))
22+
self.assertEqual(("", "a"), split_filename("/a"))
23+
self.assertEqual(("a", ""), split_filename("a/"))
24+
self.assertEqual(("/a", ""), split_filename("/a/"))
2525

2626
def test_split_filename_2c(self):
27-
self.assertEqual(('a', 'b'), split_filename("a/b"))
28-
self.assertEqual(('/a', 'b'), split_filename("/a/b"))
29-
self.assertEqual(('a/b', ''), split_filename("a/b/"))
30-
self.assertEqual(('/a/b', ''), split_filename("/a/b/"))
27+
self.assertEqual(("a", "b"), split_filename("a/b"))
28+
self.assertEqual(("/a", "b"), split_filename("/a/b"))
29+
self.assertEqual(("a/b", ""), split_filename("a/b/"))
30+
self.assertEqual(("/a/b", ""), split_filename("/a/b/"))
3131

3232
def test_split_filename_3c(self):
33-
self.assertEqual(('a/b', 'c'), split_filename("a/b/c"))
34-
self.assertEqual(('/a/b', 'c'), split_filename("/a/b/c"))
35-
self.assertEqual(('a/b/c', ''), split_filename("a/b/c/"))
36-
self.assertEqual(('/a/b/c', ''), split_filename("/a/b/c/"))
33+
self.assertEqual(("a/b", "c"), split_filename("a/b/c"))
34+
self.assertEqual(("/a/b", "c"), split_filename("/a/b/c"))
35+
self.assertEqual(("a/b/c", ""), split_filename("a/b/c/"))
36+
self.assertEqual(("/a/b/c", ""), split_filename("/a/b/c/"))
3737

3838

3939
class SplitComponentsTest(unittest.TestCase):

tests/fsutil/test_transaction.py

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
# noinspection PyShadowingNames
1717
class TransactionTest(unittest.TestCase):
18-
1918
def setUp(self):
2019
clear_memory_fs()
2120

@@ -29,7 +28,6 @@ def test_transaction_failure_without_rollback(self):
2928
self._run_transaction_test(fail=True, rollback=False)
3029

3130
def _run_transaction_test(self, fail: bool, rollback: bool):
32-
3331
test_root = FileObj("memory://test")
3432
test_root.mkdir()
3533
test_file_1 = test_root / "file-1.txt"
@@ -44,8 +42,7 @@ def _run_transaction_test(self, fail: bool, rollback: bool):
4442
self.assertFalse(test_file_3.exists())
4543

4644
temp_dir = FileObj("memory://temp")
47-
transaction = Transaction(test_root, temp_dir,
48-
disable_rollback=not rollback)
45+
transaction = Transaction(test_root, temp_dir, disable_rollback=not rollback)
4946

5047
self.assertEqual(test_root, transaction.target_dir)
5148

@@ -81,16 +78,17 @@ def create_test_folder(rollback_cb: Callable):
8178

8279
if rollback:
8380
rollback_data = rollback_file.read(mode="rt")
84-
rollback_records = [line.split()[:2]
85-
for line in rollback_data.split("\n")]
81+
rollback_records = [
82+
line.split()[:2] for line in rollback_data.split("\n")
83+
]
8684
self.assertEqual(
8785
[
8886
["replace_file", "file-1.txt"],
8987
["delete_file", "file-2.txt"],
9088
["delete_dir", "folder"],
91-
[]
89+
[],
9290
],
93-
rollback_records
91+
rollback_records,
9492
)
9593

9694
if fail:
@@ -129,9 +127,11 @@ def test_it_raises_on_nested_transaction(self):
129127
rollback_dir = FileObj("memory://rollback")
130128
transaction = Transaction(test_root, rollback_dir)
131129
with transaction:
132-
with pytest.raises(ValueError,
133-
match="Transaction instance cannot be"
134-
" used with nested 'with' statements"):
130+
with pytest.raises(
131+
ValueError,
132+
match="Transaction instance cannot be"
133+
" used with nested 'with' statements",
134+
):
135135
with transaction:
136136
pass
137137

@@ -141,8 +141,7 @@ def test_it_raises_on_locked_target(self):
141141
test_root.mkdir()
142142
rollback_dir = FileObj("memory://rollback")
143143
with Transaction(test_root, rollback_dir):
144-
with pytest.raises(OSError,
145-
match="Target is locked: memory:///test.lock"):
144+
with pytest.raises(OSError, match="Target is locked: memory:///test.lock"):
146145
with Transaction(test_root, rollback_dir):
147146
pass
148147

@@ -152,9 +151,10 @@ def test_it_raises_if_not_used_with_with(self):
152151
test_root.mkdir()
153152
rollback_dir = FileObj("memory://rollback")
154153
transaction = Transaction(test_root, rollback_dir)
155-
with pytest.raises(ValueError,
156-
match="Transaction instance must be"
157-
" used with the 'with' statement"):
154+
with pytest.raises(
155+
ValueError,
156+
match="Transaction instance must be" " used with the 'with' statement",
157+
):
158158
transaction._add_rollback_action("delete_file", "path", None)
159159

160160
def test_deletes_lock(self):
@@ -193,40 +193,49 @@ def test_it_raises_on_illegal_callback_calls(self):
193193
test_root = FileObj("memory://test")
194194
test_root.mkdir()
195195
rollback_dir = FileObj("memory://rollback")
196-
with pytest.raises(TypeError,
197-
match="Transaction._add_rollback_action\\(\\)"
198-
" missing 3 required positional arguments:"
199-
" 'action', 'path', and 'data'"):
196+
with pytest.raises(
197+
TypeError,
198+
match="Transaction._add_rollback_action\\(\\)"
199+
" missing 3 required positional arguments:"
200+
" 'action', 'path', and 'data'",
201+
):
200202
with Transaction(test_root, rollback_dir) as callback:
201203
callback()
202204

203-
with pytest.raises(TypeError,
204-
match="Type of 'action' argument must be"
205-
" <class 'str'>, but was <class 'int'>"):
205+
with pytest.raises(
206+
TypeError,
207+
match="Type of 'action' argument must be"
208+
" <class 'str'>, but was <class 'int'>",
209+
):
206210
with Transaction(test_root, rollback_dir) as callback:
207-
callback(42, "I/am/the/path", b'I/m/the/data')
211+
callback(42, "I/am/the/path", b"I/m/the/data")
208212

209-
with pytest.raises(TypeError,
210-
match="Type of 'path' argument must be"
211-
" <class 'str'>, but was <class 'int'>"):
213+
with pytest.raises(
214+
TypeError,
215+
match="Type of 'path' argument must be"
216+
" <class 'str'>, but was <class 'int'>",
217+
):
212218
with Transaction(test_root, rollback_dir) as callback:
213-
callback("replace_file", 13, b'I/m/the/data')
219+
callback("replace_file", 13, b"I/m/the/data")
214220

215-
with pytest.raises(TypeError,
216-
match="Type of 'data' argument must be"
217-
" <class 'bytes'>, but was <class 'int'>"):
221+
with pytest.raises(
222+
TypeError,
223+
match="Type of 'data' argument must be"
224+
" <class 'bytes'>, but was <class 'int'>",
225+
):
218226
with Transaction(test_root, rollback_dir) as callback:
219227
callback("replace_file", "I/am/the/path", 0)
220228

221-
with pytest.raises(ValueError,
222-
match="Value of 'data' argument must be None"):
229+
with pytest.raises(ValueError, match="Value of 'data' argument must be None"):
223230
with Transaction(test_root, rollback_dir) as callback:
224-
callback("delete_file", "I/am/the/path", b'I/m/the/data')
225-
226-
with pytest.raises(ValueError,
227-
match="Value of 'action' argument must be one of"
228-
" 'delete_dir',"
229-
" 'delete_file', 'replace_file',"
230-
" but was 'replace_ifle'"):
231+
callback("delete_file", "I/am/the/path", b"I/m/the/data")
232+
233+
with pytest.raises(
234+
ValueError,
235+
match="Value of 'action' argument must be one of"
236+
" 'delete_dir',"
237+
" 'delete_file', 'replace_file',"
238+
" but was 'replace_ifle'",
239+
):
231240
with Transaction(test_root, rollback_dir) as callback:
232-
callback("replace_ifle", "I/am/the/path", b'I/m/the/data')
241+
callback("replace_ifle", "I/am/the/path", b"I/m/the/data")

0 commit comments

Comments
 (0)