Skip to content

Commit

Permalink
fix: specify encoding during .unpack() (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jun 12, 2024
1 parent 209099e commit 77de2d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ethpm_types/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def unpack_sources(self, destination: Path):
# Create nested directories as needed.
source_path.parent.mkdir(parents=True, exist_ok=True)

source_path.write_text(content)
source_path.write_text(content, encoding="utf8")

def get_compiler(self, name: str, version: str) -> Optional[Compiler]:
"""
Expand Down
11 changes: 6 additions & 5 deletions tests/test_package_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,21 +153,22 @@ def test_get_contract_type(package_manifest, solidity_contract):


def test_unpack_sources():
foo_txt = Content(root={0: "line 0 in foo.txt"})
baz_txt = Content(root={1: "line 1 in baz.txt"})
# NOTE: Purposely using extra utf-8 symbol `“` as an encoding test.
foo_txt = Content(root={0: "line “0“ in foo.txt"})
baz_txt = Content(root={1: "line “1“ in baz.txt"})
sources = {"foo.txt": Source(content=foo_txt), "bar/nested/baz.txt": Source(content=baz_txt)}
manifest = PackageManifest(sources=sources)

with tempfile.TemporaryDirectory() as temp_dir:
destination = Path(temp_dir) / "src"
destination = Path(temp_dir).resolve() / "src"
manifest.unpack_sources(destination)
foo_expected = destination / "foo.txt"
baz_expected = destination / "bar" / "nested" / "baz.txt"

assert foo_expected.is_file()
assert baz_expected.is_file()
assert foo_expected.read_text() == str(foo_txt)
assert baz_expected.read_text() == str(baz_txt)
assert foo_expected.read_text(encoding="utf8") == str(foo_txt)
assert baz_expected.read_text(encoding="utf8") == str(baz_txt)


def test_package_name_name():
Expand Down

0 comments on commit 77de2d8

Please sign in to comment.