diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000000..254832ceaf --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,70 @@ +name: Unit tests & Build Testapp + +on: ['push', 'pull_request'] + +jobs: + + flake8: + name: Flake8 tests + runs-on: ubuntu-latest + steps: + - name: Checkout python-for-android + uses: actions/checkout@master + - name: Set up Python 3.7 + uses: actions/setup-python@v1.1.0 + with: + python-version: 3.7 + - name: Run flake8 + run: | + python -m pip install --upgrade pip + pip install tox>=2.0 + tox -e pep8 + + test: + name: Pytest [Python ${{ matrix.python-version }} | ${{ matrix.os }}] + needs: flake8 + runs-on: ${{ matrix.os }} + strategy: + matrix: + python-version: [3.6, 3.7] + os: [ubuntu-latest, macOs-latest] + steps: + - name: Checkout python-for-android + uses: actions/checkout@master + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1.1.0 + with: + python-version: ${{ matrix.python-version }} + - name: Tox tests + run: | + python -m pip install --upgrade pip + pip install tox>=2.0 + make test + + build: + name: Build testapp + needs: [flake8] + runs-on: ubuntu-latest + steps: + - name: Checkout python-for-android + uses: actions/checkout@master + - name: Pull docker image + run: | + make docker/pull + - name: Build apk for Python 3 arm64-v8a + run: | + make docker/run/make/testapps/python3/arm64-v8a + + rebuild_updated_recipes: + name: Test updated recipes + needs: [flake8] + runs-on: ubuntu-latest + steps: + - name: Checkout python-for-android + uses: actions/checkout@master + - name: Pull docker image + run: | + make docker/pull + - name: Rebuild updated recipes + run: | + make docker/run/make/rebuild_updated_recipes diff --git a/tests/recipes/recipe_lib_test.py b/tests/recipes/recipe_lib_test.py index 5622397aa5..6c48474384 100644 --- a/tests/recipes/recipe_lib_test.py +++ b/tests/recipes/recipe_lib_test.py @@ -1,4 +1,5 @@ from unittest import mock +from platform import system from tests.recipes.recipe_ctx import RecipeCtx @@ -13,7 +14,7 @@ class BaseTestForMakeRecipe(RecipeCtx): recipe_name = None expected_compiler = ( - "{android_ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" + "{android_ndk}/toolchains/llvm/prebuilt/{system}-x86_64/bin/clang" ) sh_command_calls = ["./configure"] @@ -48,7 +49,7 @@ def test_get_recipe_env( some internal methods has been called. """ mock_find_executable.return_value = self.expected_compiler.format( - android_ndk=self.ctx._ndk_dir + android_ndk=self.ctx._ndk_dir, system=system().lower() ) mock_glob.return_value = ["llvm"] mock_check_recipe_choices.return_value = sorted( @@ -85,7 +86,7 @@ def test_build_arch( mock_current_directory, ): mock_find_executable.return_value = self.expected_compiler.format( - android_ndk=self.ctx._ndk_dir + android_ndk=self.ctx._ndk_dir, system=system().lower() ) mock_glob.return_value = ["llvm"] @@ -133,7 +134,7 @@ def test_build_arch( mock_current_directory, ): mock_find_executable.return_value = self.expected_compiler.format( - android_ndk=self.ctx._ndk_dir + android_ndk=self.ctx._ndk_dir, system=system().lower() ) mock_glob.return_value = ["llvm"] diff --git a/tests/recipes/test_icu.py b/tests/recipes/test_icu.py index 506cdb74b2..00cfbdbbe7 100644 --- a/tests/recipes/test_icu.py +++ b/tests/recipes/test_icu.py @@ -1,6 +1,7 @@ import os import unittest from unittest import mock +from platform import system from tests.recipes.recipe_ctx import RecipeCtx from pythonforandroid.recipes.icu import ICURecipe @@ -47,7 +48,7 @@ def test_build_arch( ): mock_find_executable.return_value = os.path.join( self.ctx._ndk_dir, - "toolchains/llvm/prebuilt/linux-x86_64/bin/clang", + f"toolchains/llvm/prebuilt/{system().lower()}-x86_64/bin/clang", ) mock_archs_glob.return_value = [ os.path.join(self.ctx._ndk_dir, "toolchains", "llvm") diff --git a/tests/test_archs.py b/tests/test_archs.py index ddb18b80e2..61887e0e51 100644 --- a/tests/test_archs.py +++ b/tests/test_archs.py @@ -2,6 +2,7 @@ import unittest from os import environ from unittest import mock +from platform import system from pythonforandroid.bootstrap import Bootstrap from pythonforandroid.distribution import Distribution @@ -70,8 +71,8 @@ def setUp(self): # Here we define the expected compiler, which, as per ndk >= r19, # should be the same for all the tests (no more gcc compiler) self.expected_compiler = ( - "/opt/android/android-ndk/toolchains/" - "llvm/prebuilt/linux-x86_64/bin/clang" + f"/opt/android/android-ndk/toolchains/" + f"llvm/prebuilt/{system().lower()}-x86_64/bin/clang" ) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 02d54f0d9e..b164985e38 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -4,6 +4,8 @@ import unittest from unittest import mock +from platform import system + from pythonforandroid.bootstrap import ( _cmp_bootstraps_by_priority, Bootstrap, expand_dependencies, ) @@ -546,7 +548,7 @@ def test_bootstrap_strip( ): mock_find_executable.return_value = os.path.join( self.ctx._ndk_dir, - "toolchains/llvm/prebuilt/linux-x86_64/bin/clang", + f"toolchains/llvm/prebuilt/{system().lower()}-x86_64/bin/clang", ) mock_glob.return_value = [ os.path.join(self.ctx._ndk_dir, "toolchains", "llvm") diff --git a/tests/test_pythonpackage_basic.py b/tests/test_pythonpackage_basic.py index 3d1a156df6..a39d8a44e3 100644 --- a/tests/test_pythonpackage_basic.py +++ b/tests/test_pythonpackage_basic.py @@ -308,7 +308,9 @@ def test_virtualenv(self): sys_python_path = self.run__get_system_python_executable( os.path.join(test_dir, "virtualenv", "bin", "python") ) - assert os.path.normpath(sys_python_path) == os.path.normpath(pybin) + assert os.path.normpath(sys_python_path).startswith( + os.path.normpath(pybin) + ) finally: shutil.rmtree(test_dir) @@ -341,6 +343,8 @@ def test_venv(self): sys_python_path = self.run__get_system_python_executable( os.path.join(test_dir, "venv", "bin", "python") ) - assert os.path.normpath(sys_python_path) == os.path.normpath(pybin) + assert os.path.normpath(sys_python_path).startswith( + os.path.normpath(pybin) + ) finally: shutil.rmtree(test_dir) diff --git a/tests/test_recipe.py b/tests/test_recipe.py index c01ab83507..9ff1713c95 100644 --- a/tests/test_recipe.py +++ b/tests/test_recipe.py @@ -5,6 +5,8 @@ import warnings from unittest import mock from backports import tempfile +from platform import system + from pythonforandroid.build import Context from pythonforandroid.recipe import Recipe, import_recipe from pythonforandroid.archs import ArchAarch_64 @@ -278,8 +280,8 @@ def test_get_recipe_env_with( should be tested in the proper test. """ expected_compiler = ( - "/opt/android/android-ndk/toolchains/" - "llvm/prebuilt/linux-x86_64/bin/clang" + f"/opt/android/android-ndk/toolchains/" + f"llvm/prebuilt/{system().lower()}-x86_64/bin/clang" ) mock_find_executable.return_value = expected_compiler mock_glob.return_value = ["llvm"] diff --git a/tests/test_toolchain.py b/tests/test_toolchain.py index 7e3078133b..e299794ebb 100644 --- a/tests/test_toolchain.py +++ b/tests/test_toolchain.py @@ -78,10 +78,14 @@ def test_create(self): m_get_ndk_platform_dir.return_value = ( '/tmp/android-ndk/platforms/android-21/arch-arm', True) ToolchainCL() - assert m_get_available_apis.call_args_list == [ - mock.call('/tmp/android-sdk')] - assert m_get_toolchain_versions.call_args_list == [ - mock.call('/tmp/android-ndk', mock.ANY)] + assert m_get_available_apis.call_args_list in [ + [mock.call('/tmp/android-sdk')], # linux case + [mock.call('/private/tmp/android-sdk')] # macos case + ] + assert m_get_toolchain_versions.call_args_list in [ + [mock.call('/tmp/android-ndk', mock.ANY)], # linux case + [mock.call('/private/tmp/android-ndk', mock.ANY)], # macos case + ] build_order = [ 'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3', 'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android', @@ -100,6 +104,10 @@ def test_create(self): ] assert m_run_distribute.call_args_list == [mock.call()] + @mock.patch( + 'pythonforandroid.build.environ', + # Make sure that no environ variable modifies `sdk_dir` + {'ANDROIDSDK': None, 'ANDROID_HOME': None}) def test_create_no_sdk_dir(self): """ The `--sdk-dir` is mandatory to `create` a distribution.