Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for modopt.base.backend and fix minute bug uncovered #126

Merged
merged 12 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
python -m pip install -r develop.txt
python -m pip install -r docs/requirements.txt
python -m pip install astropy scikit-image scikit-learn
python -m pip install tensorflow>=2.4.1
python -m pip install twine
python -m pip install .

Expand Down
54 changes: 53 additions & 1 deletion modopt/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
"""

from builtins import range
from unittest import TestCase
from unittest import TestCase, skipIf

import numpy as np
import numpy.testing as npt

from modopt.base import np_adjust, transform, types
from modopt.base.backend import (LIBRARIES, change_backend, get_array_module,
get_backend)


class NPAdjustTestCase(TestCase):
Expand Down Expand Up @@ -275,3 +277,53 @@ def test_check_npndarray(self):
self.data3,
dtype=np.integer,
)


class TestBackend(TestCase):
"""Test the backend codes."""

def setUp(self):
"""Set test parameter values."""
self.input = np.array([10, 10])

@skipIf(LIBRARIES['tensorflow'] is None, 'tensorflow library not installed')
def test_tf_backend(self):
"""Test tensorflow backend."""
xp, backend = get_backend('tensorflow')
if backend != 'tensorflow' or xp != LIBRARIES['tensorflow']:
raise AssertionError('tensorflow get_backend fails!')
tf_input = change_backend(self.input, 'tensorflow')
if (
get_array_module(LIBRARIES['tensorflow'].ones(1)) != LIBRARIES['tensorflow']
or get_array_module(tf_input) != LIBRARIES['tensorflow']
):
raise AssertionError('tensorflow backend fails!')

@skipIf(LIBRARIES['cupy'] is None, 'cupy library not installed')
def test_cp_backend(self):
"""Test cupy backend."""
xp, backend = get_backend('cupy')
if backend != 'cupy' or xp != LIBRARIES['cupy']:
raise AssertionError('cupy get_backend fails!')
cp_input = change_backend(self.input, 'cupy')
if (
get_array_module(LIBRARIES['cupy'].ones(1)) != LIBRARIES['cupy']
or get_array_module(cp_input) != LIBRARIES['cupy']
):
raise AssertionError('cupy backend fails!')

def test_np_backend(self):
"""Test numpy backend."""
xp, backend = get_backend('numpy')
if backend != 'numpy' or xp != LIBRARIES['numpy']:
raise AssertionError('numpy get_backend fails!')
np_input = change_backend(self.input, 'numpy')
if (
get_array_module(LIBRARIES['numpy'].ones(1)) != LIBRARIES['numpy']
or get_array_module(np_input) != LIBRARIES['numpy']
):
raise AssertionError('numpy backend fails!')

def tearDown(self):
"""Tear Down of objects."""
self.input = None
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ per-file-ignores =
modopt/signal/wavelet.py: S404,S603
#Todo: Clean up tests
modopt/tests/*.py: E731,F401,WPS301,WPS420,WPS425,WPS437,WPS604
#Todo: Import has bad parenthesis
modopt/tests/test_base.py: WPS318,WPS319,E501,WPS301
#WPS Settings
max-arguments = 25
max-attributes = 40
Expand Down