Commit d91d9756 authored by Carsten Richter's avatar Carsten Richter

Merge branch 'win-ci' into 'master'

Run tests on Windows as part of continuous integration

See merge request !110
parents 53880cab cab33388
Pipeline #7085 passed with stages
in 6 minutes and 53 seconds
......@@ -9,9 +9,14 @@ variables: # Global variables
https_proxy: http://proxy.esrf.fr:3128
no_proxy: .esrf.fr,localhost
### Linux ###
# Target definitions
.build_template: &build_definition
.linux_build_template: &linux_build_definition
stage: build
tags:
- linux
image: ${IMAGE}
before_script:
- rm -rf ${VENV_DIR}
......@@ -35,8 +40,10 @@ variables: # Global variables
when: on_success
expire_in: 2h
.test_template: &test_definition
.linux_test_template: &linux_test_definition
stage: test
tags:
- linux
image: ${IMAGE}
before_script:
- rm -rf ${VENV_DIR}
......@@ -58,45 +65,47 @@ variables: # Global variables
# Python2 tasks
.python2_variables:
variables: &python2_definition
.linux_python2_variables:
variables: &linux_python2_definition
IMAGE: python:2.7-jessie
PYTHON: python2
build_python2:
<<: *build_definition
variables: *python2_definition
linux_build_python2:
<<: *linux_build_definition
variables: *linux_python2_definition
test_python2:
<<: *test_definition
linux_test_python2:
<<: *linux_test_definition
dependencies:
- build_python2
variables: *python2_definition
- linux_build_python2
variables: *linux_python2_definition
# Python3 tasks
.python3_variables:
variables: &python3_definition
.linux_python3_variables:
variables: &linux_python3_definition
IMAGE: python:3.4-jessie
PYTHON: python3
build_python3:
<<: *build_definition
variables: *python3_definition
linux_build_python3:
<<: *linux_build_definition
variables: *linux_python3_definition
test_python3:
<<: *test_definition
linux_test_python3:
<<: *linux_test_definition
dependencies:
- build_python3
variables: *python3_definition
- linux_build_python3
variables: *linux_python3_definition
### Documentation ###
# Deploy documentation in gitlab (only for master branch)
pages:
stage: deploy
image: python:3.4-jessie
dependencies:
- build_python3
- linux_build_python3
script:
- rm -rf public
- mv build/sphinx/html public
......@@ -105,3 +114,48 @@ pages:
- public
only:
- master
### Windows ###
.windows_template: &windows_definition
tags:
- win
before_script:
- SET "PATH=C:\\miniconda3;C:\\miniconda3\\Scripts;%PATH%"
- python -m venv --clear %VENV_DIR%
- call "%VENV_DIR%\\Scripts\\activate.bat"
- python -m pip install --upgrade pip
- python ci\info_platform.py
script:
after_script:
- rmdir %VENV_DIR% /s /q
windows_build_python3:
<<: *windows_definition
stage: build
script:
- pip install --upgrade -r requirements-dev.txt
- python ci\info_platform.py
# Build the wheel
- python setup.py bdist_wheel
- dir dist
artifacts:
paths:
- dist
when: on_success
expire_in: 2h
windows_test_python3:
<<: *windows_definition
stage: test
dependencies:
- windows_build_python3
script:
# Install numpy first as it is needed to build xrayutilities
- pip install numpy --only-binary numpy
- pip install h5py fabio scipy silx xrayutilities --only-binary scipy,h5py,silx,fabio
- python ci\info_platform.py
# Install wheel and run the tests
- pip install --pre --find-links dist/ --no-cache-dir --no-index xsocs
- python run_tests.py --installed -v
......@@ -455,7 +455,8 @@ class BuildExt(build_ext):
from Cython.Build import cythonize
patched_exts = cythonize(
[ext],
compiler_directives={'embedsignature': True},
compiler_directives={'embedsignature': True,
'language_level': 3},
force=self.force_cython
)
ext.sources = patched_exts[0].sources
......
......@@ -251,6 +251,17 @@ class FitResult(object):
def __eq__(self, other):
"""Implement equality, useful for tests"""
return self.almost_equal(other, rtol=0., atol=0.)
def almost_equal(self, other, rtol=1e-5, atol=1e-8):
"""Implement almost equal comparison, useful for tests
:param FitResult other: The other FitResult to compare to
:param float rtol: The relative tolerance.
See :func:`numpy.allclose` for details.
:param float atol: The absolute tolerance.
See :func:`numpy.allclose` for details.
"""
return (
isinstance(other, FitResult) and
numpy.array_equal(self.sample_x, other.sample_x) and
......@@ -260,10 +271,18 @@ class FitResult(object):
other.qspace_dimension_values)]) and
(tuple(self.qspace_dimension_names) ==
tuple(other.qspace_dimension_names)) and
numpy.array_equal(self.roi_indices, self.roi_indices) and
numpy.array_equal(self.roi_indices, other.roi_indices) and
self.fit_mode == other.fit_mode and
self.background_mode == self.background_mode and
numpy.array_equal(self._fit_results, other._fit_results))
self.background_mode == other.background_mode and
(set(self.available_result_names) ==
set(other.available_result_names)) and
numpy.all([numpy.allclose(ary1[param],
ary2[param],
rtol=rtol,
atol=atol)
for param in self.available_result_names
for ary1, ary2 in zip(self._fit_results,
other._fit_results)]))
class PeakFitter(object):
......
......@@ -33,6 +33,7 @@ __date__ = "05/01/2016"
import os
import shutil
import sys
import tempfile
import unittest
......@@ -68,6 +69,17 @@ class TestPeakFitter(ParametricTestCase):
shutil.rmtree(self._tmpTestDir)
self._tmpTestDir = None
def _assertResultAlmostEqual(self, ref, result):
"""Compare FitResults are equal on Linux and almost equal on Windows
:param FitResult ref:
:param FitResult result:
"""
if sys.platform == 'win32':
self.assertTrue(ref.almost_equal(result))
else:
self.assertEqual(ref, result)
def test_gaussian(self):
"""Test gaussian fit"""
for fit_f, qspace_f in zip(self._GAUSSIAN_FILES, self._QSPACE_FILES):
......@@ -86,12 +98,13 @@ class TestPeakFitter(ParametricTestCase):
# Compare results
ref = FitResult.from_fit_h5(
test_resources.getfile('fit_2018_12/' + fit_f))
self.assertEqual(ref, fitter.results)
self._assertResultAlmostEqual(ref, fitter.results)
# Save as HDF5 and compare
fit_out = os.path.join(self._tmpTestDir, fit_f)
fitter.results.to_fit_h5(fit_out)
self.assertEqual(ref, FitResult.from_fit_h5(fit_out))
self._assertResultAlmostEqual(ref,
FitResult.from_fit_h5(fit_out))
def test_com(self):
"""Test Center-of-mass and Max reduction"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment