From: Zbigniew Jędrzejewski-S. <zb...@in...> - 2014-04-01 21:11:30
|
One interesting error was detected: in mumbl.py a code like this appears: raise UserWarning, "Unsupported type or parameter", direction but it doesn't actually work, even under Python 2: >>> direction = "in" >>> raise UserWarning, "Unsupported", direction Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: raise: arg 3 must be a traceback or None The proper fix is to format the string before passing it to raise. --- python/moose/multiscale/core/mumbl.py | 12 ++++++------ python/moose/multiscale/core/types.py | 5 +---- python/moose/multiscale/helper/moose_methods.py | 4 ++-- python/moose/multiscale/parser/ChannelML.py | 6 +++--- python/moose/multiscale/parser/parser.py | 2 +- .../twoNeurons/generatedPyNN/PyNNUtils/PyNNUtils.py | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/python/moose/multiscale/core/mumbl.py b/python/moose/multiscale/core/mumbl.py index 32e5ca1..a33b4f7 100644 --- a/python/moose/multiscale/core/mumbl.py +++ b/python/moose/multiscale/core/mumbl.py @@ -157,7 +157,7 @@ class Mumble(): debug.printDebug("TODO" , "Unsupported model type : {0}".format(modelType) ) - raise UserWarning, "Unsupported model type" + raise UserWarning("Unsupported model type") return None def loadElectricalModel(self, modelXml): @@ -200,7 +200,7 @@ class Mumble(): , "Loading user external script is not supported yet." , frame = inspect.currentframe() ) - raise UserWarning, "Unimplemented feature" + raise UserWarning("Unimplemented feature") # Otherwise load the model. modelFilePath = modelXml.get('file_path', None) @@ -244,7 +244,7 @@ class Mumble(): comparment ids. """ if chemType != "chemical": - raise UserWarning, "Only chemical models are supported" + raise UserWarning("Only chemical models are supported") compPath = os.path.join(self.chemPath, self.compartmentName) moose.Neutral(compPath) @@ -303,7 +303,7 @@ class Mumble(): tgts = adaptor.findall('target') [self.outTarget(t, moosePath) for t in tgts] else: - raise UserWarning, "Unsupported type or parameter", direction + raise UserWarning("Unsupported type or parameter: {}".format(direction)) def inTarget(self, src, moosePath): """Set up incoming source and target. @@ -325,7 +325,7 @@ class Mumble(): # in which compartment and which type of pool compId = src.get('compartment_id') if compId is None: - raise UserWarning, "Missing parameter or value: compartment_id" + raise UserWarning("Missing parameter or value: compartment_id") species = src.get('species') assert species, "Must have species in source" poolId = os.path.join(self.compartmentName, compId) @@ -372,7 +372,7 @@ class Mumble(): compId = tgt.get('compartment_id') if compId is None: - raise UserWarning, "Missing parameter or value: compartment_id" + raise UserWarning("Missing parameter or value: compartment_id") assert int(compId) >= 0, "Not a valid compartment id: %s" % compId diff --git a/python/moose/multiscale/core/types.py b/python/moose/multiscale/core/types.py index 4ae60c1..f8fcfae 100644 --- a/python/moose/multiscale/core/types.py +++ b/python/moose/multiscale/core/types.py @@ -28,10 +28,7 @@ class DoubleDict: if k == self.v[self.k.get(k, None)]: txt.append(unicode('{} <-> {}'.format(k, self.k[k]))) else: - raise UserWarning, "Duplicate Entries: {} {}".format( - self.k - , self.v - ) + raise UserWarning("Duplicate Entries: {0.k} {0.v}".format(self)) return '{' + ', '.join(txt) + '}' diff --git a/python/moose/multiscale/helper/moose_methods.py b/python/moose/multiscale/helper/moose_methods.py index b99b4bd..e3e9d68 100644 --- a/python/moose/multiscale/helper/moose_methods.py +++ b/python/moose/multiscale/helper/moose_methods.py @@ -58,7 +58,7 @@ def moosePath(baseName, append): elif len(nameSep) == 2: return baseName + nameSep[0] + append + nameSep[1] else: - raise UserWarning, "Not more than 2 characters are not supported" + raise UserWarning("Not more than 2 characters are not supported") else: return os.path.join(baseName, append) @@ -96,7 +96,7 @@ def stringToFloat(text): val = float(text) return val except Exception: - raise UserWarning, "Failed to convert {0} to float".format(text) + raise UserWarning("Failed to convert {0} to float".format(text)) def dumpMoosePaths(pat, isRoot=True): diff --git a/python/moose/multiscale/parser/ChannelML.py b/python/moose/multiscale/parser/ChannelML.py index f24d7fa..48f642e 100644 --- a/python/moose/multiscale/parser/ChannelML.py +++ b/python/moose/multiscale/parser/ChannelML.py @@ -84,7 +84,7 @@ class ChannelML: Gfactor = 1.0 else: debug.printDebug("ERROR", "Wrong units {0}".format(units)) - raise UserWarning, "Wrong value or parameter {0}".format(units) + raise UserWarning("Wrong value or parameter {0}".format(units)) # creates /library in MOOSE tree; elif present, wraps # NOTE: This path is created by NeuroML now in __init__. Disabling, @@ -139,7 +139,7 @@ class ChannelML: , "wrong units %s. Existing... " % units , frame = inspect.currentframe() ) - raise UserWarning, "Unknown units" + raise UserWarning("Unknown units") # creates /library in MOOSE tree; elif present, wraps channel_name = channelElement.attrib['name'] @@ -184,7 +184,7 @@ class ChannelML: msg = "Sorry! Maximum x, y, and z (three) gates are possible in\ MOOSE/Genesis" debug.printDebug("ERR", msg, frame=inspect.currentframe()) - raise UserWarning, "Bad value or parameter" + raise UserWarning("Bad value or parameter") # These are the names that MOOSE uses to create gates. gate_full_name = [ 'gateX', 'gateY', 'gateZ' ] diff --git a/python/moose/multiscale/parser/parser.py b/python/moose/multiscale/parser/parser.py index 4e0c4aa..0f05f28 100644 --- a/python/moose/multiscale/parser/parser.py +++ b/python/moose/multiscale/parser/parser.py @@ -39,7 +39,7 @@ def parseWithoutValidation(modelName, modelPath) : except Exception as e : debug.printDebug("ERROR", "Parsing of {0} failed.".format(modelPath)) debug.printDebug("DEBUG", "Error: {0}".format(e)) - raise RuntimeError, "Failed to parse XML" + raise RuntimeError("Failed to parse XML") return xmlRootElem def parseXMLs(commandLineArgs, validate=False) : diff --git a/python/moose/xmls_to_network/twoNeurons/generatedPyNN/PyNNUtils/PyNNUtils.py b/python/moose/xmls_to_network/twoNeurons/generatedPyNN/PyNNUtils/PyNNUtils.py index 915eada..a9c04c0 100644 --- a/python/moose/xmls_to_network/twoNeurons/generatedPyNN/PyNNUtils/PyNNUtils.py +++ b/python/moose/xmls_to_network/twoNeurons/generatedPyNN/PyNNUtils/PyNNUtils.py @@ -201,7 +201,7 @@ class NetManagerPyNN(NetworkHandler): freq = float(inputProps["frequency"]) if (self.maxSimLength<0): - raise ValueError, "The value of maxSimLength must be set!" + raise ValueError("The value of maxSimLength must be set!") numberExp = int(float(self.maxSimLength)*freq) -- 1.8.5.3 |