From b4d3795736b67564923376a7b257a2ffb75555d5 Mon Sep 17 00:00:00 2001 From: opacam Date: Sun, 15 Sep 2019 13:17:54 +0200 Subject: [PATCH 1/3] [test] From `__new__` to `__init__` for `BaseTestForMakeRecipe` --- tests/recipes/recipe_lib_test.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/recipes/recipe_lib_test.py b/tests/recipes/recipe_lib_test.py index dbb476028b..ac80434ad4 100644 --- a/tests/recipes/recipe_lib_test.py +++ b/tests/recipes/recipe_lib_test.py @@ -26,13 +26,12 @@ class BaseTestForMakeRecipe(RecipeCtx): This must be a dictionary containing pairs of key (env var) and value. """ - def __new__(cls, *args): - obj = super().__new__(cls) - if obj.recipe_name is not None: - print(f"We are testing recipe: {obj.recipe_name}") - obj.recipes.append(obj.recipe_name) - obj.recipe_build_order.insert(1, obj.recipe_name) - return obj + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + if self.recipe_name not in self.recipes: + self.recipes.append(self.recipe_name) + self.recipe_build_order.insert(1, self.recipe_name) + print(f"We are testing recipe: {self.recipe_name}") @mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices") @mock.patch("pythonforandroid.build.ensure_dir") From 7f8823eea7204172cafd2cf8df9374dc5f6e4289 Mon Sep 17 00:00:00 2001 From: opacam Date: Sun, 15 Sep 2019 13:30:37 +0200 Subject: [PATCH 2/3] [test] Remove mock dependency for py3 tests Because, as per Python 3.3+, `mock` it's a built-in-module --- tests/recipes/test_gevent.py | 2 +- tests/recipes/test_reportlab.py | 2 +- tests/test_archs.py | 8 +------- tests/test_bootstrap.py | 7 +------ tests/test_build.py | 7 +------ tests/test_distribution.py | 7 +------ tests/test_graph.py | 2 +- tests/test_logger.py | 2 +- tests/test_pythonpackage_basic.py | 2 +- tests/test_recipe.py | 2 +- tests/test_toolchain.py | 2 +- tests/test_util.py | 7 +------ tox.ini | 2 +- 13 files changed, 13 insertions(+), 39 deletions(-) diff --git a/tests/recipes/test_gevent.py b/tests/recipes/test_gevent.py index 3b1ce62842..fa56fe6a11 100644 --- a/tests/recipes/test_gevent.py +++ b/tests/recipes/test_gevent.py @@ -1,5 +1,5 @@ import unittest -from mock import patch +from unittest.mock import patch from tests.recipes.recipe_ctx import RecipeCtx diff --git a/tests/recipes/test_reportlab.py b/tests/recipes/test_reportlab.py index 24934efdaf..83191e5286 100644 --- a/tests/recipes/test_reportlab.py +++ b/tests/recipes/test_reportlab.py @@ -1,6 +1,6 @@ import os import unittest -from mock import patch +from unittest.mock import patch from tests.recipes.recipe_ctx import RecipeCtx from pythonforandroid.util import ensure_dir diff --git a/tests/test_archs.py b/tests/test_archs.py index 7cbe5421ad..24c118eb40 100644 --- a/tests/test_archs.py +++ b/tests/test_archs.py @@ -1,13 +1,7 @@ import os import unittest from os import environ - -try: - from unittest import mock -except ImportError: - # `Python 2` or lower than `Python 3.3` does not - # have the `unittest.mock` module built-in - import mock +from unittest import mock from pythonforandroid.bootstrap import Bootstrap from pythonforandroid.distribution import Distribution diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index e3e75b945f..6297eef551 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -3,12 +3,7 @@ import sh import unittest -try: - from unittest import mock -except ImportError: - # `Python 2` or lower than `Python 3.3` does not - # have the `unittest.mock` module built-in - import mock +from unittest import mock from pythonforandroid.bootstrap import ( _cmp_bootstraps_by_priority, Bootstrap, expand_dependencies, ) diff --git a/tests/test_build.py b/tests/test_build.py index 784e24c23f..6e659a5837 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -1,11 +1,6 @@ import unittest +from unittest import mock -try: - from unittest import mock -except ImportError: - # `Python 2` or lower than `Python 3.3` does not - # have the `unittest.mock` module built-in - import mock from pythonforandroid.build import run_pymodules_install diff --git a/tests/test_distribution.py b/tests/test_distribution.py index dece511074..e533a5af5e 100644 --- a/tests/test_distribution.py +++ b/tests/test_distribution.py @@ -1,13 +1,8 @@ import os import json import unittest +from unittest import mock -try: - from unittest import mock -except ImportError: - # `Python 2` or lower than `Python 3.3` does not - # have the `unittest.mock` module built-in - import mock from pythonforandroid.bootstrap import Bootstrap from pythonforandroid.distribution import Distribution from pythonforandroid.recipe import Recipe diff --git a/tests/test_graph.py b/tests/test_graph.py index ccade98561..ebe9fb400d 100644 --- a/tests/test_graph.py +++ b/tests/test_graph.py @@ -8,7 +8,7 @@ from pythonforandroid.util import BuildInterruptingException from itertools import product -import mock +from unittest import mock import pytest ctx = Context() diff --git a/tests/test_logger.py b/tests/test_logger.py index 8212b4596f..773e7e54a0 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -1,5 +1,5 @@ import unittest -from mock import MagicMock +from unittest.mock import MagicMock from pythonforandroid import logger diff --git a/tests/test_pythonpackage_basic.py b/tests/test_pythonpackage_basic.py index 121f0e946b..7b92f79721 100644 --- a/tests/test_pythonpackage_basic.py +++ b/tests/test_pythonpackage_basic.py @@ -5,7 +5,6 @@ while the other additional ones aren't (for build time reasons). """ -import mock import os import pytest import shutil @@ -13,6 +12,7 @@ import subprocess import tempfile import textwrap +from unittest import mock from pythonforandroid.pythonpackage import ( _extract_info_from_package, diff --git a/tests/test_recipe.py b/tests/test_recipe.py index c3ff2d6b6e..c01ab83507 100644 --- a/tests/test_recipe.py +++ b/tests/test_recipe.py @@ -3,7 +3,7 @@ import types import unittest import warnings -import mock +from unittest import mock from backports import tempfile from pythonforandroid.build import Context from pythonforandroid.recipe import Recipe, import_recipe diff --git a/tests/test_toolchain.py b/tests/test_toolchain.py index 11e35ff989..7e3078133b 100644 --- a/tests/test_toolchain.py +++ b/tests/test_toolchain.py @@ -1,7 +1,7 @@ import io import sys import pytest -import mock +from unittest import mock from pythonforandroid.recipe import Recipe from pythonforandroid.toolchain import ToolchainCL from pythonforandroid.util import BuildInterruptingException diff --git a/tests/test_util.py b/tests/test_util.py index 9568514890..0653991639 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,13 +1,8 @@ import os import types import unittest +from unittest import mock -try: - from unittest import mock -except ImportError: - # `Python 2` or lower than `Python 3.3` does not - # have the `unittest.mock` module built-in - import mock from pythonforandroid import util diff --git a/tox.ini b/tox.ini index 2ca84ae803..6a90ef435d 100644 --- a/tox.ini +++ b/tox.ini @@ -4,7 +4,7 @@ basepython = python3 [testenv] deps = - mock + py27: mock pytest virtualenv py3: coveralls From 5ea2ba517b703cb089224b3664e4b4ff46ab74b2 Mon Sep 17 00:00:00 2001 From: opacam Date: Sun, 15 Sep 2019 15:10:01 +0200 Subject: [PATCH 3/3] [test] Convert cls attributes to instance attributes Because we may have some side effects without willing, considering that cls attributes are shared between instances. --- tests/recipes/recipe_lib_test.py | 9 ++++----- tests/recipes/test_icu.py | 2 -- tests/recipes/test_pyicu.py | 9 --------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/tests/recipes/recipe_lib_test.py b/tests/recipes/recipe_lib_test.py index ac80434ad4..5622397aa5 100644 --- a/tests/recipes/recipe_lib_test.py +++ b/tests/recipes/recipe_lib_test.py @@ -12,8 +12,6 @@ class BaseTestForMakeRecipe(RecipeCtx): """ recipe_name = None - recipes = ["python3", "kivy"] - recipe_build_order = ["hostpython3", "python3", "sdl2", "kivy"] expected_compiler = ( "{android_ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" ) @@ -28,9 +26,10 @@ class BaseTestForMakeRecipe(RecipeCtx): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if self.recipe_name not in self.recipes: - self.recipes.append(self.recipe_name) - self.recipe_build_order.insert(1, self.recipe_name) + self.recipes = ["python3", "kivy", self.recipe_name] + self.recipe_build_order = [ + "hostpython3", self.recipe_name, "python3", "sdl2", "kivy" + ] print(f"We are testing recipe: {self.recipe_name}") @mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices") diff --git a/tests/recipes/test_icu.py b/tests/recipes/test_icu.py index 22de4b3dd3..506cdb74b2 100644 --- a/tests/recipes/test_icu.py +++ b/tests/recipes/test_icu.py @@ -12,8 +12,6 @@ class TestIcuRecipe(RecipeCtx, unittest.TestCase): """ recipe_name = "icu" - recipes = ["python3", "kivy", "icu"] - recipe_build_order = ["hostpython3", "icu", "python3", "sdl2", "kivy"] def test_url(self): self.assertTrue(self.recipe.versioned_url.startswith("http")) diff --git a/tests/recipes/test_pyicu.py b/tests/recipes/test_pyicu.py index 2bcf1feeaf..ac70c4ea18 100644 --- a/tests/recipes/test_pyicu.py +++ b/tests/recipes/test_pyicu.py @@ -9,15 +9,6 @@ class TestPyIcuRecipe(RecipeCtx, unittest.TestCase): An unittest for recipe :mod:`~pythonforandroid.recipes.pyicu` """ recipe_name = "pyicu" - recipes = ["python3", "kivy", "pyicu"] - recipe_build_order = [ - "hostpython3", - "icu", - "python3", - "sdl2", - "pyicu", - "kivy", - ] @mock.patch("pythonforandroid.recipe.Recipe.check_recipe_choices") @mock.patch("pythonforandroid.build.ensure_dir")