Skip to content

Commit bdccca0

Browse files
Fix linting issues
# Summary This fixes formatting issues identified by the linter. No functional changes are included. # Tests - hatch run lint passes - hatch run test passes (and coverage is sufficient)
1 parent 985cfc0 commit bdccca0

File tree

4 files changed

+80
-34
lines changed

4 files changed

+80
-34
lines changed

frictionless/resource/resource.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,11 @@ def __enter__(self):
273273
274274
would result in errors because the second context would close the file
275275
before the write happened. While the above code is obvious, similar
276-
things can happen when composing steps in pipelines, calling petl code etc.
276+
things can happen when composing steps in pipelines, calling petl code etc.
277277
where the various functions may have no knowledge of each other.
278278
See #1622 for more details.
279279
280-
So we only allow a single context to be open at a time, and raise an
280+
So we only allow a single context to be open at a time, and raise an
281281
exception if nested context is attempted. For similar reasons, we
282282
also raise an exception if a context is attempted on an open resource.
283283
@@ -298,7 +298,7 @@ def __enter__(self):
298298
if self.__context_manager_entered:
299299
note = "Resource has previously entered a context manager (`with` statement) and does not support nested contexts. To use in a nested context use `to_copy()` then use the copy in the `with`."
300300
raise FrictionlessException(note)
301-
if self.closed == False:
301+
if not self.closed:
302302
note = "Resource is currently open, and cannot be used in a `with` statement (which would reopen the file). To use `with` on an open Resouece, use to_copy() then use the copy in the `with`."
303303
raise FrictionlessException(note)
304304

frictionless/validator/validator.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def validate_resource(
138138
errors.append(error)
139139

140140
# Validate file
141-
if not isinstance(resource_copy, platform.frictionless_resources.TableResource):
141+
if not isinstance(
142+
resource_copy, platform.frictionless_resources.TableResource
143+
):
142144
if resource_copy.hash is not None or resource_copy.bytes is not None:
143145
helpers.pass_through(resource_copy.byte_stream)
144146

tests/resource/test_context_manager.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from frictionless import Resource, FrictionlessException
21
import pytest
32

3+
from frictionless import FrictionlessException, Resource
4+
45
# Test that the context manager implementation works correctly
56

67
# As per PEP-343, the context manager should be a single-use object (like files)
@@ -40,38 +41,38 @@ def test_resource_copy_can_use_nested_context():
4041
with Resource("data/table.csv") as resource:
4142
copy = resource.to_copy()
4243
with copy:
43-
assert (copy.closed is False)
44-
assert (resource.closed is False)
44+
assert copy.closed is False
45+
assert resource.closed is False
4546

4647
# Check that the original resource is still open
47-
assert (copy.closed is True)
48-
assert (resource.closed is False)
48+
assert copy.closed is True
49+
assert resource.closed is False
4950

5051

5152
def test_resource_can_use_repeated_non_nested_contexts():
5253
# Repeat context allowed
5354
resource = Resource("data/table.csv")
5455
with resource:
55-
assert (resource.closed is False)
56+
assert resource.closed is False
5657

57-
assert (resource.closed is True)
58+
assert resource.closed is True
5859

5960
with resource:
60-
assert (resource.closed is False)
61-
assert (resource.closed is True)
61+
assert resource.closed is False
62+
assert resource.closed is True
6263

6364

6465
def test_resource_copy_can_use_repeated_context():
6566
# Repeated context with a copy is allowed
6667
resource = Resource("data/table.csv")
6768
copy = resource.to_copy()
6869
with resource:
69-
assert (resource.closed is False)
70-
assert (copy.closed is True)
70+
assert resource.closed is False
71+
assert copy.closed is True
7172

7273
with copy:
73-
assert (resource.closed is True)
74-
assert (copy.closed is False)
74+
assert resource.closed is True
75+
assert copy.closed is False
7576

7677

7778
def test_context_manager_on_open_resource_throw_exception():
@@ -81,7 +82,7 @@ def test_context_manager_on_open_resource_throw_exception():
8182
"""
8283
resource = Resource("data/table.csv")
8384
resource.open()
84-
assert (resource.closed is False)
85+
assert resource.closed is False
8586
with pytest.raises(FrictionlessException):
8687
with resource:
8788
pass
@@ -93,10 +94,10 @@ def test_explicit_open_can_be_repeated():
9394
# using explicit open() calls must be aware of that.
9495
resource = Resource("data/table.csv")
9596
resource.open()
96-
assert (resource.closed is False)
97+
assert resource.closed is False
9798
resource.open()
98-
assert (resource.closed is False)
99+
assert resource.closed is False
99100
resource.close()
100-
assert (resource.closed is True)
101+
assert resource.closed is True
101102
resource.close()
102-
assert (resource.closed is True)
103+
assert resource.closed is True

tests/table/test_to_petl.py

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
from frictionless import Resource, FrictionlessException
21
from petl import util
32

3+
from frictionless.resources import TableResource
4+
45

56
def __assert_nth_row(it, n, expected):
67
"""
78
A helper function to assert that the nth row of an iterator is as expected.
89
"""
9-
for _ in range(n-1):
10+
for _ in range(n - 1):
1011
next(it)
1112
assert next(it) == expected
1213

1314

1415
def test_to_petl_gives_valid_table():
15-
resource = Resource("data/table.csv")
16+
resource = TableResource("data/table.csv")
1617
table = resource.to_petl()
1718
assert util.header(table) == ("id", "name")
1819

1920

2021
def test_to_petl_is_iterable():
21-
resource = Resource("data/table.csv")
22+
resource = TableResource("data/table.csv")
2223
table = resource.to_petl()
2324
it = iter(table)
2425
assert next(it) == ["id", "name"]
@@ -27,7 +28,7 @@ def test_to_petl_is_iterable():
2728

2829

2930
def test_to_petl_iterators_are_independent():
30-
resource = Resource("data/table.csv")
31+
resource = TableResource("data/table.csv")
3132
table = resource.to_petl()
3233
it1 = iter(table)
3334
it2 = iter(table)
@@ -46,7 +47,7 @@ def test_to_petl_iterators_are_independent():
4647

4748

4849
def test_to_petl_iterators_have_independent_lifetime():
49-
resource = Resource("data/table-1MB.csv")
50+
resource = TableResource("data/table-1MB.csv")
5051
table = resource.to_petl()
5152
it1 = iter(table)
5253

@@ -56,19 +57,61 @@ def test_to_petl_iterators_have_independent_lifetime():
5657
# but the buffer is not, so you would get away with incorrectly closing the
5758
# resource if you remain within the buffer).
5859
# See #1622 for more.
59-
__assert_nth_row(it1, 101, [
60-
"ahltic", "22354", "428.17", "382.54", "false", "1926-09-15T01:15:27Z", "1956-04-14", "08:20:13", "4,5", "{\"x\":1,\"y\":7}"])
60+
__assert_nth_row(
61+
it1,
62+
101,
63+
[
64+
"ahltic",
65+
"22354",
66+
"428.17",
67+
"382.54",
68+
"false",
69+
"1926-09-15T01:15:27Z",
70+
"1956-04-14",
71+
"08:20:13",
72+
"4,5",
73+
'{"x":1,"y":7}',
74+
],
75+
)
6176

6277
# Make a local function to give it2 a different scope
6378
def read_from_it2():
6479
it2 = iter(table)
65-
__assert_nth_row(it2, 101, [
66-
"ahltic", "22354", "428.17", "382.54", "false", "1926-09-15T01:15:27Z", "1956-04-14", "08:20:13", "4,5", "{\"x\":1,\"y\":7}"])
80+
__assert_nth_row(
81+
it2,
82+
101,
83+
[
84+
"ahltic",
85+
"22354",
86+
"428.17",
87+
"382.54",
88+
"false",
89+
"1926-09-15T01:15:27Z",
90+
"1956-04-14",
91+
"08:20:13",
92+
"4,5",
93+
'{"x":1,"y":7}',
94+
],
95+
)
6796

6897
# Read from it2 within the nested function scope
6998
read_from_it2()
7099

71100
# Check we can stil read from it1 from where we left off
72101
# Prior to the fix for #1622 this would throw an exception: "ValueError: I/O operation on closed file."
73-
__assert_nth_row(it1, 101, [
74-
"tlbmv8", "91378", "101.19", "832.96", "false", "1983-02-26T12:44:52Z", "1960-08-28", "04:44:23", "5,6", "{\"x\":9,\"y\":4}"])
102+
__assert_nth_row(
103+
it1,
104+
101,
105+
[
106+
"tlbmv8",
107+
"91378",
108+
"101.19",
109+
"832.96",
110+
"false",
111+
"1983-02-26T12:44:52Z",
112+
"1960-08-28",
113+
"04:44:23",
114+
"5,6",
115+
'{"x":9,"y":4}',
116+
],
117+
)

0 commit comments

Comments
 (0)