Skip to content
Snippets Groups Projects
Commit 23311884 authored by Maximilian Schanner's avatar Maximilian Schanner
Browse files

Merge branch 'tests' into 'master'

Tests

See merge request arthus/pymagglobal!8
parents 51e02618 d8f47c8e
No related branches found
No related tags found
1 merge request!8Tests
tests:
stage: test
script: python setup.py test
image: continuumio/miniconda3
build-job:
stage: build
script:
- conda install conda-build
- conda build -c conda-forge FieldTools
- conda build purge
- conda build -c local -c conda-forge ./
- conda build purge
# To some reason setting CONDA_BLD_PATH=conda_bld does not work
- mv /opt/conda/conda-bld ./conda_bld
artifacts:
paths:
- conda_bld
pages:
stage: deploy
test-job:
stage: test
script:
- python3 setup.py build_sphinx
- mv build/sphinx/html public
- export CONDA_BLD_PATH=conda_bld # Received packages as artifacts
- conda install -c local -c conda-forge pymagglobal packaging
- python tests/run_tests.py
artifacts:
paths:
- public
only:
- master
- ./docs/pic_mst.png
- ./docs/pic_map.png
- ./docs/pic_dip.png
- ./docs/pic_cfe.png
- ./docs/pic_cfs.png
......@@ -458,9 +458,9 @@ def maps(args):
f'{args.epoch} {args.t_unit}')
for it in range(3):
axs[it].tripcolor(plt_lat, plt_lon, field[it],
vmin=vmins[it], vmax=vmaxs[it],
rasterized=True, cmap=cmaps[it])
mappable = axs[it].tripcolor(plt_lat, plt_lon, field[it],
vmin=vmins[it], vmax=vmaxs[it],
rasterized=True, cmap=cmaps[it])
axs[it].coastlines(alpha=0.8, lw=0.5)
axs[it].set_global()
axs[it].set_title(f'{utils._names[args.type][it]} [{units[it]}]')
......@@ -470,9 +470,7 @@ def maps(args):
bnds[1]-0.1-cbar_hght,
bnds[2],
cbar_hght])
norm = colors.Normalize(vmin=vmins[it],
vmax=vmaxs[it])
fig.colorbar(cm.ScalarMappable(norm=norm, cmap=cmaps[it]),
fig.colorbar(mappable,
cax=colax,
orientation='horizontal')
return fig
import unittest
import doctest
from pathlib import PurePath
from pymagglobal import utils
from pymagglobal import _commands
def test_suite():
'''To be called in setup.py
XXX Deprecated since 3.8'''
tests_path = PurePath(__file__).parent
# By convention discovers TestCases in test_*.py
suite = unittest.TestLoader().discover(tests_path)
# Add doc-test manually
suite.addTest(doctest.DocTestSuite(utils))
suite.addTest(doctest.DocTestSuite(_commands))
return suite
import unittest
import io
import sys
from matplotlib import pyplot as plt
from pymagglobal import models
from test_argument_parser import _SetUpCls
class Commands(_SetUpCls):
@unittest.skip('not yet implemented')
def test_usage_ex_master(self):
from pymagglobal.__main__ import mst_ex_ofn, mst_ex_cmd
nsp = self.parser.parse_args(mst_ex_cmd.split()[1:])
#nsp.func(nsp)
#plt.savefig('./docs/' + mst_ex_ofn)
@unittest.skip('not yet implemented')
def test_usage_ex_dipole(self):
from pymagglobal.__main__ import dip_ex_ofn, dip_ex_cmd
nsp = self.parser.parse_args(dip_ex_cmd.split()[1:])
#nsp.func(nsp)
#plt.savefig('./docs/' + mst_ex_ofn)
@unittest.skip('not yet implemented')
def test_usage_ex_map(self):
from pymagglobal.__main__ import map_ex_ofn, map_ex_cmd
nsp = self.parser.parse_args(map_ex_cmd.split()[1:])
#nsp.func(nsp)
#plt.savefig('./docs/' + mst_ex_ofn)
......@@ -105,5 +105,4 @@ setup(
f'pymagglobal.__main__:main']},
cmdclass=cmdclass,
command_options=command_options,
test_suite='pymagglobal.tests.test_suite',
)
import sys
from pathlib import PurePath
import unittest
import doctest
import matplotlib
matplotlib.use('Agg') # Select a headless backend
from pymagglobal import utils
from pymagglobal import _commands
# Fetch relative path
tests_path = PurePath(__file__).parent
# By convention the TestLoader discovers TestCases in test_*.py
suite = unittest.TestLoader().discover(tests_path)
# Add all doc-tests manually
suite.addTest(doctest.DocTestSuite(utils))
suite.addTest(doctest.DocTestSuite(_commands))
if __name__ == '__main__':
# Set up a test-runner
runner = unittest.TextTestRunner(verbosity=2)
# Collect test results
result = runner.run(suite)
# If not successful return 1
sys.exit(not result.wasSuccessful())
......@@ -35,6 +35,7 @@ class ParserTestGlobal(_SetUpCls):
'''Check if `--list-models` terminates successfully'''
with self.assertRaises(SystemExit) as cm:
# Redirect stdout not to pollute output the terminal
# FIXME: stdout remains redirected and suppresses potential output
sys.stdout = io.StringIO()
# Pass list since sys.argv splits at white space (filename
# stripped)
......@@ -46,12 +47,6 @@ class ParserTestGlobal(_SetUpCls):
class ParserTestMaster(_SetUpCls):
'''Test-cases from the `master` sub-command'''
def test_master_valid(self):
'''Check if a syntactically proper string is parsed without error'''
# TODO: Grab that command from 'example of use'
cmd = 'pymagglobal master --no-show 12 12 gufm1'
nsp = self.parser.parse_args(cmd.split()[1:])
def test_master_exclusive_res_every(self):
'''Raise if both, --res and --every are specified'''
cmd = 'pymagglobal master --no-show --res=20 --every=12 12 12 gufm1'
......@@ -69,23 +64,42 @@ class ParserTestMaster(_SetUpCls):
def test_command_run(self):
''' Check if the example runs flawlessly '''
from pymagglobal.__main__ import mst_ex_cmd as cmd
from pymagglobal.__main__ import mst_ex_cmd as cmd, mst_ex_ofn as ofn
nsp = self.parser.parse_args(cmd.split()[1:])
nsp.func(nsp)
fig = nsp.func(nsp)
# TODO: use --no-show together with --savefig
fig.savefig(f'./docs/{ofn}', bbox_inches='tight')
class ParserTestMap(_SetUpCls):
'''Test-cases from the `map` sub-command'''
def test_custom_model(self):
cmd = 'map 1500 ./pymagglobal/dat/arhimag1k'
'''Check whether a file-name passed is treated as a custom model'''
from pymagglobal import models
cmd = 'map 1500 ' + models['arhimag1k']
nsp = self.parser.parse_args(cmd.split())
self.assertEqual(nsp.model.name, 'custom model')
def test_custom_model_raises(self):
'''Check if a wrong file-name throws FileNotFoundError'''
cmd = 'map 1500 ./non_existent_file'
self.assertRaises(FileNotFoundError,
self.parser.parse_args, cmd.split())
def test_usage_valid(self):
'''Check if the example of us is parsed without error'''
from pymagglobal.__main__ import map_ex_cmd as cmd
nsp = self.parser.parse_args(cmd.split()[1:])
def test_command_run(self):
''' Check if the example runs flawlessly '''
from pymagglobal.__main__ import map_ex_cmd as cmd, map_ex_ofn as ofn
nsp = self.parser.parse_args(cmd.split()[1:])
fig = nsp.func(nsp)
# TODO: use --no-show together with --savefig
fig.savefig(f'./docs/{ofn}', bbox_inches='tight')
class ParserTestDipole(_SetUpCls):
'''Test-cases from the `dipole` sub-command'''
......@@ -95,7 +109,15 @@ class ParserTestDipole(_SetUpCls):
from pymagglobal.__main__ import dip_ex_cmd as cmd
nsp = self.parser.parse_args(cmd.split()[1:])
def test_longerm(self):
def test_command_run(self):
''' Check if the example runs flawlessly '''
from pymagglobal.__main__ import dip_ex_cmd as cmd, dip_ex_ofn as ofn
nsp = self.parser.parse_args(cmd.split()[1:])
fig = nsp.func(nsp)
# TODO: use --no-show together with --savefig
fig.savefig(f'./docs/{ofn}', bbox_inches='tight')
def test_longterm(self):
cmd = 'dipole --longterm LSMOD.2'
nsp = self.parser.parse_args(cmd.split())
self.assertEqual(nsp.t_unit, 'ka')
......@@ -116,6 +138,15 @@ class ParserTestCoefficientsEpoch(_SetUpCls):
from pymagglobal.__main__ import cfe_ex_cmd as cmd
nsp = self.parser.parse_args(cmd.split()[1:])
def test_command_run(self):
''' Check if the example runs flawlessly '''
from pymagglobal.__main__ import cfe_ex_cmd as cmd, cfe_ex_ofn as ofn
nsp = self.parser.parse_args(cmd.split()[1:])
fig = nsp.func(nsp)
# TODO: use --no-show together with --savefig
fig.savefig(f'./docs/{ofn}', bbox_inches='tight')
class ParserTestCoefficientSeries(_SetUpCls):
'''Test-cases from the `coeff-series` sub-command'''
......@@ -126,6 +157,8 @@ class ParserTestCoefficientSeries(_SetUpCls):
def test_command_run(self):
''' Check if the example runs flawlessly '''
from pymagglobal.__main__ import cfs_ex_cmd as cmd
from pymagglobal.__main__ import cfs_ex_cmd as cmd, cfs_ex_ofn as ofn
nsp = self.parser.parse_args(cmd.split()[1:])
nsp.func(nsp)
fig = nsp.func(nsp)
# TODO: use --no-show together with --savefig
fig.savefig(f'./docs/{ofn}', bbox_inches='tight')
......@@ -8,6 +8,7 @@ import pymagglobal
# Not a test-case since `import *` is only allowed at module level
from pymagglobal import *
class ParserTestPackage(unittest.TestCase):
'''Unit-tests for the package i.e. __init__.py'''
......@@ -17,6 +18,6 @@ class ParserTestPackage(unittest.TestCase):
def test_models(self):
'''Check if built-in model-files exist'''
for model_fn in models.values():
for model_fn in pymagglobal.models.values():
with self.subTest(msg=model_fn):
self.assertTrue(Path(model_fn).is_file())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment