14
14
"bootstrap" : "sdl2" ,
15
15
"archs" : ["armeabi" , "armeabi-v7a" , "x86" , "x86_64" , "arm64-v8a" ],
16
16
"ndk_api" : 21 ,
17
+ "android_api" : 27 ,
17
18
"use_setup_py" : False ,
18
19
"recipes" : ["hostpython3" , "python3" , "sdl2" , "kivy" , "requests" ],
19
20
"hostpython" : "/some/fake/hostpython3" ,
@@ -33,8 +34,8 @@ def setUp(self):
33
34
"""Configure a :class:`~pythonforandroid.build.Context` so we can
34
35
perform our unittests"""
35
36
self .ctx = Context ()
36
- self .ctx .ndk_api = 21
37
- self .ctx .android_api = 27
37
+ self .ctx .ndk_api = dist_info_data [ 'ndk_api' ]
38
+ self .ctx .android_api = dist_info_data [ 'android_api' ]
38
39
self .ctx ._sdk_dir = "/opt/android/android-sdk"
39
40
self .ctx ._ndk_dir = "/opt/android/android-ndk"
40
41
self .ctx .setup_dirs (os .getcwd ())
@@ -104,6 +105,40 @@ def test_get_dist_info(self, mock_open):
104
105
mock_open .assert_called_once_with ("/fake_dir/dist_info.json" , "r" )
105
106
self .assertIsInstance (dist_info , dict )
106
107
108
+ @mock .patch ("pythonforandroid.distribution.json.dump" )
109
+ @mock .patch ("pythonforandroid.distribution.open" , create = True )
110
+ def test_update_dist_info (self , mock_open , mock_json ):
111
+ """Test that method
112
+ :meth:`~pythonforandroid.distribution.Distribution.update_dist_info`
113
+ calls the proper methods with the right arguments."""
114
+ self .setUp_distribution_with_bootstrap (
115
+ Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
116
+ )
117
+ new_info_data = dist_info_data
118
+ new_info_data ['android_api' ] = 28
119
+ expected_json_file = mock .mock_open (
120
+ read_data = json .dumps (new_info_data )
121
+ ).return_value
122
+ mock_open .side_effect = [
123
+ # first call to open, when we read the file
124
+ mock .mock_open (read_data = json .dumps (dist_info_data )).return_value ,
125
+ # second call to open, when we update the file
126
+ expected_json_file ,
127
+ ]
128
+
129
+ self .ctx .bootstrap .distribution .update_dist_info (
130
+ "android_api" , new_info_data ['android_api' ]
131
+ )
132
+ # Note: call_args only contemplates the last mocked call, see also:
133
+ # https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.call_args # noqa
134
+ self .assertTrue (mock_open .call_args [0 ][0 ].endswith (
135
+ 'dists/test_prj__armeabi-v7a/dist_info.json' )
136
+ )
137
+ self .assertEqual (mock_open .call_args [0 ][1 ], 'w' )
138
+ mock_json .assert_called_once_with (
139
+ new_info_data , expected_json_file , indent = 4 , sort_keys = True ,
140
+ )
141
+
107
142
@mock .patch ("pythonforandroid.distribution.exists" )
108
143
def test_folder_exist (self , mock_exists ):
109
144
"""Test that method
0 commit comments