def test_01Check(self): import CGNS.PAT.cgnsutils as CGU import CGNS.PAT.cgnserrors as CGE import CGNS.PAT.cgnskeywords as CGK self.assertFalse(CGU.checkName('/name')) self.assertFalse(CGU.checkNodeName(3)) self.assertFalse(CGU.checkName(3)) self.assertFalse(CGU.checkName(['name'])) self.assertFalse(CGU.checkName('')) self.assertFalse(CGU.checkName('x' * 33)) self.assertFalse(CGU.checkName('.')) self.assertFalse(CGU.checkName('..')) self.assertFalse(CGU.checkName(' ')) self.assertTrue(CGU.checkName('name test')) self.assertTrue(CGU.checkName('name"test"')) self.assertTrue(CGU.checkName('name\\test')) self.assertTrue(CGU.checkName(' name')) self.assertTrue(CGU.checkName('name')) self.assertTrue(CGU.checkName('x' * 32)) self.assertTrue(CGU.checkNodeName(['test', None, [], 'Zone_t'])) self.assertTrue(CGU.checkNodeName([' test', None, [], 'Zone_t'])) self.assertTrue(CGU.checkNodeName(['?test#320', None, [], 'Zone_t'])) self.assertTrue(CGU.checkNodeName(['test ', None, [], 'Zone_t'])) self.assertFalse(CGU.checkName('name test', strict=True)) self.assertFalse(CGU.checkName('name\\test', strict=True)) self.assertFalse(CGU.checkName('name"test"', strict=True)) self.assertFalse(CGU.checkName(' name', strict=True)) import string clist = list(string.ascii_letters + string.digits + string.punctuation + ' ') clist.remove('/') for c in clist: self.assertTrue(CGU.checkName('_' + c)) ex = CGE.cgnsNameError fn = CGU.checkName self.assertRaisesRegexp(ex, self.eStr(2), CGU.checkNodeName, [], dienow=True) self.assertRaisesRegexp(ex, self.eStr(22), fn, 3, dienow=True) self.assertRaisesRegexp(ex, self.eStr(23), fn, '', dienow=True) self.assertRaisesRegexp(ex, self.eStr(24), fn, '/', dienow=True) self.assertRaisesRegexp(ex, self.eStr(25), fn, 'a' * 33, dienow=True) self.assertRaisesRegexp(ex, self.eStr(29), fn, '.', dienow=True) self.assertRaisesRegexp(ex, self.eStr(31), fn, ' ' * 5, dienow=True) self.assertRaisesRegexp(ex, self.eStr(32), fn, ' a' * 5, dienow=True, strict=True) self.assertRaisesRegexp(ex, self.eStr(33), fn, '"', dienow=True, strict=True) self.assertRaisesRegexp(ex, self.eStr(34), fn, 'a a', dienow=True, strict=True) self.genTree() self.assertTrue(CGU.checkSameNode(self.T, self.T)) self.assertFalse(CGU.checkSameNode(self.T, [None, None, [], None])) self.assertRaisesRegexp(CGE.cgnsNodeError, self.eStr(30), CGU.checkSameNode, self.T, [None, None, [], None], dienow=True)
def checkSingleNode(self, T, path, node, parent): stt = CGM.CHECK_GOOD if (not CGU.checkNodeName(node)): stt = self.log.push(path, 'G0003', node[0]) lchildren = CGU.childNames(parent) if (lchildren): if (node[0] in lchildren): lchildren.remove(node[0]) if (node[0] in lchildren): stt = self.log.push(path, 'G0004', node[0]) tlist = CGU.getNodeAllowedChildrenTypes(parent, node) if ((CGU.getTypeAsGrammarToken(node[3]) not in tlist) and (node[3] != CGK.CGNSTree_ts)): if (parent is not None): stt = self.log.push(path, 'S0002', node[3], parent[3]) else: stt = self.log.push(path, 'S0003', node[3]) dlist = CGU.getNodeAllowedDataTypes(node) dt = CGU.getValueDataType(node) if (dt not in dlist): stt = self.log.push(path, 'S0004', dt) if (node[3] not in CGT.types.keys()): stt = self.log.push(path, 'S0001', node[3]) else: stt = self.checkCardinalityOfChildren(T, path, node, parent) stt = self.checkReservedChildrenNames(T, path, node, parent) return stt
def checkLeafStructure(self, T, path, node, parent): stt = CGM.CHECK_GOOD try: CGU.checkNode(node, dienow=True) CGU.checkNodeName(node, dienow=True) CGU.checkDuplicatedName(parent, node[0], dienow=True) CGU.checkNodeType(node, dienow=True) if (node[1] is not None): CGU.checkArray(node[1], dienow=True) except CGE.cgnsException as v: if (v.code == 1): stt = self.log.push(path, 'G0010') if (v.code == 2): stt = self.log.push(path, 'G0009') if (v.code == 3): stt = self.log.push(path, 'G0008') if (v.code == 4): stt = self.log.push(path, 'G0007') if (v.code == 5): stt = self.log.push(path, 'G0006') if (v.code == 22): stt = self.log.push(path, 'G0008') if (v.code == 23): stt = self.log.push(path, 'G0011') if (v.code == 24): stt = self.log.push(path, 'G0012') if (v.code == 25): stt = self.log.push(path, 'G0014') if (v.code == 29): stt = self.log.push(path, 'G0013') if (v.code == 31): stt = self.log.push(path, 'G0011') if (v.code == 32): stt = self.log.push(path, 'G0011') if (v.code == 111): stt = self.log.push(path, 'G0015') if (self._stop): raise CGE.cgnsException(-1) return stt