27
27
28
28
29
29
class TestDistribution (unittest .TestCase ):
30
+ """
31
+ An inherited class of `unittest.TestCase`to test the module
32
+ :mod:`~pythonforandroid.distribution`.
33
+ """
34
+
30
35
def setUp (self ):
36
+ """Configure a :class:`~pythonforandroid.build.Context` so we can
37
+ perform our unittests"""
31
38
self .ctx = Context ()
32
39
self .ctx .ndk_api = 21
33
40
self .ctx .android_api = 27
@@ -42,8 +49,8 @@ def setUp(self):
42
49
]
43
50
44
51
def setUp_distribution_with_bootstrap (self , bs , ** kwargs ):
45
- # extend the setUp by configuring a distribution, because some test
46
- # needs a distribution to be set to be properly tested
52
+ """Extend the setUp by configuring a distribution, because some test
53
+ needs a distribution to be set to be properly tested"""
47
54
self .ctx .bootstrap = bs
48
55
self .ctx .bootstrap .distribution = Distribution .get_distribution (
49
56
self .ctx ,
@@ -53,9 +60,13 @@ def setUp_distribution_with_bootstrap(self, bs, **kwargs):
53
60
)
54
61
55
62
def tearDown (self ):
63
+ """Here we make sure that we reset a possible bootstrap created in
64
+ `setUp_distribution_with_bootstrap`"""
56
65
self .ctx .bootstrap = None
57
66
58
67
def test_properties (self ):
68
+ """Test that some attributes has the expected result (for now, we check
69
+ that `__repr__` and `__str__` return the proper values"""
59
70
self .setUp_distribution_with_bootstrap (
60
71
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
61
72
)
@@ -69,6 +80,9 @@ def test_properties(self):
69
80
70
81
@mock .patch ("pythonforandroid.distribution.exists" )
71
82
def test_folder_exist (self , mock_exists ):
83
+ """Test that method
84
+ :meth:`~pythonforandroid.distribution.Distribution.folder_exist` is
85
+ called once with the proper arguments."""
72
86
73
87
self .setUp_distribution_with_bootstrap (
74
88
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
@@ -80,7 +94,9 @@ def test_folder_exist(self, mock_exists):
80
94
81
95
@mock .patch ("pythonforandroid.distribution.rmtree" )
82
96
def test_delete (self , mock_rmtree ):
83
-
97
+ """Test that method
98
+ :meth:`~pythonforandroid.distribution.Distribution.delete` is
99
+ called once with the proper arguments."""
84
100
self .setUp_distribution_with_bootstrap (
85
101
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
86
102
)
@@ -91,7 +107,9 @@ def test_delete(self, mock_rmtree):
91
107
92
108
@mock .patch ("pythonforandroid.distribution.exists" )
93
109
def test_get_distribution_no_name (self , mock_exists ):
94
-
110
+ """Test that method
111
+ :meth:`~pythonforandroid.distribution.Distribution.get_distribution`
112
+ returns the proper result which should `unnamed_dist_1`."""
95
113
mock_exists .return_value = False
96
114
self .ctx .bootstrap = Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
97
115
dist = Distribution .get_distribution (self .ctx )
@@ -100,6 +118,9 @@ def test_get_distribution_no_name(self, mock_exists):
100
118
@mock .patch ("pythonforandroid.util.chdir" )
101
119
@mock .patch ("pythonforandroid.distribution.open" , create = True )
102
120
def test_save_info (self , mock_open_dist_info , mock_chdir ):
121
+ """Test that method
122
+ :meth:`~pythonforandroid.distribution.Distribution.save_info`
123
+ is called once with the proper arguments."""
103
124
self .setUp_distribution_with_bootstrap (
104
125
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
105
126
)
@@ -119,6 +140,15 @@ def test_save_info(self, mock_open_dist_info, mock_chdir):
119
140
def test_get_distributions (
120
141
self , mock_glob , mock_exists , mock_open_dist_info
121
142
):
143
+ """Test that method
144
+ :meth:`~pythonforandroid.distribution.Distribution.get_distributions`
145
+ returns some expected values:
146
+
147
+ - A list of instances of class
148
+ `~pythonforandroid.distribution.Distribution
149
+ - That one of the distributions returned in the result has the
150
+ proper values (`name`, `ndk_api` and `recipes`)
151
+ """
122
152
self .setUp_distribution_with_bootstrap (
123
153
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
124
154
)
@@ -146,6 +176,10 @@ def test_get_distributions(
146
176
def test_get_distributions_error_ndk_api (
147
177
self , mock_glob , mock_exists , mock_open_dist_info
148
178
):
179
+ """Test method
180
+ :meth:`~pythonforandroid.distribution.Distribution.get_distributions`
181
+ in case that `ndk_api` is not set..which should return a `None`.
182
+ """
149
183
dist_info_data_no_ndk_api = dist_info_data .copy ()
150
184
dist_info_data_no_ndk_api .pop ("ndk_api" )
151
185
self .setUp_distribution_with_bootstrap (
@@ -169,6 +203,12 @@ def test_get_distributions_error_ndk_api(
169
203
def test_get_distributions_error_ndk_api_mismatch (
170
204
self , mock_glob , mock_exists , mock_get_dists
171
205
):
206
+ """Test that method
207
+ :meth:`~pythonforandroid.distribution.Distribution.get_distribution`
208
+ raises an error in case that we have some distribution already build,
209
+ with a given `name` and `ndk_api`, and we try to get another
210
+ distribution with the same `name` but different `ndk_api`.
211
+ """
172
212
expected_dist = Distribution .get_distribution (
173
213
self .ctx , name = "test_prj" , recipes = ["python3" , "kivy" ]
174
214
)
@@ -189,10 +229,15 @@ def test_get_distributions_error_ndk_api_mismatch(
189
229
)
190
230
191
231
def test_get_distributions_error_extra_dist_dirs (self ):
232
+ """Test that method
233
+ :meth:`~pythonforandroid.distribution.Distribution.get_distributions`
234
+ raises an exception of
235
+ :class:`~pythonforandroid.util.BuildInterruptingException` in case that
236
+ we supply the kwargs `extra_dist_dirs`.
237
+ """
192
238
self .setUp_distribution_with_bootstrap (
193
239
Bootstrap ().get_bootstrap ("sdl2" , self .ctx )
194
240
)
195
-
196
241
with self .assertRaises (BuildInterruptingException ) as e :
197
242
self .ctx .bootstrap .distribution .get_distributions (
198
243
self .ctx , extra_dist_dirs = ["/fake/extra/dist_dirs" ]
@@ -205,6 +250,13 @@ def test_get_distributions_error_extra_dist_dirs(self):
205
250
206
251
@mock .patch ("pythonforandroid.distribution.Distribution.get_distributions" )
207
252
def test_get_distributions_possible_dists (self , mock_get_dists ):
253
+ """Test that method
254
+ :meth:`~pythonforandroid.distribution.Distribution.get_distributions`
255
+ returns the proper
256
+ `:class:`~pythonforandroid.distribution.Distribution` in case that we
257
+ already have it build and we request the same
258
+ `:class:`~pythonforandroid.distribution.Distribution`.
259
+ """
208
260
expected_dist = Distribution .get_distribution (
209
261
self .ctx , name = "test_prj" , recipes = ["python3" , "kivy" ]
210
262
)
0 commit comments