Skip to content

Commit

Permalink
Updates after dropping Python 3.6 and 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jul 22, 2023
1 parent 405c8b6 commit c142a5f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 50 deletions.
5 changes: 2 additions & 3 deletions src/briefcase/integrations/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ def install(self):

with self.tools.input.wait_bar("Installing OpenJDK..."):
try:
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
self.tools.shutil.unpack_archive(
os.fsdecode(jdk_zip_path),
extract_dir=os.fsdecode(self.tools.base_path),
str(jdk_zip_path),
extract_dir=str(self.tools.base_path),
)
except (shutil.ReadError, EOFError) as e:
raise BriefcaseCommandError(
Expand Down
6 changes: 2 additions & 4 deletions src/briefcase/integrations/wix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
import shutil
from pathlib import Path

Expand Down Expand Up @@ -138,10 +137,9 @@ def install(self):

try:
with self.tools.input.wait_bar("Installing WiX..."):
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
self.tools.shutil.unpack_archive(
os.fsdecode(wix_zip_path),
extract_dir=os.fsdecode(self.wix_home),
str(wix_zip_path),
extract_dir=str(self.wix_home),
)
except (shutil.ReadError, EOFError) as e:
raise BriefcaseCommandError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def test_existing_skin(mock_tools, android_sdk):

def test_new_skin(mock_tools, android_sdk):
"""If the skin doesn't exist, an attempt is made to download it."""
# MagicMock below py3.8 doesn't have __fspath__ attribute.
# Remove if block when we drop py3.7 support.
skin_tgz_path = MagicMock(spec_set=Path)
skin_tgz_path.__fspath__.return_value = "/path/to/skin.tgz"
mock_tools.download.file.return_value = skin_tgz_path
Expand Down Expand Up @@ -50,8 +48,6 @@ def test_new_skin(mock_tools, android_sdk):

def test_skin_download_failure(mock_tools, android_sdk, tmp_path):
"""If the skin download fails, an error is raised."""
# MagicMock below py3.8 doesn't have __fspath__ attribute.
# Remove if block when we drop py3.7 support.
skin_tgz_path = MagicMock(spec_set=Path)
skin_tgz_path.__fspath__.return_value = "/path/to/skin.tgz"
mock_tools.download.file.return_value = skin_tgz_path
Expand Down Expand Up @@ -79,8 +75,6 @@ def test_skin_download_failure(mock_tools, android_sdk, tmp_path):
def test_unpack_failure(mock_tools, android_sdk, tmp_path):
"""If the download is corrupted and unpacking fails, an error is raised."""
# Mock the result of the download of a skin
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
skin_tgz_path = MagicMock(spec_set=Path)
skin_tgz_path.__fspath__.return_value = "/path/to/skin.tgz"
mock_tools.download.file.return_value = skin_tgz_path
Expand Down
19 changes: 6 additions & 13 deletions tests/integrations/java/test_JDK__upgrade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import shutil
from unittest.mock import MagicMock

Expand Down Expand Up @@ -60,10 +59,9 @@ def rmtree(path):
mock_tools.shutil.rmtree.side_effect = rmtree

# Mock the cached download path.
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
archive = MagicMock()
archive.__fspath__.return_value = "/path/to/download.zip"
archive.__str__.return_value = "/path/to/download.zip"
mock_tools.download.file.return_value = archive

# Create a directory to make it look like Java was downloaded and unpacked.
Expand All @@ -87,9 +85,8 @@ def rmtree(path):
)

# The archive was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
"/path/to/download.zip", extract_dir=os.fsdecode(tmp_path / "tools")
"/path/to/download.zip", extract_dir=str(tmp_path / "tools")
)
# The original archive was deleted
archive.unlink.assert_called_once_with()
Expand All @@ -112,10 +109,9 @@ def rmtree(path):
mock_tools.shutil.rmtree.side_effect = rmtree

# Mock the cached download path.
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
archive = MagicMock()
archive.__fspath__.return_value = "/path/to/download.zip"
archive.__str__.return_value = "/path/to/download.zip"
mock_tools.download.file.return_value = archive

# Create a directory to make it look like Java was downloaded and unpacked.
Expand All @@ -139,10 +135,9 @@ def rmtree(path):
)

# The archive was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
"/path/to/download.zip",
extract_dir=os.fsdecode(tmp_path / "tools"),
extract_dir=str(tmp_path / "tools"),
)
# The original archive was deleted
archive.unlink.assert_called_once_with()
Expand Down Expand Up @@ -198,10 +193,9 @@ def rmtree(path):
mock_tools.shutil.rmtree.side_effect = rmtree

# Mock the cached download path
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
archive = MagicMock()
archive.__fspath__.return_value = "/path/to/download.zip"
archive.__str__.return_value = "/path/to/download.zip"
mock_tools.download.file.return_value = archive

# Mock an unpack failure due to an invalid archive
Expand All @@ -226,10 +220,9 @@ def rmtree(path):
)

# The archive was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
"/path/to/download.zip",
extract_dir=os.fsdecode(tmp_path / "tools"),
extract_dir=str(tmp_path / "tools"),
)
# The original archive was not deleted
assert archive.unlink.call_count == 0
12 changes: 4 additions & 8 deletions tests/integrations/java/test_JDK__verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,9 @@ def test_successful_jdk_download(
mock_tools.os.environ = {"JAVA_HOME": "/does/not/exist"}

# Mock the cached download path
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
archive = mock.MagicMock()
archive.__fspath__.return_value = "/path/to/download.zip"
archive.__str__.return_value = "/path/to/download.zip"
mock_tools.download.file.return_value = archive

# Create a directory to make it look like Java was downloaded and unpacked.
Expand All @@ -477,9 +476,8 @@ def test_successful_jdk_download(
role="Java 17 JDK",
)
# The archive was unpacked
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
"/path/to/download.zip", extract_dir=os.fsdecode(tmp_path / "tools")
"/path/to/download.zip", extract_dir=str(tmp_path / "tools")
)
# The original archive was deleted
archive.unlink.assert_called_once_with()
Expand Down Expand Up @@ -529,10 +527,9 @@ def test_invalid_jdk_archive(mock_tools, tmp_path):
mock_tools.host_arch = "x86_64"

# Mock the cached download path
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
archive = mock.MagicMock()
archive.__fspath__.return_value = "/path/to/download.zip"
archive.__str__.return_value = "/path/to/download.zip"
mock_tools.download.file.return_value = archive

# Mock an unpack failure due to an invalid archive
Expand All @@ -549,10 +546,9 @@ def test_invalid_jdk_archive(mock_tools, tmp_path):
role="Java 17 JDK",
)
# An attempt was made to unpack the archive.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
"/path/to/download.zip",
extract_dir=os.fsdecode(tmp_path / "tools"),
extract_dir=str(tmp_path / "tools"),
)
# The original archive was not deleted
assert archive.unlink.call_count == 0
12 changes: 4 additions & 8 deletions tests/integrations/wix/test_WiX__upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ def test_existing_wix_install(mock_tools, tmp_path):
wix_path = tmp_path / "tools" / "wix"

wix_zip_path = os.fsdecode(tmp_path / "tools" / "wix.zip")
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
wix_zip = MagicMock()
wix_zip.__fspath__.return_value = wix_zip_path
wix_zip.__str__.return_value = wix_zip_path

mock_tools.download.file.return_value = wix_zip

Expand All @@ -75,9 +74,8 @@ def test_existing_wix_install(mock_tools, tmp_path):
)

# The download was unpacked
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
os.fsdecode(wix_zip_path), extract_dir=os.fsdecode(wix_path)
str(wix_zip_path), extract_dir=str(wix_path)
)

# The zip file was removed
Expand Down Expand Up @@ -125,10 +123,9 @@ def test_unpack_fail(mock_tools, tmp_path):

# Mock the download
wix_zip_path = os.fsdecode(tmp_path / "tools" / "wix.zip")
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
wix_zip = MagicMock()
wix_zip.__fspath__.return_value = wix_zip_path
wix_zip.__str__.return_value = wix_zip_path

mock_tools.download.file.return_value = wix_zip

Expand All @@ -151,9 +148,8 @@ def test_unpack_fail(mock_tools, tmp_path):
)

# The download was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
os.fsdecode(wix_zip_path), extract_dir=os.fsdecode(wix_path)
str(wix_zip_path), extract_dir=str(wix_path)
)

# The zip file was not removed
Expand Down
12 changes: 4 additions & 8 deletions tests/integrations/wix/test_WiX__verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ def test_download_wix(mock_tools, tmp_path):
wix_path = tmp_path / "tools" / "wix"

wix_zip_path = os.fsdecode(tmp_path / "tools" / "wix.zip")
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
wix_zip = MagicMock()
wix_zip.__fspath__.return_value = wix_zip_path
wix_zip.__str__.return_value = wix_zip_path

mock_tools.download.file.return_value = wix_zip

Expand All @@ -125,9 +124,8 @@ def test_download_wix(mock_tools, tmp_path):
)

# The download was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
os.fsdecode(wix_zip_path), extract_dir=os.fsdecode(wix_path)
str(wix_zip_path), extract_dir=str(wix_path)
)

# The zip file was removed
Expand Down Expand Up @@ -191,10 +189,9 @@ def test_unpack_fail(mock_tools, tmp_path):
wix_path = tmp_path / "tools" / "wix"

wix_zip_path = os.fsdecode(tmp_path / "tools" / "wix.zip")
# Consider to remove if block when we drop py3.7 support, only keep statements from else.
# MagicMock below py3.8 doesn't have __fspath__ attribute.
wix_zip = MagicMock()
wix_zip.__fspath__.return_value = wix_zip_path
wix_zip.__str__.return_value = wix_zip_path

mock_tools.download.file.return_value = wix_zip

Expand All @@ -217,9 +214,8 @@ def test_unpack_fail(mock_tools, tmp_path):
)

# The download was unpacked.
# TODO: Py3.6 compatibility; os.fsdecode not required in Py3.7
mock_tools.shutil.unpack_archive.assert_called_with(
os.fsdecode(wix_zip_path), extract_dir=os.fsdecode(wix_path)
str(wix_zip_path), extract_dir=str(wix_path)
)

# The zip file was not removed
Expand Down

0 comments on commit c142a5f

Please sign in to comment.