Skip to content

Commit

Permalink
Merge pull request mantidproject#20348 from rosswhitfield/misc_python…
Browse files Browse the repository at this point in the history
…3_systemtests

Fix a few misc systemtests for python3
  • Loading branch information
martyngigg authored Aug 30, 2017
2 parents 4c95572 + 04f130b commit 66ec89d
Show file tree
Hide file tree
Showing 48 changed files with 264 additions and 232 deletions.
3 changes: 2 additions & 1 deletion Testing/SystemTests/tests/analysis/BuildSQWTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
the result file that is ~30Gb. The files are not included with the standard
repository & required to be accessible from any machine that wishes to run the test.
"""
from __future__ import (absolute_import, division, print_function)
import stresstesting
import os
from mantid.simpleapi import *
Expand Down Expand Up @@ -70,7 +71,7 @@ def runTest(self):
if os.path.exists(target):
os.remove(target)

print "Converting '%s' to '%s' " % (source_path,target)
print("Converting '%s' to '%s' " % (source_path,target))
_cur_spe_ws = LoadNXSPE(Filename=source_path)
SetUB(Workspace=_cur_spe_ws,a='2.87',b='2.87',c='2.87')
# rotated by proper number of degrees around axis Y
Expand Down
1 change: 1 addition & 0 deletions Testing/SystemTests/tests/analysis/CRISPLoadingTest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import (absolute_import, division, print_function)
from LoadAndCheckBase import *


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#pylint: disable=invalid-name,no-init,attribute-defined-outside-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
import os
from mantid.simpleapi import *
from six import string_types


def _skip_test():
Expand Down Expand Up @@ -41,7 +43,7 @@ def runTest(self):
MaxOffset=0.01, PeakPositions = '.6866,.7283,.8185,.8920,1.0758,1.2615,2.0599',
CrossCorrelation = False, RunNumber = 'PG3_2538')

if isinstance(output, basestring):
if isinstance(output, string_types):
self.saved_cal_file = output.replace('.h5','.cal')
else:
raise NotImplementedError("Output from CalibrateRectangularDetectors is NOT string for calibration file name!")
Expand Down Expand Up @@ -89,7 +91,7 @@ def runTest(self):
MaxOffset=0.01, PeakPositions = '0.7282933,1.261441',DetectorsPeaks = '17,6',
CrossCorrelation = True, RunNumber = 'PG3_2538')

if isinstance(output, basestring):
if isinstance(output, string_types):
self.saved_cal_file = output.replace('.h5','.cal')
else:
raise NotImplementedError("Output from CalibrateRectangularDetectors is NOT string for calibration file name!")
Expand Down
43 changes: 23 additions & 20 deletions Testing/SystemTests/tests/analysis/CodeConventions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pylint: disable=no-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
import re
import mantid
from mantid.simpleapi import *
from six.moves import range
from six import iteritems

MAX_ALG_LEN = 40 # TODO convention says 20 is the maximum

Expand Down Expand Up @@ -80,24 +83,24 @@ def __init__(self):

def verifyAlgName(self, name):
if not self.algRegExp.match(name):
print "Algorithm " + name + " has a name that violates conventions"
print("Algorithm " + name + " has a name that violates conventions")
return False

if bool(len(name) > MAX_ALG_LEN):
print "%s has a name that is longer than " % name, \
"%d characters (%d > %d)" % (MAX_ALG_LEN, len(name), MAX_ALG_LEN)
print("%s has a name that is longer than " % name,
"%d characters (%d > %d)" % (MAX_ALG_LEN, len(name), MAX_ALG_LEN))
return False

# passed all of the checks
return True

def verifyCategories(self, name, categories):
if len(categories) <= 0:
print name + " has no categories"
print(name + " has no categories")

for category in categories:
if not self.categoryRegExp.match(category):
print name + " has a bad category " + category
print(name + " has a bad category " + category)
return False

return True
Expand All @@ -112,13 +115,13 @@ def verifyProperty(self, alg_descr, name):
upper = name.upper()
if (upper in SPECIAL_UPPER) and (name not in SPECIAL):
index = SPECIAL_UPPER.index(upper)
print alg_descr + " property (" + name + ") has special name "\
+ "with wrong case: " + name + " should be " + SPECIAL[index]
print(alg_descr + " property (" + name + ") has special name "
+ "with wrong case: " + name + " should be " + SPECIAL[index])
return False

if not self.paramRegExp.match(name):
if not self.checkAllowed(alg_descr, name):
print alg_descr + " property (" + name +") violates conventions"
print(alg_descr + " property (" + name +") violates conventions")
return False

# passed all of the checks
Expand All @@ -127,7 +130,7 @@ def verifyProperty(self, alg_descr, name):
def runTest(self):
algs = AlgorithmFactory.getRegisteredAlgorithms(True)

for (name, versions) in algs.iteritems():
for (name, versions) in iteritems(algs):
if not self.verifyAlgName(name):
self.__ranOk += 1
continue
Expand All @@ -148,8 +151,8 @@ def runTest(self):

def validate(self):
if self.__ranOk > 0:
print "Found %d errors. Coding conventions found at" % self.__ranOk,\
"http://www.mantidproject.org/Mantid_Standards"
print("Found %d errors. Coding conventions found at" % self.__ranOk,
"http://www.mantidproject.org/Mantid_Standards")
return False

return True
Expand All @@ -168,28 +171,28 @@ def verifyFuncName(self, name):
return True

if not self.funcRegExp.match(name):
print "Function " + name + " has a name that violates conventions"
print("Function " + name + " has a name that violates conventions")
return False

if bool(len(name) > MAX_ALG_LEN):
print "%s has a name that is longer than " % name, \
"%d characters (%d > %d)" % (MAX_ALG_LEN, len(name), MAX_ALG_LEN)
print("%s has a name that is longer than " % name,
"%d characters (%d > %d)" % (MAX_ALG_LEN, len(name), MAX_ALG_LEN))
return False

# passed all of the checks
return True

def verifyCategories(self, name, categories):
if len(categories) <= 0:
print name + " has no categories"
print(name + " has no categories")

for category in categories:
# TODO remove the special case
if category == "C++ User Defined":
return True

if not self.categoryRegExp.match(category):
print name + " has a bad category " + category
print(name + " has a bad category " + category)
return False

return True
Expand All @@ -204,7 +207,7 @@ def verifyParameter(self, alg_descr, name):

if not self.paramRegExp.match(name):
if not self.checkAllowed(alg_descr, name):
print alg_descr + " property (" + name +") violates conventions"
print(alg_descr + " property (" + name +") violates conventions")
return False

# passed all of the checks
Expand All @@ -222,14 +225,14 @@ def runTest(self):
if not self.verifyCategories(name, function.categories()):
self.__ranOk += 1

for i in xrange(function.numParams()):
for i in range(function.numParams()):
if not self.verifyParameter(name, function.getParamName(i)):
self.__ranOk += 1

def validate(self):
if self.__ranOk > 0:
print "Found %d errors. Coding conventions found at" % self.__ranOk,\
"http://www.mantidproject.org/Mantid_Standards"
print("Found %d errors. Coding conventions found at" % self.__ranOk,
"http://www.mantidproject.org/Mantid_Standards")
return False

return True
9 changes: 5 additions & 4 deletions Testing/SystemTests/tests/analysis/ConvertToMDworkflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pylint: disable=no-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
from mantid.simpleapi import *

Expand Down Expand Up @@ -27,10 +28,10 @@ def runTest(self):
try:
DeleteWorkspace(RezWS)
except ValueError:
print "Target ws ",RezWS," not found in analysis data service\n"
print("Target ws ",RezWS," not found in analysis data service\n")
#
#---> Start loop over contributing files
for i in xrange(0,20,5):
for i in range(0,20,5):
# the following operations simulate different workspaces, obtained from experiment using rotating crystal;
# For real experiment we usually just load these workspaces from nxspe files with proper Psi values defined there
# and have to set up ub matrix
Expand Down Expand Up @@ -72,8 +73,8 @@ def validate(self):

checker.execute()
if checker.getPropertyValue("Equals") != "1":
print " Workspaces do not match, result: ",checker.getPropertyValue("Result")
print self.__class__.__name__
print(" Workspaces do not match, result: ",checker.getPropertyValue("Result"))
print(self.__class__.__name__)
SaveMD(InputWorkspace=valNames[0],Filename=self.__class__.__name__+'-mismatch.nxs')
return False

Expand Down
5 changes: 3 additions & 2 deletions Testing/SystemTests/tests/analysis/CountReflectionsTest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import (absolute_import, division, print_function)
import stresstesting
from mantid.simpleapi import *
from SortHKLTest import HKLStatisticsTestMixin
Expand Down Expand Up @@ -32,8 +33,8 @@ def _run_count_reflections(self, reflections, space_group):
LatticeCentering=centering, MinDSpacing=0.5, MaxDSpacing=10.0)

def _compare_statistics(self, statistics, reference_statistics):
self.assertEquals(round(statistics['Redundancy'], 1), round(reference_statistics['<N>'], 1))
self.assertEquals(statistics['UniqueReflections'], int(reference_statistics['Nunique']))
self.assertEqual(round(statistics['Redundancy'], 1), round(reference_statistics['<N>'], 1))
self.assertEqual(statistics['UniqueReflections'], int(reference_statistics['Nunique']))
self.assertDelta(round(statistics['Completeness'] * 100.0, 1),
round(reference_statistics['Completeness'], 1),
0.5)
1 change: 1 addition & 0 deletions Testing/SystemTests/tests/analysis/DOSTest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pylint: disable=no-init,attribute-defined-outside-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
from mantid.kernel import *
from mantid.api import *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
System test that loads TOPAZ single-crystal data,
and runs Diffraction Workflow.
"""
from __future__ import (absolute_import, division, print_function)
import stresstesting
import numpy
import os
Expand Down Expand Up @@ -153,7 +154,7 @@ def runTest(self):
newUB = numpy.array(mtd["TOPAZ_3132"].sample().getOrientedLattice().getUB())
# UB Matrices are not necessarily the same, some of the H,K and/or L sign can be reversed
diff = abs(newUB) - abs(originalUB) < 0.001
for c in xrange(3):
for c in range(3):
# This compares each column, allowing old == new OR old == -new
if not numpy.all(diff[:,c]) :
raise Exception("More than 0.001 difference between UB matrices: Q (lab frame):\n%s\nQ (sample frame):\n%s"
Expand Down
6 changes: 4 additions & 2 deletions Testing/SystemTests/tests/analysis/EQSANSIQOutputAPIv2.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#pylint: disable=no-init,invalid-name,attribute-defined-outside-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
import math
import os
from mantid.simpleapi import *
from reduction_workflow.instruments.sans.sns_command_interface import *
from reduction_workflow.instruments.sans.hfir_command_interface import *
from mantid.api import *
from functools import reduce


def do_cleanup():
Expand Down Expand Up @@ -192,7 +194,7 @@ def validate(self):
output = reduce(lambda x,y:x and y, diff)
if not output:
for i,dqi in enumerate(dq):
print i, dqi, dq_ref[i], math.fabs(dq_ref[i]-dqi)<0.0001
print(i, dqi, dq_ref[i], math.fabs(dq_ref[i]-dqi)<0.0001)
return output


Expand Down Expand Up @@ -258,5 +260,5 @@ def validate(self):

if not output:
for i,dqi in enumerate(dq):
print i, dqi, dq_ref[i], math.fabs(dq_ref[i]-dqi)<0.0001
print(i, dqi, dq_ref[i], math.fabs(dq_ref[i]-dqi)<0.0001)
return output
3 changes: 2 additions & 1 deletion Testing/SystemTests/tests/analysis/EQSANSSolidAPIv2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pylint: disable=no-init,attribute-defined-outside-init
from __future__ import (absolute_import, division, print_function)
import stresstesting
from mantid.simpleapi import *
from reduction_workflow.instruments.sans.sns_command_interface import *
Expand All @@ -12,7 +13,7 @@ def do_cleanup():
absfile = FileFinder.getFullPath("EQSANS_1466_event_reduction.log")
if os.path.exists(absfile):
os.remove(absfile)
print "cleaned"
print("cleaned")
return True


Expand Down
Loading

0 comments on commit 66ec89d

Please sign in to comment.