Skip to content

Commit c2b4c80

Browse files
committed
[docs] Add documentation for module tests.test_distribution
1 parent 44741ae commit c2b4c80

File tree

1 file changed

+57
-5
lines changed

1 file changed

+57
-5
lines changed

tests/test_distribution.py

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727

2828

2929
class TestDistribution(unittest.TestCase):
30+
"""
31+
An inherited class of `unittest.TestCase`to test the module
32+
:mod:`~pythonforandroid.distribution`.
33+
"""
34+
3035
def setUp(self):
36+
"""Configure a :class:`~pythonforandroid.build.Context` so we can
37+
perform our unittests"""
3138
self.ctx = Context()
3239
self.ctx.ndk_api = 21
3340
self.ctx.android_api = 27
@@ -42,8 +49,8 @@ def setUp(self):
4249
]
4350

4451
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"""
4754
self.ctx.bootstrap = bs
4855
self.ctx.bootstrap.distribution = Distribution.get_distribution(
4956
self.ctx,
@@ -53,9 +60,13 @@ def setUp_distribution_with_bootstrap(self, bs, **kwargs):
5360
)
5461

5562
def tearDown(self):
63+
"""Here we make sure that we reset a possible bootstrap created in
64+
`setUp_distribution_with_bootstrap`"""
5665
self.ctx.bootstrap = None
5766

5867
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"""
5970
self.setUp_distribution_with_bootstrap(
6071
Bootstrap().get_bootstrap("sdl2", self.ctx)
6172
)
@@ -69,6 +80,9 @@ def test_properties(self):
6980

7081
@mock.patch("pythonforandroid.distribution.exists")
7182
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."""
7286

7387
self.setUp_distribution_with_bootstrap(
7488
Bootstrap().get_bootstrap("sdl2", self.ctx)
@@ -80,7 +94,9 @@ def test_folder_exist(self, mock_exists):
8094

8195
@mock.patch("pythonforandroid.distribution.rmtree")
8296
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."""
84100
self.setUp_distribution_with_bootstrap(
85101
Bootstrap().get_bootstrap("sdl2", self.ctx)
86102
)
@@ -91,7 +107,9 @@ def test_delete(self, mock_rmtree):
91107

92108
@mock.patch("pythonforandroid.distribution.exists")
93109
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`."""
95113
mock_exists.return_value = False
96114
self.ctx.bootstrap = Bootstrap().get_bootstrap("sdl2", self.ctx)
97115
dist = Distribution.get_distribution(self.ctx)
@@ -100,6 +118,9 @@ def test_get_distribution_no_name(self, mock_exists):
100118
@mock.patch("pythonforandroid.util.chdir")
101119
@mock.patch("pythonforandroid.distribution.open", create=True)
102120
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."""
103124
self.setUp_distribution_with_bootstrap(
104125
Bootstrap().get_bootstrap("sdl2", self.ctx)
105126
)
@@ -119,6 +140,15 @@ def test_save_info(self, mock_open_dist_info, mock_chdir):
119140
def test_get_distributions(
120141
self, mock_glob, mock_exists, mock_open_dist_info
121142
):
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+
"""
122152
self.setUp_distribution_with_bootstrap(
123153
Bootstrap().get_bootstrap("sdl2", self.ctx)
124154
)
@@ -146,6 +176,10 @@ def test_get_distributions(
146176
def test_get_distributions_error_ndk_api(
147177
self, mock_glob, mock_exists, mock_open_dist_info
148178
):
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+
"""
149183
dist_info_data_no_ndk_api = dist_info_data.copy()
150184
dist_info_data_no_ndk_api.pop("ndk_api")
151185
self.setUp_distribution_with_bootstrap(
@@ -169,6 +203,12 @@ def test_get_distributions_error_ndk_api(
169203
def test_get_distributions_error_ndk_api_mismatch(
170204
self, mock_glob, mock_exists, mock_get_dists
171205
):
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+
"""
172212
expected_dist = Distribution.get_distribution(
173213
self.ctx, name="test_prj", recipes=["python3", "kivy"]
174214
)
@@ -189,10 +229,15 @@ def test_get_distributions_error_ndk_api_mismatch(
189229
)
190230

191231
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+
"""
192238
self.setUp_distribution_with_bootstrap(
193239
Bootstrap().get_bootstrap("sdl2", self.ctx)
194240
)
195-
196241
with self.assertRaises(BuildInterruptingException) as e:
197242
self.ctx.bootstrap.distribution.get_distributions(
198243
self.ctx, extra_dist_dirs=["/fake/extra/dist_dirs"]
@@ -205,6 +250,13 @@ def test_get_distributions_error_extra_dist_dirs(self):
205250

206251
@mock.patch("pythonforandroid.distribution.Distribution.get_distributions")
207252
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+
"""
208260
expected_dist = Distribution.get_distribution(
209261
self.ctx, name="test_prj", recipes=["python3", "kivy"]
210262
)

0 commit comments

Comments
 (0)