Skip to content

Commit

Permalink
More mocks missed
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-O committed Aug 27, 2023
1 parent 1fddf4b commit 52ef3f6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
21 changes: 12 additions & 9 deletions tests/targets/test_android.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
init_buildozer,
patch_buildozer,
patch_buildops_checkbin,
patch_buildozer_cmd,
patch_buildops_cmd,
patch_buildops_file_exists,
)

Expand Down Expand Up @@ -131,14 +131,14 @@ def test_sdkmanager(self):
"""Tests the _sdkmanager() method."""
target_android = init_target(self.temp_dir)
kwargs = {}
with patch_buildozer_cmd() as m_cmd, patch_buildozer_cmd_expect() as m_cmd_expect, patch_os_isfile() as m_isfile:
with patch_buildops_cmd() as m_cmd, patch_buildozer_cmd_expect() as m_cmd_expect, patch_os_isfile() as m_isfile:
m_isfile.return_value = True
assert m_cmd.return_value == target_android._sdkmanager(**kwargs)
assert m_cmd.call_count == 1
assert m_cmd_expect.call_count == 0
assert m_isfile.call_count == 1
kwargs = {"return_child": True}
with patch_buildozer_cmd() as m_cmd, patch_buildozer_cmd_expect() as m_cmd_expect, patch_os_isfile() as m_isfile:
with patch_buildops_cmd() as m_cmd, patch_buildozer_cmd_expect() as m_cmd_expect, patch_os_isfile() as m_isfile:
m_isfile.return_value = True
assert m_cmd_expect.return_value == target_android._sdkmanager(
**kwargs
Expand Down Expand Up @@ -429,39 +429,42 @@ def test_install_platform_p4a_clone_url(self):
'p4a.fork': 'myfork',
})

with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
with patch_buildops_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()

assert mock.call(
["git", "clone", "-b", "master", "--single-branch", "https://custom-p4a-url/p4a.git", "python-for-android"],
cwd=mock.ANY) in m_cmd.call_args_list
cwd=mock.ANY,
env=mock.ANY) in m_cmd.call_args_list

def test_install_platform_p4a_clone_fork(self):
"""The `p4a.fork` config should be used for cloning p4a."""
target_android = init_target(self.temp_dir, {
'p4a.fork': 'fork'
})

with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
with patch_buildops_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()

assert mock.call(
["git", "clone", "-b", "master", "--single-branch", "https://github.com/fork/python-for-android.git", "python-for-android"],
cwd=mock.ANY) in m_cmd.call_args_list
cwd=mock.ANY,
env=mock.ANY) in m_cmd.call_args_list

def test_install_platform_p4a_clone_default(self):
"""The default URL should be used for cloning p4a if no config options `p4a.url` and `p4a.fork` are set."""
target_android = init_target(self.temp_dir)

with patch_buildozer_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
with patch_buildops_cmd() as m_cmd, mock.patch('buildozer.targets.android.open') as m_open:
m_open.return_value = StringIO('install_reqs = []') # to stub setup.py parsing
target_android._install_p4a()

assert mock.call(
["git", "clone", "-b", "master", "--single-branch", "https://github.com/kivy/python-for-android.git", "python-for-android"],
cwd=mock.ANY) in m_cmd.call_args_list
cwd=mock.ANY,
env=mock.ANY) in m_cmd.call_args_list

def test_orientation(self):
target_android = init_target(self.temp_dir, {
Expand Down
11 changes: 7 additions & 4 deletions tests/targets/test_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tests.targets.utils import (
init_buildozer,
patch_buildops_checkbin,
patch_buildozer_cmd,
patch_buildops_cmd,
patch_buildops_file_exists,
patch_logger_error,
)
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_install_platform(self):
target = init_target(self.temp_dir)
assert target.ios_dir is None
assert target.ios_deploy_dir is None
with patch_buildozer_cmd() as m_cmd:
with patch_buildops_cmd() as m_cmd:
target.install_platform()
assert m_cmd.call_args_list == [
mock.call(
Expand All @@ -124,6 +124,7 @@ def test_install_platform(self):
"https://github.com/kivy/kivy-ios",
],
cwd=mock.ANY,
env=mock.ANY,
),
mock.call(
[
Expand All @@ -134,6 +135,7 @@ def test_install_platform(self):
"https://github.com/phonegap/ios-deploy",
],
cwd=mock.ANY,
env=mock.ANY,
),
]
assert target.ios_dir.endswith(".buildozer/ios/platform/kivy-ios")
Expand Down Expand Up @@ -176,7 +178,7 @@ def test_unlock_keychain_wrong_password(self):
target = init_target(self.temp_dir)
# fmt: off
with mock.patch("buildozer.targets.ios.getpass") as m_getpass, \
patch_buildozer_cmd() as m_cmd, \
patch_buildops_cmd() as m_cmd, \
pytest.raises(BuildozerCommandException):
m_getpass.return_value = "password"
# the `security unlock-keychain` command returned an error
Expand All @@ -199,7 +201,7 @@ def test_build_package_no_signature(self):
patch_logger_error() as m_error, \
mock.patch("buildozer.targets.ios.TargetIos.load_plist_from_file") as m_load_plist_from_file, \
mock.patch("buildozer.targets.ios.TargetIos.dump_plist_to_file") as m_dump_plist_to_file, \
patch_buildozer_cmd() as m_cmd:
patch_buildops_cmd() as m_cmd:
m_load_plist_from_file.return_value = {}
target.build_package()
# fmt: on
Expand Down Expand Up @@ -235,6 +237,7 @@ def test_build_package_no_signature(self):
"clean",
"build"],
cwd="/ios/dir/myapp-ios",
env=MOCK.ANY,
),
mock.call([
"xcodebuild",
Expand Down
4 changes: 2 additions & 2 deletions tests/targets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def patch_buildozer(method):
return mock.patch("buildozer.Buildozer.{method}".format(method=method))


def patch_buildozer_cmd():
return patch_buildozer("cmd")
def patch_buildops_cmd():
return mock.patch("buildozer.buildops.cmd")


def patch_buildops_checkbin():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_buildozer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def test_android_ant_path(self):
mock.patch('buildozer.buildops.file_extract') as m_file_extract, \
mock.patch('os.makedirs'):
ant_path = target._install_apache_ant()
assert m_file_extract.call_args_list == [mock.call(mock.ANY, cwd='/my/ant/path')]
assert m_file_extract.call_args_list == [
mock.call(mock.ANY, cwd='/my/ant/path', env=mock.ANY)]
assert ant_path == my_ant_path
assert download.call_args_list == [
mock.call("https://archive.apache.org/dist/ant/binaries/", mock.ANY, cwd=my_ant_path)]
Expand Down

0 comments on commit 52ef3f6

Please sign in to comment.