Skip to content

Commit 2b541b2

Browse files
opacamjoergbrech
authored andcommitted
Recipes tests enhancements (kivy#1984)
This is a follow up of kivy#1982 In here we do: - Move from `__new__` to `__init__` for `BaseTestForMakeRecipe` ([discussed at here](kivy#1982 (comment))) - Convert cls attributes to instance attributes ([discussed at here](kivy#1982 (comment))) - Remove `mock` dependency for py3 tests (Because, as per Python 3.3+, `mock` it's a built-in-module). (Unfortunately we still will have a couple of `import mock` entries that we cannot remove until we completely remove python2 from our tests) * [test] From `__new__` to `__init__` for `BaseTestForMakeRecipe` * [test] Remove mock dependency for py3 tests Because, as per Python 3.3+, `mock` it's a built-in-module * [test] Convert cls attributes to instance attributes Because we may have some side effects without willing, considering that cls attributes are shared between instances.
1 parent 1bb3972 commit 2b541b2

16 files changed

+20
-59
lines changed

tests/recipes/recipe_lib_test.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class BaseTestForMakeRecipe(RecipeCtx):
1212
"""
1313

1414
recipe_name = None
15-
recipes = ["python3", "kivy"]
16-
recipe_build_order = ["hostpython3", "python3", "sdl2", "kivy"]
1715
expected_compiler = (
1816
"{android_ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
1917
)
@@ -26,13 +24,13 @@ class BaseTestForMakeRecipe(RecipeCtx):
2624
This must be a dictionary containing pairs of key (env var) and value.
2725
"""
2826

29-
def __new__(cls, *args):
30-
obj = super().__new__(cls)
31-
if obj.recipe_name is not None:
32-
print(f"We are testing recipe: {obj.recipe_name}")
33-
obj.recipes.append(obj.recipe_name)
34-
obj.recipe_build_order.insert(1, obj.recipe_name)
35-
return obj
27+
def __init__(self, *args, **kwargs):
28+
super().__init__(*args, **kwargs)
29+
self.recipes = ["python3", "kivy", self.recipe_name]
30+
self.recipe_build_order = [
31+
"hostpython3", self.recipe_name, "python3", "sdl2", "kivy"
32+
]
33+
print(f"We are testing recipe: {self.recipe_name}")
3634

3735
@mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices")
3836
@mock.patch("pythonforandroid.build.ensure_dir")

tests/recipes/test_gevent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from mock import patch
2+
from unittest.mock import patch
33
from tests.recipes.recipe_ctx import RecipeCtx
44

55

tests/recipes/test_icu.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class TestIcuRecipe(RecipeCtx, unittest.TestCase):
1212
"""
1313

1414
recipe_name = "icu"
15-
recipes = ["python3", "kivy", "icu"]
16-
recipe_build_order = ["hostpython3", "icu", "python3", "sdl2", "kivy"]
1715

1816
def test_url(self):
1917
self.assertTrue(self.recipe.versioned_url.startswith("http"))

tests/recipes/test_pyicu.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ class TestPyIcuRecipe(RecipeCtx, unittest.TestCase):
99
An unittest for recipe :mod:`~pythonforandroid.recipes.pyicu`
1010
"""
1111
recipe_name = "pyicu"
12-
recipes = ["python3", "kivy", "pyicu"]
13-
recipe_build_order = [
14-
"hostpython3",
15-
"icu",
16-
"python3",
17-
"sdl2",
18-
"pyicu",
19-
"kivy",
20-
]
2112

2213
@mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices")
2314
@mock.patch("pythonforandroid.build.ensure_dir")

tests/recipes/test_reportlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import unittest
3-
from mock import patch
3+
from unittest.mock import patch
44
from tests.recipes.recipe_ctx import RecipeCtx
55
from pythonforandroid.util import ensure_dir
66

tests/test_archs.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import os
22
import unittest
33
from os import environ
4-
5-
try:
6-
from unittest import mock
7-
except ImportError:
8-
# `Python 2` or lower than `Python 3.3` does not
9-
# have the `unittest.mock` module built-in
10-
import mock
4+
from unittest import mock
115

126
from pythonforandroid.bootstrap import Bootstrap
137
from pythonforandroid.distribution import Distribution

tests/test_bootstrap.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
import sh
44
import unittest
55

6-
try:
7-
from unittest import mock
8-
except ImportError:
9-
# `Python 2` or lower than `Python 3.3` does not
10-
# have the `unittest.mock` module built-in
11-
import mock
6+
from unittest import mock
127
from pythonforandroid.bootstrap import (
138
_cmp_bootstraps_by_priority, Bootstrap, expand_dependencies,
149
)

tests/test_build.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import unittest
2+
from unittest import mock
23

3-
try:
4-
from unittest import mock
5-
except ImportError:
6-
# `Python 2` or lower than `Python 3.3` does not
7-
# have the `unittest.mock` module built-in
8-
import mock
94
from pythonforandroid.build import run_pymodules_install
105

116

tests/test_distribution.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import os
22
import json
33
import unittest
4+
from unittest import mock
45

5-
try:
6-
from unittest import mock
7-
except ImportError:
8-
# `Python 2` or lower than `Python 3.3` does not
9-
# have the `unittest.mock` module built-in
10-
import mock
116
from pythonforandroid.bootstrap import Bootstrap
127
from pythonforandroid.distribution import Distribution
138
from pythonforandroid.recipe import Recipe

tests/test_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pythonforandroid.util import BuildInterruptingException
99
from itertools import product
1010

11-
import mock
11+
from unittest import mock
1212
import pytest
1313

1414
ctx = Context()

tests/test_logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import unittest
2-
from mock import MagicMock
2+
from unittest.mock import MagicMock
33
from pythonforandroid import logger
44

55

tests/test_pythonpackage_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
while the other additional ones aren't (for build time reasons).
66
"""
77

8-
import mock
98
import os
109
import pytest
1110
import shutil
1211
import sys
1312
import subprocess
1413
import tempfile
1514
import textwrap
15+
from unittest import mock
1616

1717
from pythonforandroid.pythonpackage import (
1818
_extract_info_from_package,

tests/test_recipe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import types
44
import unittest
55
import warnings
6-
import mock
6+
from unittest import mock
77
from backports import tempfile
88
from pythonforandroid.build import Context
99
from pythonforandroid.recipe import Recipe, import_recipe

tests/test_toolchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import sys
33
import pytest
4-
import mock
4+
from unittest import mock
55
from pythonforandroid.recipe import Recipe
66
from pythonforandroid.toolchain import ToolchainCL
77
from pythonforandroid.util import BuildInterruptingException

tests/test_util.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import os
22
import types
33
import unittest
4+
from unittest import mock
45

5-
try:
6-
from unittest import mock
7-
except ImportError:
8-
# `Python 2` or lower than `Python 3.3` does not
9-
# have the `unittest.mock` module built-in
10-
import mock
116
from pythonforandroid import util
127

138

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ basepython = python3
44

55
[testenv]
66
deps =
7-
mock
7+
py27: mock
88
pytest
99
virtualenv
1010
py3: coveralls

0 commit comments

Comments
 (0)