Skip to content

Commit

Permalink
Merge pull request #57 from MJOLNIRPackage/develop
Browse files Browse the repository at this point in the history
Test suite update
  • Loading branch information
Jakob-Lass committed Aug 27, 2020
2 parents 929eb1a + 8cb304a commit f1a4dc5
Show file tree
Hide file tree
Showing 55 changed files with 4,202 additions and 3,346 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ Report/
*/.coverage*

coverage_html_report
samlpedata/*
docs/Commissioning/*
122 changes: 100 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,113 @@ services:
- xvfb

language: python
# ===== Linux ======

python:
- "3.5"
- "3.6"
- "3.7"
- "3.8"


#before_install:
#- sudo apt-get -qq update && sudo apt-get install -y --no-install-recommends texlive-fonts-recommended texlive-latex-extra texlive-fonts-extra dvipng texlive-latex-recommended


before_script: # configure a headless display to test plot generation
# - xvfb-run --server-args="-screen 0 1024x768x24"
- sleep 3 # give xvfb some time to start
# - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1280x1024x24"


install:
- 3.5
- 3.6
- 3.7
- 3.8
matrix:
include:
- name: "Python 3.7.5 on macOS 10.14"
os: osx
osx_image: xcode10.2 # Python 3.7.5 running on macOS 10.14.3
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- python3 --version
- sleep 3 # give xvfb some time to start
- pip3 install -U pip
- pip install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- pip install .
- wget -UseBasicParsing 'https://www.psi.ch/en/media/60041/download'
- unzip download
script: py.test test/ -vv
- name: "Python 3.8.0 on macOS 10.14"
os: osx
osx_image: xcode11.3 # Python 3.8.0 running on macOS 10.14.6
language: shell # 'language: python' is an error on Travis CI macOS
before_install:
- python3 --version
- sleep 3 # give xvfb some time to start
- pip3 install -U pip
- pip install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- pip install .
- wget -UseBasicParsing 'https://www.psi.ch/en/media/60041/download'
- unzip download
script: py.test test/ -vv
- name: "Python 3.5.4 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.5.4
- python --version
- sleep 3 # give xvfb some time to start
- python -m pip install --upgrade pip
- pip3 install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- python setup.py sdist
- pip3 install .
- curl -o download.zip https://www.psi.ch/en/media/60041/download
- 7z e download.zip "-osamlpedata"
script: py.test test/ -vv
env: PATH=/c/Python35:/c/Python35/Scripts:$PATH
- name: "Python 3.6.8 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.6.8
- python --version
- sleep 3 # give xvfb some time to start
- python -m pip install --upgrade pip
- pip3 install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- python setup.py sdist
- pip3 install .
- curl -o download.zip https://www.psi.ch/en/media/60041/download
- 7z e download.zip "-osamlpedata"
env: PATH=/c/Python36:/c/Python36/Scripts:$PATH
- name: "Python 3.7.9 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.7.9
- python --version
- sleep 3 # give xvfb some time to start
- python -m pip install --upgrade pip
- pip3 install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- python setup.py sdist
- pip3 install .
- curl -o download.zip https://www.psi.ch/en/media/60041/download
- 7z e download.zip "-osamlpedata"
env: PATH=/c/Python37:/c/Python37/Scripts:$PATH
- name: "Python 3.8.5 on Windows"
os: windows # Windows 10.0.17134 N/A Build 17134
language: shell # 'language: python' is an error on Travis CI Windows
before_install:
- choco install python --version 3.8.5
- python --version
- sleep 3 # give xvfb some time to start
- python -m pip install --upgrade pip
- pip3 install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- python setup.py sdist
- pip3 install .
- curl -o download.zip https://www.psi.ch/en/media/60041/download
- 7z e download.zip "-osamlpedata"
env: PATH=/c/Python38:/c/Python38/Scripts:$PATH
before_install:
- pip install pytest>=3.6 pycodestyle python-coveralls pytest-cov>=2.5 coveralls
- pip install --upgrade pip
- pip install .
# - pip install -r requirements.txt
- wget 'https://www.psi.ch/en/media/60041/download'
- unzip download

#before_script:
# - if [ "$TRAVIS_OS_NAME" = "linux" ]; then export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start; sleep 3; fi

script:
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then py.test MJOLNIR/ -vv --cov=MJOLNIR/; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then py.test MJOLNIR/ -vv --ignore=MJOLNIR/CommandLineScripts/MJOLNIRHistory.py --ignore=MJOLNIR/CommandLineScripts/MJOLNIRCalibrationInspector.py --ignore=MJOLNIR/CommandLineScripts/MJOLNIR3DView.py --ignore=MJOLNIR/CommandLineScripts/MJOLNIRConvert.py; fi
- if [[ $TRAVIS_PYTHON_VERSION > 3.6 ]]; then py.test MJOLNIR/ -vv; fi
- if [[ $TRAVIS_PYTHON_VERSION < 3.5 ]]; then py.test MJOLNIR/ -vv; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]]; then py.test test/ -vv --cov=test/; fi
- if [[ $TRAVIS_PYTHON_VERSION == 3.5 ]]; then py.test test/ -vv --ignore=test/CommandLineScripts/MJOLNIRHistory.py --ignore=test/CommandLineScripts/MJOLNIRCalibrationInspector.py --ignore=test/CommandLineScripts/MJOLNIR3DView.py --ignore=test/CommandLineScripts/MJOLNIRConvert.py; fi
- if [[ $TRAVIS_PYTHON_VERSION > 3.6 ]]; then py.test test/ -vv; fi
- if [[ $TRAVIS_PYTHON_VERSION < 3.5 ]]; then py.test test/ -vv; fi

after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 ]];
Expand Down
Binary file removed Data/camea2018n000017.hdf
Binary file not shown.
Binary file removed Data/camea2018n000017.nxs
Binary file not shown.
Binary file removed Data/camea2018n000017.nxs_old
Binary file not shown.
Binary file removed Data/camea2018n000038.hdf
Binary file not shown.
Binary file removed Data/camea2018n000038.nxs_old
Binary file not shown.
Binary file removed Data/camea2018n000136.hdf
Binary file not shown.
Binary file removed Data/camea2018n000136.nxs
Binary file not shown.
Binary file removed Data/camea2018n000136.nxs_old
Binary file not shown.
Binary file removed Data/camea2018n000137.hdf
Binary file not shown.
Binary file removed Data/camea2018n000137.nxs
Binary file not shown.
Binary file removed Data/camea2018n000137.nxs_old
Binary file not shown.
Binary file removed Data/camea2018n000178.hdf
Binary file not shown.
Binary file removed Data/camea2018n000178.nxs
Binary file not shown.
Binary file removed Data/camea2018n000178.nxs_old
Binary file not shown.
5 changes: 2 additions & 3 deletions MJOLNIR/CommandLineScripts/MJOLNIR3DView.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import argparse
import numpy as np
import matplotlib.pyplot as plt
plt.ion()

import os
import sys
from MJOLNIR.CommandLineScripts import _tools
Expand Down Expand Up @@ -62,7 +62,6 @@

V.caxis = [VMin,VMax]

plt.show()

def main():
pass
plt.show()
27 changes: 15 additions & 12 deletions MJOLNIR/CommandLineScripts/MJOLNIRCalibrationInspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import matplotlib.pyplot as plt
import matplotlib._pylab_helpers

plt.ion()

from MJOLNIR.CommandLineScripts import _tools
import sys,os
settingsName = 'CalibrationInspectorDir'
Expand Down Expand Up @@ -47,9 +45,20 @@ def switch(argument):

args = parser.parse_args()

file = _tools.extractDataFiles(args,settingsName,oneFile=True)
if not args.save is '':
saveFile = True
saveLocation = os.path.realpath(args.save.strip())
if not os.path.exists(saveLocation):
os.mkdir(saveLocation)
else:
if not os.path.isdir(saveLocation):
raise FileNotFoundError("[Errno 2] No such file or directory: '{}'".format(saveLocation))
else:
saveFile = False

file = _tools.extractDataFiles(args,settingsName,oneFile=True)[0]

directory = os.path.split(file)[0]
directory = os.path.split(file)

_tools.updateSetting(settingsName,directory)

Expand All @@ -68,12 +77,6 @@ def switch(argument):



if not args.save is '':
saveFile = True
saveLocation = os.path.realpath(args.save.strip())
else:
saveFile = False

File = DataFile.DataFile(file)

for id in argsIdx:
Expand Down Expand Up @@ -115,7 +118,7 @@ def switch(argument):
f.savefig(os.path.join(saveLocation,title+'.png'))


plt.show()


def main():
pass
plt.show()
67 changes: 32 additions & 35 deletions MJOLNIR/CommandLineScripts/test_commandline.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,32 @@
from MJOLNIR.Data import DataFile
import subprocess
import os
import os,sys
import pytest

dataFiles = ['Data/camea2018n000136.hdf','Data/camea2018n000136.nxs',
'Data/camea2018n000137.nxs',
'Data/camea2018n000178.hdf']

multiFLEXXDataFiles = ['/home/lass/Dropbox/PhD/Software/MJOLNIR/Data/065059']
dataFiles = [os.path.join('Data',f) for f in ['camea2018n000136.hdf','camea2018n000136.nxs',
'camea2018n000137.nxs',
'camea2018n000178.hdf']]

returnText = [b'camea2018n000136.hdf: sc a3 0 da3 0.5 np 121 mn 150000 A3 scan around 1 0 0 YMnO3 T=10, 2T= -20\n',
b'camea2018n000136.nxs: sc a3 0 da3 0.5 np 121 mn 150000 A3 scan around 1 0 0 YMnO3 T=10, 2T= -20\n',
b'camea2018n000137.nxs: sc a3 0 da3 0.5 np 121 mn 150000 A3 scan around 1 0 0 YMnO3 T=10, 2T= -24\n',
b'camea2018n000178.hdf: sc a3 0 da3 1 np 181 mn 100000 PbTi T=1.5K Ei=5.5 2t=-10 HHL plane around 1 1 0\n'
]


if sys.platform == 'win32':
returnText = [t[:-1] + b'\r\n' for t in returnText]


## Calibration inspector

def test_CalibrationInspector_Help_Text():
result = subprocess.check_output(['MJOLNIRCalibrationInspector','-h'])
helpText = b"""usage: MJOLNIRCalibrationInspector [-h] [-s SAVE]
[-p [PLOTLIST [PLOTLIST ...]]] [-b BINNING]
[DataFile]
Inspection tool to visualize calibration tables in a data file.
if sys.platform == 'win32':
print(result)
helpText = b'usage: MJOLNIRCalibrationInspector [-h] [-s SAVE]\r\n [-p [PLOTLIST [PLOTLIST ...]]] [-b BINNING]\r\n [DataFile]\r\n\r\nInspection tool to visualize calibration tables in a data file.\r\n\r\npositional arguments:\r\n DataFile Data file from which calibration table is to be\r\n plotted. If none provided file dialogue will appear.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -s SAVE, --save SAVE Location to which the generated file will be saved.\r\n -p [PLOTLIST [PLOTLIST ...]], --plot [PLOTLIST [PLOTLIST ...]]\r\n List of wanted plots to be generated. Should be\r\n "A4","Normalization","Ef","EfOverview". Default all of\r\n them.\r\n -b BINNING, --binning BINNING\r\n Binning to be inspected. Default \'8\'\r\n'
else:
helpText = b'usage: MJOLNIRCalibrationInspector [-h] [-s SAVE]\n [-p [PLOTLIST [PLOTLIST ...]]] [-b BINNING]\n [DataFile]\n\nInspection tool to visualize calibration tables in a data file.\n\npositional arguments:\n DataFile Data file from which calibration table is to be\n plotted. If none provided file dialogue will appear.\n\noptional arguments:\n -h, --help show this help message and exit\n -s SAVE, --save SAVE Location to which the generated file will be saved.\n -p [PLOTLIST [PLOTLIST ...]], --plot [PLOTLIST [PLOTLIST ...]]\n List of wanted plots to be generated. Should be\n "A4","Normalization","Ef","EfOverview". Default all of\n them.\n -b BINNING, --binning BINNING\n Binning to be inspected. Default \'8\'\n'

positional arguments:
DataFile Data file from which calibration table is to be
plotted. If none provided file dialogue will appear.
optional arguments:
-h, --help show this help message and exit
-s SAVE, --save SAVE Location to which the generated file will be saved.
-p [PLOTLIST [PLOTLIST ...]], --plot [PLOTLIST [PLOTLIST ...]]
List of wanted plots to be generated. Should be
"A4","Normalization","Ef","EfOverview". Default all of
them.
-b BINNING, --binning BINNING
Binning to be inspected. Default '8'
"""
assert(result == helpText)

@pytest.mark.skip(reason="Fails on the headless Travis-ci")
Expand All @@ -67,7 +52,11 @@ def test_CalibrationInsepctor_Run():

def test_History_Help_Text():
result = subprocess.check_output(['MJOLNIRHistory', '-h'])
helpText = b"""usage: MJOLNIRHistory [-h] [-s SAVE] [-r] [DataFile [DataFile ...]]
if sys.platform == 'win32':
print(result)
helpText = b'usage: MJOLNIRHistory [-h] [-s SAVE] [-r] [DataFile [DataFile ...]]\r\n\r\nHistory tool for displaying files and command for selected data files.\r\n\r\npositional arguments:\r\n DataFile Data file(s) to be used. If none provided file\r\n dialogue will appear. Using string format, directory\r\n and year is also possible. See documentation.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -s SAVE, --save SAVE Location to which the generated history will be saved.\r\n -r, --reuse Set flag to reuse files from previous usage. Default\r\n false.\r\n'
else:
helpText = b"""usage: MJOLNIRHistory [-h] [-s SAVE] [-r] [DataFile [DataFile ...]]
History tool for displaying files and command for selected data files.
Expand Down Expand Up @@ -113,7 +102,11 @@ def test_History_MultipleFiles_repeat():

def test_Convert_Help_Text():
result = subprocess.check_output(['MJOLNIRConvert', '-h'])
helpText = b"""usage: MJOLNIRConvert [-h] [-s SAVE] [-b BINNING] [-r]
if sys.platform == 'win32':
print(result)
helpText = b"usage: MJOLNIRConvert [-h] [-s SAVE] [-b BINNING] [-r]\r\n [DataFile [DataFile ...]]\r\n\r\nConversion tool for converting output h5 files to nxs files.\r\n\r\npositional arguments:\r\n DataFile Data file(s) to be used. If none provided file\r\n dialogue will appear. Using string format, directory\r\n and year is also possible. See documentation.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -s SAVE, --save SAVE Location to which the generated file will be saved.\r\n -b BINNING, --binning BINNING\r\n Binning performed. Default '8'\r\n -r, --reuse Set flag to reuse files from previous usage. Default\r\n false.\r\n"
else:
helpText = b"""usage: MJOLNIRConvert [-h] [-s SAVE] [-b BINNING] [-r]
[DataFile [DataFile ...]]
Conversion tool for converting output h5 files to nxs files.
Expand All @@ -140,15 +133,15 @@ def test_Convert_binning():
assert(f.binning == 8)
subprocess.check_output(['MJOLNIRConvert',dataFiles[0],'-b 1'])
f = DataFile.DataFile(dataFiles[0].replace('hdf','nxs'))
assert(f.name == dataFiles[0].split('/')[1].replace('hdf','nxs'))
assert(f.name == dataFiles[0].split(os.path.sep)[1].replace('hdf','nxs'))
assert(f.binning == 1)

def test_Convert_SaveLocation():
if not os.path.isdir('Data/Data'):
os.makedirs('Data/Data')
subprocess.check_output(['MJOLNIRConvert',dataFiles[0],'-s Data/'])
fileName = dataFiles[0].split('/')[1].replace('hdf','nxs')
f = DataFile.DataFile('Data/'+fileName)
if not os.path.isdir(os.path.join('Data','Data')):
os.makedirs(os.path.join('Data','Data'))
subprocess.check_output(['MJOLNIRConvert',dataFiles[0],'-s Data'+os.path.sep])
fileName = dataFiles[0].split(os.path.sep)[1].replace('hdf','nxs')
f = DataFile.DataFile('Data'+os.path.sep+fileName)

assert(f.binning == 8)
print(fileName)
Expand All @@ -171,7 +164,11 @@ def test_Convert_Reuse():
### 3DView
def test_3DView_Help_Text():
result = subprocess.check_output(['MJOLNIR3DView','-h'])
helpText = b"""usage: MJOLNIR3DView [-h] [-r] [-b BINNING] [-d DQXDQYDE DQXDQYDE DQXDQYDE]
print(result)
if sys.platform == 'win32':
helpText = b"usage: MJOLNIR3DView [-h] [-r] [-b BINNING] [-d DQXDQYDE DQXDQYDE DQXDQYDE]\r\n [-M VMAX] [-m VMIN]\r\n [DataFile [DataFile ...]]\r\n\r\nConversion tool for quick visualization using the viewer3D.\r\n\r\npositional arguments:\r\n DataFile Data file(s) to be used. If none provided file\r\n dialogue will appear. Using string format, directory\r\n and year is also possible. See documentation.\r\n\r\noptional arguments:\r\n -h, --help show this help message and exit\r\n -r, --reuse Set flag to reuse files from previous usage. Default\r\n false.\r\n -b BINNING, --binning BINNING\r\n Binning performed. Default '8'\r\n -d DQXDQYDE DQXDQYDE DQXDQYDE, --dQxdQydE DQXDQYDE DQXDQYDE DQXDQYDE\r\n Binning used to plot in 3D, Default [0.03,0.03,0.08]\r\n -M VMAX, --VMax VMAX Maximal value for plotting, default max of data\r\n -m VMIN, --VMin VMIN Minimal value for plotting, default min of data\r\n"
else:
helpText = b"""usage: MJOLNIR3DView [-h] [-r] [-b BINNING] [-d DQXDQYDE DQXDQYDE DQXDQYDE]
[-M VMAX] [-m VMIN]
[DataFile [DataFile ...]]
Expand Down

0 comments on commit f1a4dc5

Please sign in to comment.