Skip to content

Commit

Permalink
Recipes tests enhancements (kivy#1984)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
opacam authored and joergbrech committed Nov 10, 2019
1 parent 1bb3972 commit 2b541b2
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 59 deletions.
16 changes: 7 additions & 9 deletions tests/recipes/recipe_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -26,13 +24,13 @@ 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)
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")
@mock.patch("pythonforandroid.build.ensure_dir")
Expand Down
2 changes: 1 addition & 1 deletion tests/recipes/test_gevent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from mock import patch
from unittest.mock import patch
from tests.recipes.recipe_ctx import RecipeCtx


Expand Down
2 changes: 0 additions & 2 deletions tests/recipes/test_icu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 0 additions & 9 deletions tests/recipes/test_pyicu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion tests/recipes/test_reportlab.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 1 addition & 7 deletions tests/test_archs.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions tests/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_build.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
7 changes: 1 addition & 6 deletions tests/test_distribution.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pythonforandroid.util import BuildInterruptingException
from itertools import product

import mock
from unittest import mock
import pytest

ctx = Context()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from mock import MagicMock
from unittest.mock import MagicMock
from pythonforandroid import logger


Expand Down
2 changes: 1 addition & 1 deletion tests/test_pythonpackage_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
while the other additional ones aren't (for build time reasons).
"""

import mock
import os
import pytest
import shutil
import sys
import subprocess
import tempfile
import textwrap
from unittest import mock

from pythonforandroid.pythonpackage import (
_extract_info_from_package,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_toolchain.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ basepython = python3

[testenv]
deps =
mock
py27: mock
pytest
virtualenv
py3: coveralls
Expand Down

0 comments on commit 2b541b2

Please sign in to comment.