|
21 | 21 | "python_version": "3.7",
|
22 | 22 | }
|
23 | 23 |
|
| 24 | +gradle_file_partial_content = f""" |
| 25 | +android {{ |
| 26 | + compileSdkVersion {dist_info_data["android_api"]} |
| 27 | + buildToolsVersion '29.0.1' |
| 28 | + defaultConfig {{ |
| 29 | + minSdkVersion {dist_info_data["ndk_api"]} |
| 30 | + targetSdkVersion {dist_info_data["android_api"]} |
| 31 | + versionCode 821101 |
| 32 | + versionName '1.1' |
| 33 | + }} |
| 34 | +}} |
| 35 | +""" |
| 36 | + |
24 | 37 |
|
25 | 38 | class TestDistribution(unittest.TestCase):
|
26 | 39 | """
|
@@ -158,6 +171,45 @@ def test_update_dist_project_properties_android_api(self, mock_open):
|
158 | 171 | )
|
159 | 172 | self.assertEqual(mock_open.call_args[0][1], 'w')
|
160 | 173 |
|
| 174 | + @mock.patch("pythonforandroid.distribution.open") |
| 175 | + def test_update_dist_android_api(self, mock_open): |
| 176 | + """Test that method |
| 177 | + :meth:`~pythonforandroid.distribution.Distribution.update_dist_android_api` |
| 178 | + calls the proper methods with the right arguments.""" |
| 179 | + self.setUp_distribution_with_bootstrap( |
| 180 | + Bootstrap().get_bootstrap("sdl2", self.ctx) |
| 181 | + ) |
| 182 | + |
| 183 | + new_android_api = 28 |
| 184 | + new_gradle_content = gradle_file_partial_content.replace( |
| 185 | + f"compileSdkVersion {dist_info_data['android_api']}", |
| 186 | + f"compileSdkVersion {new_android_api}" |
| 187 | + ).replace( |
| 188 | + f"targetSdkVersion {dist_info_data['android_api']}", |
| 189 | + f"targetSdkVersion {new_android_api}" |
| 190 | + ) |
| 191 | + mock_open.side_effect = [ |
| 192 | + mock.mock_open(read_data=gradle_file_partial_content).return_value, |
| 193 | + mock.mock_open(read_data=new_gradle_content).return_value, |
| 194 | + mock.mock_open(read_data="target=android-27").return_value, |
| 195 | + mock.mock_open(read_data=json.dumps(dist_info_data)).return_value, |
| 196 | + mock.mock_open(read_data=json.dumps(dist_info_data)).return_value, |
| 197 | + ] |
| 198 | + |
| 199 | + dist = self.ctx.bootstrap.distribution |
| 200 | + dist.update_dist_android_api(new_android_api) |
| 201 | + mock_open.assert_has_calls( |
| 202 | + [ |
| 203 | + mock.call(os.path.join(dist.dist_dir, "build.gradle"), "r"), |
| 204 | + mock.call(os.path.join(dist.dist_dir, "build.gradle"), "w"), |
| 205 | + mock.call( |
| 206 | + os.path.join(dist.dist_dir, "project.properties"), "w" |
| 207 | + ), |
| 208 | + mock.call(os.path.join(dist.dist_dir, "dist_info.json"), "r"), |
| 209 | + mock.call(os.path.join(dist.dist_dir, "dist_info.json"), "w"), |
| 210 | + ] |
| 211 | + ) |
| 212 | + |
161 | 213 | @mock.patch("pythonforandroid.distribution.exists")
|
162 | 214 | def test_folder_exist(self, mock_exists):
|
163 | 215 | """Test that method
|
|
0 commit comments