Skip to content

Commit

Permalink
[docs] Add documentation for module tests.test_archs
Browse files Browse the repository at this point in the history
  • Loading branch information
opacam committed Jun 11, 2019
1 parent 614d584 commit c89d312
Showing 1 changed file with 81 additions and 9 deletions.
90 changes: 81 additions & 9 deletions tests/test_archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@


class ArchSetUpBaseClass(object):
"""
An class object which is intended to be used as a base class to configure
an inherited class of `unittest.TestCase`. This class will override the
`setUp` method.
"""
ctx = None

def setUp(self):
Expand All @@ -63,6 +68,11 @@ def setUp(self):


class TestArch(ArchSetUpBaseClass, unittest.TestCase):
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for the base class
:class:`~pythonforandroid.archs.Arch`.
"""
def test_arch(self):
arch = Arch(self.ctx)
with self.assertRaises(AttributeError) as e1:
Expand All @@ -81,14 +91,27 @@ def test_arch(self):


class TestArchARM(ArchSetUpBaseClass, unittest.TestCase):
# Here we mock two functions:
# - `ensure_dir` because we don't want to create any directory
# - `find_executable` because otherwise we will
# get an error when trying to find the compiler (we are setting some fake
# paths for our android sdk and ndk so probably will not exist)
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for :class:`~pythonforandroid.archs.ArchARM`.
"""
@mock.patch("pythonforandroid.archs.find_executable")
@mock.patch("pythonforandroid.build.ensure_dir")
def test_arch_arm(self, mock_ensure_dir, mock_find_executable):
"""
Test that class :class:`~pythonforandroid.archs.ArchARM` returns some
expected attributes and environment variables.
.. note::
Here we mock two methods:
- `ensure_dir` because we don't want to create any directory
- `find_executable` because otherwise we will
get an error when trying to find the compiler (we are setting
some fake paths for our android sdk and ndk so probably will
not exist)
"""
mock_find_executable.return_value = "arm-linux-androideabi-gcc"
mock_ensure_dir.return_value = True

Expand Down Expand Up @@ -147,16 +170,30 @@ def test_arch_arm(self, mock_ensure_dir, mock_find_executable):


class TestArchARMv7a(ArchSetUpBaseClass, unittest.TestCase):
# Here we mock the same functions than the previous tests plus `glob`,
# so we make sure that the glob result is the expected even if the folder
# doesn't exist, which is probably the case. This has to be done because
# here we tests the `get_env` with clang
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for
:class:`~pythonforandroid.archs.ArchARMv7_a`.
"""

@mock.patch("pythonforandroid.archs.glob")
@mock.patch("pythonforandroid.archs.find_executable")
@mock.patch("pythonforandroid.build.ensure_dir")
def test_arch_armv7a(
self, mock_ensure_dir, mock_find_executable, mock_glob
):
"""
Test that class :class:`~pythonforandroid.archs.ArchARMv7_a` returns
some expected attributes and environment variables.
.. note::
Here we mock the same functions than
:meth:`TestArchARM.test_arch_arm` plus `glob`, so we make sure that
the glob result is the expected even if the folder doesn't exist,
which is probably the case. This has to be done because here we
tests the `get_env` with clang
"""
mock_find_executable.return_value = "arm-linux-androideabi-gcc"
mock_ensure_dir.return_value = True
mock_glob.return_value = ["llvm"]
Expand Down Expand Up @@ -197,9 +234,20 @@ def test_arch_armv7a(


class TestArchX86(ArchSetUpBaseClass, unittest.TestCase):
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for :class:`~pythonforandroid.archs.Archx86`.
"""
@mock.patch("pythonforandroid.archs.find_executable")
@mock.patch("pythonforandroid.build.ensure_dir")
def test_arch_x86(self, mock_ensure_dir, mock_find_executable):
"""
Test that class :class:`~pythonforandroid.archs.Archx86` returns
some expected attributes and environment variables.
.. note:: Here we mock the same functions than
:meth:`TestArchARM.test_arch_arm`
"""
mock_find_executable.return_value = "arm-linux-androideabi-gcc"
mock_ensure_dir.return_value = True

Expand All @@ -220,9 +268,21 @@ def test_arch_x86(self, mock_ensure_dir, mock_find_executable):


class TestArchX86_64(ArchSetUpBaseClass, unittest.TestCase):
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for
:class:`~pythonforandroid.archs.Archx86_64`.
"""
@mock.patch("pythonforandroid.archs.find_executable")
@mock.patch("pythonforandroid.build.ensure_dir")
def test_arch_x86_64(self, mock_ensure_dir, mock_find_executable):
"""
Test that class :class:`~pythonforandroid.archs.Archx86_64` returns
some expected attributes and environment variables.
.. note:: Here we mock the same functions than
:meth:`TestArchARM.test_arch_arm`
"""
mock_find_executable.return_value = "arm-linux-androideabi-gcc"
mock_ensure_dir.return_value = True

Expand All @@ -242,9 +302,21 @@ def test_arch_x86_64(self, mock_ensure_dir, mock_find_executable):


class TestArchAArch64(ArchSetUpBaseClass, unittest.TestCase):
"""
An inherited class of `ArchSetUpBaseClass` and `unittest.TestCase` which
will be used to perform tests for
:class:`~pythonforandroid.archs.ArchAarch_64`.
"""
@mock.patch("pythonforandroid.archs.find_executable")
@mock.patch("pythonforandroid.build.ensure_dir")
def test_arch_aarch_64(self, mock_ensure_dir, mock_find_executable):
"""
Test that class :class:`~pythonforandroid.archs.ArchAarch_64` returns
some expected attributes and environment variables.
.. note:: Here we mock the same functions than
:meth:`TestArchARM.test_arch_arm`
"""
mock_find_executable.return_value = "arm-linux-androideabi-gcc"
mock_ensure_dir.return_value = True

Expand Down

0 comments on commit c89d312

Please sign in to comment.