Skip to content

Commit

Permalink
Formatting nitpicks
Browse files Browse the repository at this point in the history
  • Loading branch information
encukou committed Mar 21, 2024
1 parent 1e98e35 commit 558f5bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions importlib_resources/functional.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Simplified function-based API for importlib.resources
"""
"""Simplified function-based API for importlib.resources"""

import warnings

Expand All @@ -8,6 +7,7 @@

_MISSING = object()


def open_binary(anchor, *path_names):
"""Open for binary reading the *resource* within *package*."""
return _get_resource(anchor, path_names).open('rb')
Expand Down
20 changes: 13 additions & 7 deletions importlib_resources/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ModuleAnchorMixin:
from . import data02 as anchor02


class FunctionalAPIBase():
class FunctionalAPIBase:
def _gen_resourcetxt_path_parts(self):
"""Yield various names of a text file in anchor02, each in a subTest
"""
Expand Down Expand Up @@ -61,18 +61,21 @@ def test_read_text(self):
resources.read_text(self.anchor01, 'utf-16.file')
self.assertEqual(
resources.read_text(
self.anchor01, 'binary.file', encoding='latin1',
self.anchor01,
'binary.file',
encoding='latin1',
),
'\x00\x01\x02\x03',
)
self.assertEqual(
resources.read_text(
self.anchor01, 'utf-16.file',
self.anchor01,
'utf-16.file',
errors='backslashreplace',
),
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
errors='backslashreplace',
)
),
)

def test_read_binary(self):
Expand Down Expand Up @@ -105,18 +108,21 @@ def test_open_text(self):
with self.assertRaises(UnicodeDecodeError):
f.read()
with resources.open_text(
self.anchor01, 'binary.file', encoding='latin1',
self.anchor01,
'binary.file',
encoding='latin1',
) as f:
self.assertEqual(f.read(), '\x00\x01\x02\x03')
with resources.open_text(
self.anchor01, 'utf-16.file',
self.anchor01,
'utf-16.file',
errors='backslashreplace',
) as f:
self.assertEqual(
f.read(),
'Hello, UTF-16 world!\n'.encode('utf-16').decode(
errors='backslashreplace',
)
),
)

def test_open_binary(self):
Expand Down

0 comments on commit 558f5bf

Please sign in to comment.