# -*- coding: iso-8859-1 -*-
#
#-------------------------------------------------------------------------------
#                    Code_Saturne version 1.3
#                    ------------------------
#
#
#     This file is part of the Code_Saturne User Interface, element of the
#     Code_Saturne CFD tool.
#
#     Copyright (C) 1998-2007 EDF S.A., France
#
#     contact: saturne-support@edf.fr
#
#     The Code_Saturne User Interface is free software; you can redistribute it
#     and/or modify it under the terms of the GNU General Public License
#     as published by the Free Software Foundation; either version 2 of
#     the License, or (at your option) any later version.
#
#     The Code_Saturne User Interface is distributed in the hope that it will be
#     useful, but WITHOUT ANY WARRANTY; without even the implied warranty
#     of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License
#     along with the Code_Saturne Kernel; if not, write to the
#     Free Software Foundation, Inc.,
#     51 Franklin St, Fifth Floor,
#     Boston, MA  02110-1301  USA
#
#-------------------------------------------------------------------------------

"""
This module defines the XML calls for ecs execution                            
This module contains the following classes and function:
- SolutionDomainModel 
"""

#-------------------------------------------------------------------------------
# Library modules import
#-------------------------------------------------------------------------------


import sys, unittest
import os, sys, string, types

#-------------------------------------------------------------------------------
# Class 
#-------------------------------------------------------------------------------

class SolutionDomainModel:
    """
    This class allow to call function for fill saturne running file (lance)
    """

    def __init__(self, case):
        """
        Simple constructor.
        """
        # TODO: remplacer cutting par splitting
        # TODO: remplacer solution_domain par solution_domain
        # TODO: remplacer standalone par verification
        # TODO: deplacer le contenu de miscellaneous dans batch_running
        self.case = case

        self.node_ecs        = self.case.xmlGetNode('solution_domain')
#        self.node_meshes     = self.node_ecs.xmlInitNode('meshes')
        self.node_meshes     = self.node_ecs.xmlInitNode('meshes_list')
        self.node_paste      = self.node_ecs.xmlGetNode('paste_meshes', "status")
        self.node_cut        = self.node_ecs.xmlGetNode('faces_cutting', "status")
        self.node_syrthes    = self.node_ecs.xmlGetNode('syrthes_coupling', "status")
        self.node_perio      = self.node_ecs.xmlGetNode('periodic_boundary', "status")
##        self.node_miscel     = self.node_ecs.xmlGetNode('miscellaneous')
        self.node_standalone = self.node_ecs.xmlInitNode('standalone')
##        self.node_post       = self.node_standalone.xmlInitNode('post-processing', 'status', format="ensight7 gold")
##        self.node_med        = self.node_standalone.xmlInitNode('post-processing', 'status', format="med")


    def defaultValues(self):
        """
        Return a dictionnary with default values
        """
        defvalue = {}
        defvalue['paste_status'] = "off"
        defvalue['cutting_status']    = "off"
        defvalue['fraction']     = "0.1"
        defvalue['plan']         = "0.8"
        defvalue['angle']        = "0.01"
        defvalue['syrth_status'] = "off"
        defvalue['echo_status']  = "off"
        defvalue['echo_elt_nb']  = "5"
        defvalue['sim_status']   = "on"
        defvalue['verif_mail']   = "on"
        defvalue['ens_status']   = "on"
        defvalue['med_status']   = "off"
        defvalue['dir_cas']      = "cas_defaut"
        defvalue['poly_status']  = "off"
        defvalue['perio_status'] = "off"
        defvalue['dx']           = "0.0"
        defvalue['dy']           = "0.0"
        defvalue['dz']           = "0.0"
        defvalue['rx']           = "0.0"
        defvalue['ry']           = "0.0"
        defvalue['rz']           = "0.0"
        defvalue['px']           = "0.0"
        defvalue['py']           = "0.0"
        defvalue['pz']           = "0.0"
        defvalue['rangle']       = "0.0"
        defvalue['m11']          = "0.0"
        defvalue['m12']          = "0.0"
        defvalue['m13']          = "0.0"
        defvalue['m21']          = "0.0"
        defvalue['m22']          = "0.0"
        defvalue['m23']          = "0.0"
        defvalue['m31']          = "0.0"
        defvalue['m32']          = "0.0"
        defvalue['m33']          = "0.0"

        return defvalue


    def getMeshList(self):
        """
        Return the meshes name list already put in the case.
        """
        meshList = []
        nodeList = self.node_meshes.xmlGetNodeList('mesh', 'name')
        for node in nodeList: meshList.append(node['name'])
        return meshList


    def setMesh(self, mesh, format):
        """
        Add mesh name in xml file
        """
        if self.node_meshes:
            self.node_meshes.xmlInitNode('mesh', name=mesh, format=format)


    def delMesh(self, mesh):
        """
        Delete node for mesh named "mesh" in xml file
        """
        nodeList = self.node_meshes.xmlGetNodeList('mesh', 'name')
        for node in nodeList:
            if node['name'] == mesh: node.xmlRemoveNode()


    def getPasteMeshesStatus(self):
        """
        Get status on balise "paste_meshes" from xml file             
        """
        status = ""
        if self.node_paste:
            status = self.node_paste['status']

        return status


    def setPasteMeshesStatus(self, status):
        """
        Put status on balise "paste_meshes" in xml file             
        """
        if self.node_paste:
            self.node_paste['status'] = status
        else:
            self.node_paste = self.node_ecs.xmlInitNode('paste_meshes', status=status)


    def getListNodes(self, parentNode, tagName):
        """
        Return node corresponding at the selection
        """
        listNode = parentNode.xmlGetNodeList(tagName)

        return listNode


    def getCutStatus(self):
        """
        Get status on balise "faces_cutting" from xml file             
        """
        status = ""
        if self.node_cut:
            status = self.node_cut['status']
        return status


    def setCutStatus(self, status):
        """
        Put status on balise "faces_cutting" in xml file             
        """
        if self.node_cut: 
            self.node_cut['status'] = status
        else:
            self.node_cut = self.node_ecs.xmlInitNode('faces_cutting', status=status)


    def getFacesPeriodicSelection(self, perio):
        """
        Return faces selection for periodic transformation                          
        """
        line =''
        node, mode = self.getPeriodicNumberNode(perio)
        list = node.xmlGetNodeList('faces_periodic', status="on")
        for n in list: 
            line = n.xmlGetString('faces_color')

        return line


    def getFacesSyrthesSelection(self):
        """
        Return faces selection for syrthes                          
        """
        line =''
        list = self.node_syrthes.xmlGetNodeList('faces_syrthes', status="on")
        for n in list: 
            line = n.xmlGetString('faces_color')

        return line


    def setFacesSelect(self, node, tagName, select):
        """
        Uptodate xml file if we add select in ListBox
        """
        if tagName == 'faces_syrthes'or tagName == 'faces_select':
            select['fraction'] =""
            select['plan'] = ""
        if tagName == 'faces_select':
            select['type'] =""
        if node['status'] == 'on':
            for sel, txt in [ (select['color'], 'faces_color'),
                              (select['group'], 'faces_group'),
                              (select['fraction'], 'faces_fraction'),
                              (select['plan'], 'faces_plan')]:
                if sel:
                    node.xmlSetData(txt, sel)
                else:
                    node.xmlRemoveChild(txt)

            n = node.xmlGetChildNode('faces_type')
            if n: n.xmlRemoveNode()

            if select['reverse'] == 'on':
                node_revers = node.xmlInitNode('faces_reverse',status=select['reverse'])
            else:
                node.xmlRemoveChild('faces_reverse')

            if select['semiconf'] == 'on':
                node_semiconf = node.xmlInitNode('faces_semi_conf',status=select['semiconf'])
            else:
                node.xmlRemoveChild('faces_semi_conf')




    def getValue(self, node, var):
        """
        Return node corresponding at the selection
        """

        val = node.xmlGetDouble(var)

        return val


    def getFaces(self, node):
        """
        Return values found for color, group .. for node "node"
        """
        default = {}
        default['color'] =""
        default['group'] = ""
        default['fraction'] = ""
        default['plan'] = ""
        default['type'] = ""
        default['reverse'] = ""
        default['semiconf'] = ""
        if node:
            default['color']    = node.xmlGetString('faces_color')
            default['group']    = node.xmlGetString('faces_group')
            default['fraction'] = node.xmlGetString('faces_fraction')
            default['plan']     = node.xmlGetString('faces_plan')
            default['type']     = node.xmlGetString('faces_type')
            n_revers = node.xmlGetNode('faces_reverse','status')
            if n_revers: default['reverse'] = n_revers['status']
            else:        default['reverse'] = "off"
            n_semi_conf = node.xmlGetNode('faces_semi_conf','status')
            if n_semi_conf: default['semiconf'] = n_semi_conf['status']
            else:           default['semiconf'] = "off"
        return default


    def getFacesSelect(self, nodeList, n):
        """
        Return default filled with values found for color, group ..
        """
        node = nodeList[n]
        return self.getFaces(node)


    def getStatus(self, parent, tagName):
        """
        Return status for node with parent "parent" and tagName "tagname"
        """
        node = parent.xmlInitNode(tagName, 'status')
        status = node['status']
        return status


    def getStatusNode(self, node):
        """
        Return status for node "node"
        """
        if node : status = node['status']
        return status


    def setStatusNode(self, node, status):
        """
        Put status for node "node"
        """
        if node: node['status'] = status


    def getNodeAdd(self, parentNode, tagName, perio):
        """
        Return node corresponding at the selection
        """
        if tagName == "faces_periodic":
            node, mode = self.getPeriodicNumberNode(perio)
            childNode = node.xmlAddChild(tagName, status="on")
        else:
            childNode = parentNode.xmlAddChild(tagName, status="on")
        return childNode


    def delNode(self, node):
        """
        Remove node "node"
        """
        node.xmlRemoveNode()


    def setCutAngle(self, var):
        """
        input '-dec-faces' parameter.
        """
        if self.node_cut:
            if var == self.defaultValues()['angle']:
                self.node_cut.xmlRemoveChild('warp_angle_max')
            else:
                self.node_cut.xmlSetData('warp_angle_max', var)


    def getCutAngle(self):
        """
        get '-dec-faces' parameters.
        """
        angle =""
        if self.node_cut:
            angle = self.node_cut.xmlGetString('warp_angle_max')
        return angle


    def getSyrthesCouplingStatus(self):
        """
        Get status on balise "syrthes_coupling" in xml file             
        """
        status = ""
        if self.node_syrthes:
            status = self.node_syrthes['status']
            if status not in ("on", "off"): 
                status = self.defaultValues()['syrth_status']
                self.node_syrthes['status'] = status
        return status


    def setSyrthesCouplingStatus(self, status):
        """
        Put status on balise "syrthes_coupling" in xml file             
        """
        if self.node_syrthes:
            self.node_syrthes['status'] = status
        else:
            self.node_syrthes = self.node_ecs.xmlInitNode('syrthes_coupling', status=status)


    def getSyrthes2dMeshStatus(self):
        """
        Return status of balise "'syrthes_mesh_2d'" from xml file             
        """
        status = ""
        node = self.node_syrthes.xmlGetNode('syrthes_mesh_2d', 'status')
        if node : status = node['status']
        return status


    def setSyrthes2dMeshStatus(self, status):
        """
        Put status of balise 'syrthes_mesh_2d' into xml file             
        """
        if self.node_syrthes:
            node = self.node_syrthes.xmlInitNode('syrthes_mesh_2d', 'status')
            if node: node['status'] = status

    def delSyrthes2dMeshNode(self):
        """
        Put status of balise 'syrthes_mesh_2d' into xml file             
        """
        node = self.node_syrthes.xmlInitNode('syrthes_mesh_2d', 'status')
        if node: node.xmlRemoveNode()


    def getPeriodicStatus(self):
        """
        Get status on balise "periodic_boundary" in xml file             
        """
        status = ""
        if self.node_perio:
            status = self.node_perio['status']
            if status not in ("on", "off"): 
                status = self.defaultValues()['perio_status']
                self.node_perio['status'] = status
        return status


    def setPeriodicStatus(self, status):
        """
        Put status on balise "periodic_boundary" in xml file             
        """
        if self.node_perio:
            self.node_perio['status'] = status
        else:
            self.node_perio = self.node_ecs.xmlInitNode('periodic_boundary', status=status)

        if status == "on":
            nodeList = self.node_perio.xmlGetNodeList('transformation', 'mode', 'status')
            if len(nodeList) == 0:
                self.node_perio.xmlAddChild('transformation', mode="translation", status="on")
                self.node_perio.xmlAddChild('transformation', 'mode', status="off")
                self.node_perio.xmlAddChild('transformation', 'mode', status="off")


    def setPeriodicNumberNode(self, perio, new_mode, old_mode):
        """
        Set node of transformation in periodic boundary for periodicity number "perio"
        and for mode "mode"
        """
        #pour le moment perio =1 : 1 seule transformation autorisée pour le moment
        flag = 0
        i = 0
        nodeList = self.node_perio.xmlGetNodeList('transformation', 'mode', 'status')
        for n in nodeList:
            i = i + 1
            if n['status'] == "on" and n['mode'] == old_mode: 
                n['status'] = 'off'
            else:
                if n['mode'] == new_mode: 
                    n['status'] = 'on'
                    flag = 1
                    return
        if flag == 0:
            for nd in nodeList:
##                if n['status'] != 'on':
                if nd['status'] == 'off' and nd['mode'] == "":
                    nd['status'] = 'on'
                    nd['mode'] = new_mode
                    flag = 1
                    return
                else:
                    flag = 2
        if flag == 2:
            for n in nodeList:
                if n['status'] == 'off' and n['mode'] != "old_mode":
                    n['status'] = 'on'
                    n['mode'] = new_mode
                    flag = 1
                    return

    def getPeriodicNumberNode(self, perio):
        """
        Get node of transformation in periodic boundary for periodicity number "perio"    
        """
        #pour le moment perio =1 : 1 seule transformation autorisée pour le moment
        perio = perio - 1
        mode_perio = ""
        node_perio = ""
        nodeList = self.node_perio.xmlGetNodeList('transformation', 'mode', 'status')
        for node in nodeList:
            if node['status'] == 'on':
                node_perio = node
                mode_perio = node['mode']
        return node_perio, mode_perio

    def getPeriodicTransformation(self, perio):
        """
        Get mode of transformation in periodic boundary for periodicity number "perio"
        """
        #pour le moment perio = 1
        mode =""
        node, mode = self.getPeriodicNumberNode(perio)
        return mode


    def setPeriodicTransformation(self, perio, mode):
        """
        Put mode of transformation in periodic boundary             
        """
        node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode_perio != mode: 
            self.setPeriodicNumberNode(perio, mode, mode_perio)
            node, mode_perio = self.getPeriodicNumberNode(perio)
        
        mode_list = ('translation', 'rotation1', 'rotation2')
        if mode in mode_list:
            nList = node.xmlGetChildNodeList(mode)
            if not nList:
              if mode =="translation": self.setTranslationDefault(perio)
              if mode =="rotation1": self.setRotation1Default(perio)
              if mode =="rotation2": self.setRotation2Default(perio)
        
        else:
            if mode =="tr+rota1":
                nList1 = node.xmlGetChildNodeList('translation')
                nList2 = node.xmlGetChildNodeList('rotation1')
                if not nList1 : self.setTranslationDefault(perio)
                if not nList2 : self.setRotation1Default(perio)
            elif mode =="tr+rota2":
                nList1 = node.xmlGetChildNodeList('translation')
                nList2 = node.xmlGetChildNodeList('rotation2')
                if not nList1 : self.setTranslationDefault(perio)
                if not nList2 : self.setRotation2Default(perio)


    def getTranslationDir(self, perio):
        """
        Get values of translation for periodic translation
        """
        dx = ""
        dy = ""
        dz = ""
        node, mode = self.getPeriodicNumberNode(perio)
        ntransList = node.xmlGetChildNodeList('translation')
        if ntransList:
            for n in ntransList:
                if n:
                    dx = n.xmlGetString('translation_x')
                    dy = n.xmlGetString('translation_y')
                    dz = n.xmlGetString('translation_z')

        return dx, dy, dz


    def setTranslationDefault(self, perio):
        """
        Put default values of translation for periodic translation
        """
        node, mode = self.getPeriodicNumberNode(perio)
        if node: 
            nList = node.xmlInitChildNodeList('translation')
            for n in nList:
                n.xmlSetData('translation_x', self.defaultValues()['dx'])
                n.xmlSetData('translation_y', self.defaultValues()['dy'])
                n.xmlSetData('translation_z', self.defaultValues()['dz'])

    def setTranslationDir(self, perio, dir, valcoor):
        """
        Put values of translation for periodic translation
        """
        node, mode = self.getPeriodicNumberNode(perio)
        if node:
            ntransList = node.xmlGetChildNodeList('translation')
            for n in ntransList:
                n.xmlSetData(dir,valcoor)

    def getRotationDir(self, perio):
        """
        Get values for director vector rotation for periodic translation
        """
        rx = ""
        ry = ""
        rz =  ""
        node, mode = self.getPeriodicNumberNode(perio)
        nList = node.xmlGetChildNodeList('rotation1')
        for n in nList:
            if n:
                rx = n.xmlGetString('rotation_x')
                ry = n.xmlGetString('rotation_y')
                rz = n.xmlGetString('rotation_z')
        return rx, ry, rz


    def setRotation1Default(self, perio):
        """
        Put default values of translation for periodic translation
        """
        node, mode = self.getPeriodicNumberNode(perio)
        nList = node.xmlInitChildNodeList('rotation1')
        for n in nList:
            n.xmlSetData('rotation_angle', self.defaultValues()['rangle'])
            n.xmlSetData('rotation_x', self.defaultValues()['rx'])
            n.xmlSetData('rotation_y', self.defaultValues()['ry'])
            n.xmlSetData('rotation_z', self.defaultValues()['rz'])
            n.xmlSetData('rotation_center_x', self.defaultValues()['px'])
            n.xmlSetData('rotation_center_y', self.defaultValues()['py'])
            n.xmlSetData('rotation_center_z', self.defaultValues()['pz'])


    def setRotation2Default(self, perio):
        """
        Put default values of translation for periodic translation
        """
        node, mode = self.getPeriodicNumberNode(perio)
        nList = node.xmlInitChildNodeList('rotation2')
        for n in nList:
            n.xmlSetData('rotation_matrix_11', self.defaultValues()['m11'])
            n.xmlSetData('rotation_matrix_12', self.defaultValues()['m12'])
            n.xmlSetData('rotation_matrix_13', self.defaultValues()['m13'])
            n.xmlSetData('rotation_matrix_21', self.defaultValues()['m21'])
            n.xmlSetData('rotation_matrix_22', self.defaultValues()['m22'])
            n.xmlSetData('rotation_matrix_23', self.defaultValues()['m23'])
            n.xmlSetData('rotation_matrix_31', self.defaultValues()['m31'])
            n.xmlSetData('rotation_matrix_32', self.defaultValues()['m32'])
            n.xmlSetData('rotation_matrix_33', self.defaultValues()['m33'])
            n.xmlSetData('rotation_center_x', self.defaultValues()['px'])
            n.xmlSetData('rotation_center_y', self.defaultValues()['py'])
            n.xmlSetData('rotation_center_z', self.defaultValues()['pz'])


    def setRotationDir(self, perio, dir, valcoor):
        """
        Put values for director vector rotation for periodic translation
        """
        node, mode = self.getPeriodicNumberNode(perio)
        nodeList = node.xmlGetChildNodeList('rotation1')
        for n in nodeList:
            n.xmlSetData(dir,valcoor)


    def getRotationAngle(self, perio):
        """
        Get angle for ratation for periodic rotation                     
        """
        angle = ""
        node, mode = self.getPeriodicNumberNode(perio)
        nList = node.xmlGetChildNodeList('rotation1')
        for n in nList:
            if n:
                angle = n.xmlGetString('rotation_angle')

        return angle


    def setRotationAngle(self, perio, angle):
        """
        Put angle for rotation for periodic rotation                     
        """
        node, mode = self.getPeriodicNumberNode(perio)
        nodeList = node.xmlGetChildNodeList('rotation1')
        for n in nodeList:
            n.xmlSetData('rotation_angle',angle)


    def getRotationCenter(self, perio, mode):
        """
        Get coordinates of center of rotation for periodic transformation
        """
        px = ""
        py = ""
        pz = ""
        node, mode_perio = self.getPeriodicNumberNode(perio)                                             
        if mode_perio != mode: 
            self.setPeriodicNumberNode(perio, mode, mode_perio)
            node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode == "rotation1" or mode == "tr+rota1":
            nList = node.xmlGetChildNodeList('rotation1')
        elif mode == "rotation2" or mode == "tr+rota2":
            nList = node.xmlGetChildNodeList('rotation2')
        for n in nList:
            if n:
                px = n.xmlGetString('rotation_center_x')
                py = n.xmlGetString('rotation_center_y')
                pz = n.xmlGetString('rotation_center_z')
        return px, py, pz


    def setRotationCenter(self, perio, mode, pos, val):
        """
        Put coordinates of center of rotation for periodic transformation
        """
        node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode_perio != mode: 
            self.setPeriodicNumberNode(perio, mode, mode_perio)
            node, mode_perio = self.getPeriodicNumberNode(perio)
        if node['mode'] == mode: 
            if mode == "rotation1" or mode == "tr+rota1":
                nList = node.xmlGetChildNodeList('rotation1')
            elif mode == "rotation2" or mode == "tr+rota2":
                nList = node.xmlGetChildNodeList('rotation2')
            for n in nList:
                n.xmlSetData(pos,val)


    def getRotationMatrix(self, perio, mode):
        """
        Get values of matrix of rotation for periodic transformation
        """
        m11 = ""
        m12 = ""
        m13 = ""
        m21 = ""
        m22 = ""
        m23 = ""
        m31 = ""
        m32 = ""
        m33 = ""
        node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode_perio != mode: 
            self.setPeriodicNumberNode(perio, mode, mode_perio)
            node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode == "rotation2" or mode == "tr+rota2":
            nList = node.xmlGetChildNodeList('rotation2')
            for n in nList:
                if n:
                    m11 = n.xmlGetString('rotation_matrix_11')
                    m12 = n.xmlGetString('rotation_matrix_12')
                    m13 = n.xmlGetString('rotation_matrix_13')
                    m21 = n.xmlGetString('rotation_matrix_21')
                    m22 = n.xmlGetString('rotation_matrix_22')
                    m23 = n.xmlGetString('rotation_matrix_23')
                    m31 = n.xmlGetString('rotation_matrix_31')
                    m32 = n.xmlGetString('rotation_matrix_32')
                    m33 = n.xmlGetString('rotation_matrix_33')

        return m11, m12, m13, m21, m22, m23, m31, m32, m33


    def setRotationMatrix(self, perio, mode, pos, val):
        """
        Put values of matrix of rotation for periodic transformation
        """
        node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode_perio != mode: 
            self.setPeriodicNumberNode(perio, mode, mode_perio)
            node, mode_perio = self.getPeriodicNumberNode(perio)
        if mode == "rotation2" or mode == "tr+rota2":
            nodeList = node.xmlGetChildNodeList('rotation2')
            for n in nodeList:
                n.xmlSetData(pos,val)

        # TODO: deplacer les 3 méthodes suivantes dans future classe BatchRunning
##    def setEchoCommStatus(self, status):
##        """
##        Put status of balise ''echo_communication' into xml file             
##        """
##        if self.node_miscel:
##            self.node_miscel['status'] = status
##        else:
##            self.node_miscel = self.node_ecs.xmlInitNode('echo_communication', status=status)


##    def setNbElementEchocomm(self, nb):
##        """
##        Put value of number of elements when echo-comm is ON in xml file         
##        """
##        node = self.node_miscel.xmlInitNode('echo_communication')
##        numxml = node.xmlGetInt('elements_number')
##        if not numxml or nb != numxml: 
##            node.xmlSetData('elements_number', nb)

##    def getEchoCommCommand(self):
##        """
##        Get "-echo-comm" command line for enveloppe execution
##        """
##        lines = ""
##        node = self.node_miscel.xmlInitNode('echo_communication')
##        if node['status'] == 'on':
##            line = " -echo-comm "
##            nb_elmts = node.xmlGetInt('elements_number')
##            line = line + str(nb_elmts)  +" "
##            lines = lines + line
##
##        return lines


    def setSimCommStatus(self, status):
        """
        Put status of balise ''similation_communication' into xml file             
        """
        node = self.node_standalone.xmlInitNode('simulation_communication', 'status')
        if node: node['status'] = status


    def setAsciiCommStatus(self, status):
        """
        Put status of balise 'ascii_communication' into xml file or remove balise            
        """
        node = self.node_standalone.xmlInitNode('ascii_communication', 'status')
        if status == 'on':
            node['status'] = status
        else:
            node.xmlRemoveNode()


    def setMeshCheckStatus(self, status):
        """
        Put status of balise 'check_mesh' into xml file             
        """
        node = self.node_standalone.xmlInitNode('check_mesh', 'status')
        if status == 'on':
            node['status'] = status
        else:
            node.xmlRemoveNode()


    def setEnsightStatus(self, status):
        """
        Put status of balise 'ensight post' into xml file             
        """
        self.node_post = self.node_standalone.xmlInitNode('post-processing', 'status', format="ensight7 gold")
        if self.node_post:
            self.node_post['status'] = status


    def getEnsightStatus(self):
        """
        Get status of balise 'ensight post' into xml file             
        """
        self.node_post = self.node_standalone.xmlGetNode('post-processing', 'status', format="ensight7 gold")
        if self.node_post:
            status = self.node_post['status']
        return status


    def setMedStatus(self, status):
        """
        Put status of balise 'med format post' into xml file             
        """
        self.node_med  = self.node_standalone.xmlInitNode('post-processing', 'status', format="med")
        if self.node_med:
            self.node_med['status'] = status


    def getMedStatus(self):
        """
        Get status of balise 'med format post' into xml file             
        """
        self.node_med = self.node_standalone.xmlGetNode('post-processing', 'status', format="med")
        if self.node_med:
            status = self.node_med['status']
        return status

    def createPostDir(self, dir):
        """
        Create a directory else than "cas_defaut" for Ensight                       
        """
        if self.node_post or self.node_med:
            if self.node_post['status'] == "on" or self.node_med['status'] == "on":
                self.node_standalone.xmlSetData('post_directory', dir)


    def getPostDir(self):
        """
        Get status of balise 'med format post' into xml file             
        """
        dir = self.node_standalone.xmlGetString('post_directory')
        return dir


    def delPostDir(self):
        """
        Remove balise "post_directory"
        """
        node = self.node_standalone.xmlGetChildNode('post_directory')
        if node: node.xmlRemoveNode()


    def setPolygonalNodeStatus(self, status):
        """
        Put status for balise 
        if some faces are not triangle or square, there are cut
        """
        node = self.node_standalone.xmlInitNode('polygonal_faces_cutting', 'status')
        if node: node['status'] = status


    def setPolyhedralNodeStatus(self, status):
        """
        Put status for balise 
        if some faces are not triangle or square, there are cut
        """
        node = self.node_standalone.xmlInitNode('polyhedral_faces_cutting', 'status')
        if node: node['status'] = status

    def delPolygonalNode(self):
        """
        Remove balise "polygonal_faces_cutting"
        """
        node = self.node_standalone.xmlGetChildNode('polygonal_faces_cutting')
        if node: node.xmlRemoveNode()


    def delPolyhedralNode(self):
        """
        Remove balise "polygonal_faces_cutting"
        """
        node = self.node_standalone.xmlGetChildNode('polyhedral_faces_cutting')
        if node: node.xmlRemoveNode()


    def getMeshCommand(self):
        """
        Get mesh command line for enveloppe execution
        """
        lines = ''
        nodeList = self.node_meshes.xmlGetNodeList('mesh', 'name')
        for meshNode in nodeList:
            name   = meshNode['name']
            format = meshNode['format']
            f = string.split(string.split(name,".")[1]," ")[0]
            if f not in ["unv","des","hex","med","cgns","msh","ngeom","case","neu"]:
                     name=string.split(name," ")[0]
            mesh = self.case['mesh_path'] + '/' + name
            lines = lines + " -maillage " + mesh + " "
            if format:
                lines = lines + " -format " + format + " "
        return lines


    def getLineCommand(self, node, line):
        """
        Get color group faces and revers satus and fraction and plan datas for
        command line to enveloppe execution
        """
        coul = node.xmlGetString('faces_color')
        grp = node.xmlGetString('faces_group')
        n_revers = node.xmlGetNode('faces_reverse','status')
        n_semi_conf = node.xmlGetNode('faces_semi_conf','status')
        if coul:
            line = line + " -couleur " + coul +" "
        if grp:
            line = line + " -groupe " + grp +" "
        if n_revers and n_revers['status'] == "on":
            line = line + " -invsel "
        if n_semi_conf and n_semi_conf['status'] == "on":
            line = line + " -semi-conf "
        return line


    def getPasteCommand(self):
        """
        Get rc command line for enveloppe execution
        """
        lines = ''
        if self.node_paste and self.node_paste['status'] == 'on':
            lines = ' -rc ' 
            node_face_paste_list = self.node_paste.xmlInitNodeList('faces_paste')
            if node_face_paste_list:
                for node_face_paste in node_face_paste_list:
                    if node_face_paste['status'] == 'on': 
                        linecoul = ' -rc '
                        lines = self.getLineCommand(node_face_paste, linecoul)
                        fraction = node_face_paste.xmlGetString('faces_fraction')
                        lines = lines + " -fraction " + fraction +" "
                        plan = node_face_paste.xmlGetString('faces_plan')
                        lines = lines + " -plan " + plan +" "
                        lines = lines + ' '
            else:
                lines = ' -rc ' 

        return lines


    def getCutCommand(self):
        """
        Get dec-faces command line for enveloppe execution
        """
        line = ''
        if self.node_cut and self.node_cut['status'] == 'on':
            line = line + ' -dec-faces '
            warp = self.getCutAngle()
            line = line + str(warp)
        
        return line


    def getPerioCommand(self, perio):
        """
        Get perio command line for enveloppe execution
        """
        line = ''
        if self.node_perio and self.node_perio['status'] == 'on':
            lineperio = ' -perio '
            node_face_perio_list = self.node_perio.xmlGetNodeList('faces_periodic')
##on peut ne rien préciser comme faces pour la périodicité:
            if node_face_perio_list:
                for node in node_face_perio_list:
                    if node['status'] == 'on':
                        line = self.getLineCommand(node, lineperio)
                        fraction = node.xmlGetString('faces_fraction')
                        if fraction: line = line + " -fraction " + fraction +" "
                        plan = node.xmlGetString('faces_plan')
                        if plan: line = line + " -plan " + plan +" "
            else: line = lineperio
            mode = self.getPeriodicTransformation(perio) 
            if mode == 'translation' or mode == 'tr+rota1' or mode == 'tr+rota2':
                dx, dy, dz = self.getTranslationDir(perio)
                line = line + " -trans " + dx +" " + dy +" " + dz +" "
            if mode == 'rotation1' or mode == 'tr+rota1':
                angle = self.getRotationAngle(perio)
                rx, ry, rz = self.getRotationDir(perio)
                px, py, pz = self.getRotationCenter(perio, mode)
                line = line + " -rota "  + " -angle " + angle + " -dir " + rx +" " + ry +" " + rz +" " + " -ptinv " + px +" " + py +" " + pz +" "
            if mode == 'rotation2' or mode == 'tr+rota2':
                m11, m12, m13, m21, m22, m23, m31, m32, m33 = self.getRotationMatrix(perio, mode)
                px, py, pz = self.getRotationCenter(perio, mode)
                line = line + " -rota "  + " -matrice " + m11 +" " + m12 +" " + m13 +" " + m21 +" " + m22 +" " + m23 +" " + m31 +" " + m32 +" " + m33 +" " + " -ptinv " + px +" " + py +" " + pz +" "
        return line


    def getSyrthesCommand(self):
        """
        Get syrthes command line for enveloppe execution
        """
        lines = ''
        if self.node_syrthes and self.node_syrthes['status'] == 'on':
            linesyr = ' -syrthes '
            node_list = self.node_syrthes.xmlInitNodeList('faces_syrthes')
            for node in node_list:
                #n_revers = node.xmlInitNode('faces_reverse','status')
                if node['status'] == 'on':
                    linesyr = self.getLineCommand(node, linesyr)
            node_syrth_2d = self.node_syrthes.xmlInitNode('syrthes_mesh_2d', 'status')
            if node_syrth_2d['status'] == 'on': linesyr = linesyr + " -2d "
            lines = lines + linesyr 

        return lines


    def getSimCommCommand(self):
        """
        Get " -sim-comm " command line for enveloppe execution
        """
        lines = ''
        node = self.node_standalone.xmlInitNode('simulation_communication')
        if node['status'] == 'on':
            line = " -sim-comm "
            lines = lines + line
        return lines


    def getVerifMaillCommand(self):
        """
        Get " -verif " command line for enveloppe execution
        """
        lines = ''
        node = self.node_standalone.xmlInitNode('check_mesh')
        if node['status'] != 'off':
            lines = " -verif "
        return lines


    def getSelectCommand(self):
        """
        Get "-fac-int" command line for enveloppe execution
        """
        lines  = ''
##        line   = ""
        node_list = self.node_standalone.xmlGetNodeList('faces_select')
        for nod in node_list:
            if nod['status'] == 'on':
                #n_revers = nod.xmlGetNodeList('faces_reverse','status')
                line = ' -fac-int '
                line = self.getLineCommand(nod, line)
                #coul = nod.xmlGetString('faces_color')
                #grp = nod.xmlGetString('faces_group')
                #if n_revers: rev = n_revers['status']
                #if coul: line = line + "-couleur " + coul +" "
                #if grp: line = line + "-groupe " + grp +" "
                #if rev == 'on': line = line + "-invsel "
##                typ = nod.xmlGetString('faces_type')
##                if typ == 'int': line = line + "-int "
##                if typ == 'bord': line = line + "-bord "
            lines = lines + line
        return lines


    def getEnsightCommand(self):
        """
        Get "-ensight" command line for enveloppe executiont
        """
        line  = ''
        if self.getEnsightStatus() == 'on':
            n_decpolygonal = self.node_standalone.xmlGetChildNode('polygonal_faces_cutting','status')
            n_decpolyhedral = self.node_standalone.xmlGetChildNode('polyhedral_faces_cutting','status')
            line = ' -ensight '
            if n_decpolygonal or n_decpolyhedral: 
                if n_decpolygonal['status'] == 'on' or  n_decpolyhedral['status'] == 'on': 
                    line = " -ensight -dec-poly "
            dir = self.getPostDir()
            if dir and dir != "cas_defaut": 
                line = line + "-cas " + dir +" "
##        else:
##            line = ''
        return line


    def getMedCommand(self):
        """
        Get "-med" command line for enveloppe execution
        """
        lines  = ''
        if self.getMedStatus() == 'on':
            lines = ' -med '
            dir = self.getPostDir()
            if dir and dir != "cas_defaut": 
                dir = self.getPostDir()
                lines = lines + "-cas " + dir +" "
        return lines


#-------------------------------------------------------------------------------
# SolutionDomain Model test case
#-------------------------------------------------------------------------------


class SolutionDomainTestCase(unittest.TestCase):
    """
    """
    def setUp(self):
        """
        This method is executed before all "check" methods.
        """
        from Base.XMLengine import Case
        from Base.XMLinitialize import XMLinit
        from Base.Toolbox import GuiParam
        GuiParam.lang = 'en'
        self.case = Case()
        XMLinit(self.case)

    def tearDown(self):
        """
        This method is executed after all "check" methods.
        """
        del self.case

    def xmlNewFile(self):
        """Private method to return a xml document."""
        xmldoc  = \
        '<?xml version="1.0" encoding="utf-8" ?>' +\
        '<TestCase case="CASE" study="STUDY" version="0.0"/>'

        return xmldoc

    def checkSolutionDomainInstantiation(self):
        """ Check whether the SolutionDomainModel class could be instantiated """
        model = None
        model = SolutionDomainModel(self.case)
        assert model != None, 'Could not instantiate SolutionDomainModel'

    def checkSetMesh(self):
        """ Check whether the setMesh could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setMesh('fdc','des')
        mdl.setMesh('pic','des')
        truc = mdl.node_meshes.toString()
        doc = '<meshes_list>'\
                '<mesh format="des" name="fdc"/>'\
                '<mesh format="des" name="pic"/>'\
                '</meshes_list>'
        assert doc == truc, \
        'Could not set meshes'

    def checkGetMeshList(self):
        """ Check whether the getMeshList could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setMesh('toto','des')
        mdl.setMesh('machin','truc')
        assert mdl.getMeshList() == ['toto','machin'],\
        'Could not get mesh list'

    def checkDelMesh(self):
        """ Check whether the delMesh could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setMesh('toto','des')
        mdl.setMesh('machin','truc')   
        mdl.delMesh('toto')
        truc = mdl.node_meshes.toString()
        doc = '<meshes_list><mesh format="truc" name="machin"/></meshes_list>'
        assert doc == truc, \
        'Could not delete meshes'

    def checkSetPasteMeshesStatus(self):
        """ Check whether the status of paste meshes could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        truc = mdl.node_paste.toString()
        doc = '<paste_meshes status="on"/>'
        assert doc == truc, 'could not set status in paste meshes balise'

    def checkGetPasteMeshesStatus(self):
        """ Check whether the status of paste meshes could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        assert mdl.getPasteMeshesStatus() == 'on',\
        'Could not get status from paste meshes balise'

    def checkSetFacesSelect(self):
        """ Check whether the values of color,group ... could be set """
        select = {}
        select['color'] = '1 2 3'
        select['group'] = 'toto'
        select['fraction'] = '0.1'
        select['plan'] = '0.8'
        select['type'] = ''
        select['reverse'] = 'off'
        select['semiconf'] = 'on'
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        node = mdl.getNodeAdd(mdl.node_paste, 'faces_paste', 0)
        mdl.setFacesSelect(node,'faces_paste',select)
        truc = mdl.node_paste.toString()
        doc = '<paste_meshes status="on">'\
                '<faces_paste status="on">'\
                    '<faces_color>1 2 3</faces_color>'\
                    '<faces_group>toto</faces_group>'\
                    '<faces_fraction>0.1</faces_fraction>'\
                    '<faces_plan>0.8</faces_plan>'\
                    '<faces_semi_conf status="on"/>'\
                '</faces_paste>'\
              '</paste_meshes>'
        assert doc == truc, 'could not set selection for faces'

    def checkGetFacesSelect(self):
        """ Check whether the status of paste meshes could be get """
        select = {}
        select['color'] = '1 2 3'
        select['group'] = 'toto'
        select['fraction'] = '0.1'
        select['plan'] = '0.8'
        select['type'] = ''
        select['reverse'] = 'off'
        select['semiconf'] = 'on'
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        node1 = mdl.node_paste.xmlAddChild('faces_paste', status="on")
        mdl.setFacesSelect(node1,'faces_paste',select)
        select['color'] = '9 8 7'
        select['group'] = 'machin'
        node2 = mdl.node_paste.xmlAddChild('faces_paste', status="on")
        mdl.setFacesSelect(node2,'faces_paste',select)
##        listNode = mdl.node_paste.xmlGetNodeList('faces_paste', status='on')
        listNode = mdl.getListNodes(mdl.node_paste,'faces_paste')
        assert mdl.getFacesSelect(listNode, 0) ==\
        {'group': 'toto', 'reverse': 'off', 'color': '1 2 3', 'plan': '0.8', \
        'fraction': '0.1', 'semiconf': 'on', 'type': ''},\
        'could not get selection for faces'

    def checkGetListNodes(self):
        """ Check whether the list of nodes could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        mdl.getNodeAdd(mdl.node_paste, 'faces_paste', 0)
        mdl.getNodeAdd(mdl.node_paste, 'faces_paste', 0)
        mdl.getNodeAdd(mdl.node_paste, 'faces_paste', 0)
        assert len(mdl.getListNodes(mdl.node_paste,'faces_paste')) == 3,\
        'could not get list of nodes'

    def checkGetStatus(self):
        """ Check whether the status of node given with parent and tagname could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        stat = mdl.getStatus(mdl.node_ecs, 'paste_meshes')
        assert mdl.getStatus(mdl.node_ecs, 'paste_meshes') == 'on',\
        'could not get status'

    def checkSetStatusNode(self):
        """ Check whether the status of node could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        node = mdl.node_paste.xmlAddChild('faces_paste')
        mdl.setStatusNode(node,'off')
        truc = node.toString()
        doc = '<faces_paste status="off"/>'
        assert doc == truc,'could not set status'

    def checkGetStatusNode(self):
        """ Check whether the status of node could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        mdl.setStatusNode(mdl.node_paste,'off')
        truc = mdl.node_paste.toString()
        assert mdl.getStatusNode(mdl.node_paste) == 'off',\
        'could not get status of node'

    def checkGetNodeAdd(self):
        """ Check whether the status of node could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPasteMeshesStatus('on')
        mdl.getNodeAdd(mdl.node_paste,'faces_paste',0)
        truc = mdl.node_paste.toString()
        doc ='<paste_meshes status="on"><faces_paste status="on"/></paste_meshes>'
        assert doc == truc,'could not add a node'

    def checkSetCutStatus(self):
        """ Check whether the status of node cut could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setCutStatus('on')
        truc = mdl.node_cut.toString()
        doc = '<faces_cutting status="on"/>'
        assert doc == truc,'could not set status of faces_cutting'

    def checkGetCutStatus(self):
        """ Check whether the status of node cut could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setCutStatus('off')
        assert mdl.getCutStatus() == 'off',\
        'could not get status of faces_cutting'

    def checkSetCutAngle(self):
        """ Check whether the status of node cut could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setCutStatus('on')
        mdl.setCutAngle('0.05')
        truc = mdl.node_cut.toString()
        doc = '<faces_cutting status="on">'\
                '<warp_angle_max>0.05</warp_angle_max>'\
              '</faces_cutting>'
        assert doc == truc,'could not set angle for faces_cutting'

    def checkGetCutAngle(self):
        """ Check whether the status of node cut could be set """
        mdl = SolutionDomainModel(self.case)       
        mdl.setCutStatus('on')
        mdl.setCutAngle('0.05')
        assert mdl.getCutAngle() == '0.05','could not get angle for faces_cutting'

    def checkSetSyrthesCouplingStatus(self):
        """ Check whether the status of node syrthes_coupling could be set """
        mdl = SolutionDomainModel(self.case)       
        mdl.setSyrthesCouplingStatus('on')
        truc = mdl.node_syrthes.toString()
        doc = '<syrthes_coupling status="on"/>'
        assert doc == truc,'could not set status for syrthes_coupling balise'

    def checkGetSyrthesCouplingStatus(self):
        """ Check whether the status of node syrthes_coupling could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setSyrthesCouplingStatus('on')
        assert mdl.getSyrthesCouplingStatus() == 'on',\
        'could not get status for syrthes_coupling balise'

    def checkSetSyrthes2dMeshStatus(self):
        """ Check whether the status of node syrthes_mesh_2d could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setSyrthesCouplingStatus('on')
        mdl.setSyrthes2dMeshStatus('on')
        truc = mdl.node_syrthes.toString()
        doc = '<syrthes_coupling status="on">'\
                '<syrthes_mesh_2d status="on"/>'\
              '</syrthes_coupling>'
        assert doc == truc,'could not set status for 2dMesh balise'

    def checkGetSyrthes2dMeshStatus(self):
        """ Check whether the status of node syrthes_mesh_2d could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setSyrthesCouplingStatus('on')
        mdl.setSyrthes2dMeshStatus('on')
        assert mdl.getSyrthes2dMeshStatus() == 'on',\
        'could not get status for 2dMesh balise'

    def checkDelSyrthes2dMeshNode(self):
        """ Check whether the status of node syrthes_mesh_2d could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setSyrthesCouplingStatus('on')
        mdl.setSyrthes2dMeshStatus('on')
        mdl.delSyrthes2dMeshNode()
        doc = mdl.node_syrthes.toString()
        assert doc =='<syrthes_coupling status="on"/>',\
        'could not del balise syrthes_mesh_2d'

    def checkSetPeriodicStatus(self):
        """ Check whether the status of node periodic_boundary could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus('on')
        truc = mdl.node_perio.toString()
        doc ='<periodic_boundary status="on">'\
                '<transformation mode="translation" status="on"/>'\
                '<transformation mode="" status="off"/>'\
                '<transformation mode="" status="off"/>'\
             '</periodic_boundary>'
        assert doc == truc,'could not set status for periodicity'

    def checkGetPeriodicStatus(self):
        """ Check whether the status of node periodic_boundary could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus('on')
        assert mdl.getPeriodicStatus() == 'on',\
        'could not get status for periodicity'

    def checkSetPeriodicNumberNode(self):
        """ Check whether the hopped node periodic_boundary could be get """         
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus('on')
        mdl.setPeriodicTransformation(1, "translation")
        mdl.setPeriodicTransformation(1, "tr+rota1")
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                '</transformation>'\
                '<transformation mode="tr+rota1" status="on">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                    '<rotation1>'\
                        '<rotation_angle>0.0</rotation_angle>'\
                        '<rotation_x>0.0</rotation_x>'\
                        '<rotation_y>0.0</rotation_y>'\
                        '<rotation_z>0.0</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set node for number 1 of periodicity'
        


    def checkGetPeriodicNumberNode(self):
        """ Check whether the hopped node periodic_boundary could be get """         
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus('on')
        mdl.setPeriodicTransformation(1, "translation")
        mdl.setPeriodicTransformation(1, "tr+rota1")
        node, mode = mdl.getPeriodicNumberNode(1)

    def checkSetPeriodicTransformation(self):
        """ Check whether the periodicity mode could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1, "translation")
        mdl.setPeriodicTransformation(1, "tr+rota1")
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                '</transformation>'\
                '<transformation mode="tr+rota1" status="on">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                    '<rotation1>'\
                        '<rotation_angle>0.0</rotation_angle>'\
                        '<rotation_x>0.0</rotation_x>'\
                        '<rotation_y>0.0</rotation_y>'\
                        '<rotation_z>0.0</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'             
        assert doc == truc,'could not set transformations mode of periodicity'

    def checkGetPeriodicTransformation(self):
        """ Check whether the periodicity mode could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1, "translation")
        assert mdl.getPeriodicTransformation(1) == 'translation',\
        'could not get mode "translation" of periodicity'
        mdl.setPeriodicTransformation(1, "tr+rota1")
        assert mdl.getPeriodicTransformation(1) == 'tr+rota1',\
        'could not get mode "tr+rota1" of periodicity'

    def checkSetTranslationDefault(self):
        """ Check whether the default translation mode of periodicity could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")        
        mdl.setTranslationDefault(1)
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="on">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the default translation mode of periodicity'

    def checkSetTranslationDir(self):
        """ Check whether the dir values translation mode of periodicity could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'translation')
        mdl.setTranslationDefault(1)
        mdl.setTranslationDir(1,'translation_y','3')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="on">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>3</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the dir values for translation'

    def checkGetTranslationDir(self):
        """ Check whether the dir values translation mode of periodicity could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'translation')
        mdl.setTranslationDefault(1)
        mdl.setTranslationDir(1,'translation_x','0.11')
        mdl.setTranslationDir(1,'translation_y','0.22')
        mdl.setTranslationDir(1,'translation_z','0.33')
        x,y,z = mdl.getTranslationDir(1)

    def checkSetRotation1Default(self):
        """ Check whether the default values for rotation mode of periodicity could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotation1Default(1)
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation1" status="on">'\
                    '<rotation1>'\
                        '<rotation_angle>0.0</rotation_angle>'\
                        '<rotation_x>0.0</rotation_x>'\
                        '<rotation_y>0.0</rotation_y>'\
                        '<rotation_z>0.0</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the default values for rotation1'

    def checkSetRotation2Default(self):
        """ Check whether the default values for rotation mode of periodicity could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation2')
        mdl.setRotation2Default(1)
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation2" status="on">'\
                    '<rotation2>'\
                        '<rotation_matrix_11>0.0</rotation_matrix_11>'\
                        '<rotation_matrix_12>0.0</rotation_matrix_12>'\
                        '<rotation_matrix_13>0.0</rotation_matrix_13>'\
                        '<rotation_matrix_21>0.0</rotation_matrix_21>'\
                        '<rotation_matrix_22>0.0</rotation_matrix_22>'\
                        '<rotation_matrix_23>0.0</rotation_matrix_23>'\
                        '<rotation_matrix_31>0.0</rotation_matrix_31>'\
                        '<rotation_matrix_32>0.0</rotation_matrix_32>'\
                        '<rotation_matrix_33>0.0</rotation_matrix_33>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation2>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the default values for rotation2'

    def checkSetRotationDir(self):
        """ Check whether the values for dir of rotation could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotationDir(1, 'rotation_x', '9.')
        mdl.setRotationDir(1, 'rotation_y', '8.')
        mdl.setRotationDir(1, 'rotation_z', '7.')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation1" status="on">'\
                    '<rotation1>'\
                        '<rotation_angle>0.0</rotation_angle>'\
                        '<rotation_x>9.</rotation_x>'\
                        '<rotation_y>8.</rotation_y>'\
                        '<rotation_z>7.</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the values for dir of rotation'

    def checkSetRotationAngle(self):
        """ Check whether the angle for rotation could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotationDir(1, 'rotation_x', '9.')
        mdl.setRotationDir(1, 'rotation_y', '8.')
        mdl.setRotationDir(1, 'rotation_z', '7.')
        mdl.setRotationAngle(1, '45.')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation1" status="on">'\
                    '<rotation1>'\
                        '<rotation_angle>45.</rotation_angle>'\
                        '<rotation_x>9.</rotation_x>'\
                        '<rotation_y>8.</rotation_y>'\
                        '<rotation_z>7.</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the angle for rotation'
        
    def checkSetRotationCenter(self):
        """ Check whether the center of rotation for rotation mode could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotationDir(1, 'rotation_x', '9.')
        mdl.setRotationDir(1, 'rotation_y', '8.')
        mdl.setRotationDir(1, 'rotation_z', '7.')
        mdl.setRotationAngle(1, '45.')
        mdl.setRotationCenter(1, 'rotation1', 'rotation_center_y', '66.')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation1" status="on">'\
                    '<rotation1>'\
                        '<rotation_angle>45.</rotation_angle>'\
                        '<rotation_x>9.</rotation_x>'\
                        '<rotation_y>8.</rotation_y>'\
                        '<rotation_z>7.</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>66.</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set the center of rotation for rotation mode'

    def checkSetRotationMatrix(self):
        """ Check whether the matrix of rotation for rotation2 mode could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation2')
        mdl.setRotationMatrix(1,'rotation2', 'rotation_matrix_31', '31.31')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation2" status="on">'\
                    '<rotation2>'\
                        '<rotation_matrix_11>0.0</rotation_matrix_11>'\
                        '<rotation_matrix_12>0.0</rotation_matrix_12>'\
                        '<rotation_matrix_13>0.0</rotation_matrix_13>'\
                        '<rotation_matrix_21>0.0</rotation_matrix_21>'\
                        '<rotation_matrix_22>0.0</rotation_matrix_22>'\
                        '<rotation_matrix_23>0.0</rotation_matrix_23>'\
                        '<rotation_matrix_31>31.31</rotation_matrix_31>'\
                        '<rotation_matrix_32>0.0</rotation_matrix_32>'\
                        '<rotation_matrix_33>0.0</rotation_matrix_33>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation2>'\
                '</transformation>'\
                '<transformation mode="" status="off"/>'\
              '</periodic_boundary>'
        assert doc == truc,'could not set matrix for rotation2 mode'

    def checkGetRotationDirAngleCenterAndMatrix(self):
        """ Check whether dir,angle and center of rotation and matrix for rotation modes could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotationDir(1, 'rotation_x', '9.')
        mdl.setRotationDir(1, 'rotation_y', '8.')
        mdl.setRotationDir(1, 'rotation_z', '7.')
        mdl.setRotationAngle(1, '45.')
        mdl.setRotationCenter(1, 'rotation1', 'rotation_center_y', '66.')
        angle = mdl.getRotationAngle(1)
        rx, ry, rz = mdl.getRotationDir(1)
        px, py, pz = mdl.getRotationCenter(1,'rotation1')
        mdl.setPeriodicTransformation(1,'tr+rota2')
        mdl.setRotationMatrix(1,'tr+rota2', 'rotation_matrix_31', '31.31')
        truc = mdl.node_perio.toString()
        doc = '<periodic_boundary status="on">'\
                '<transformation mode="translation" status="off"/>'\
                '<transformation mode="rotation1" status="off">'\
                    '<rotation1>'\
                        '<rotation_angle>45.</rotation_angle>'\
                        '<rotation_x>9.</rotation_x>'\
                        '<rotation_y>8.</rotation_y>'\
                        '<rotation_z>7.</rotation_z>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>66.</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation1>'\
                '</transformation>'\
                '<transformation mode="tr+rota2" status="on">'\
                    '<translation>'\
                        '<translation_x>0.0</translation_x>'\
                        '<translation_y>0.0</translation_y>'\
                        '<translation_z>0.0</translation_z>'\
                    '</translation>'\
                    '<rotation2>'\
                        '<rotation_matrix_11>0.0</rotation_matrix_11>'\
                        '<rotation_matrix_12>0.0</rotation_matrix_12>'\
                        '<rotation_matrix_13>0.0</rotation_matrix_13>'\
                        '<rotation_matrix_21>0.0</rotation_matrix_21>'\
                        '<rotation_matrix_22>0.0</rotation_matrix_22>'\
                        '<rotation_matrix_23>0.0</rotation_matrix_23>'\
                        '<rotation_matrix_31>31.31</rotation_matrix_31>'\
                        '<rotation_matrix_32>0.0</rotation_matrix_32>'\
                        '<rotation_matrix_33>0.0</rotation_matrix_33>'\
                        '<rotation_center_x>0.0</rotation_center_x>'\
                        '<rotation_center_y>0.0</rotation_center_y>'\
                        '<rotation_center_z>0.0</rotation_center_z>'\
                    '</rotation2>'\
                '</transformation>'\
              '</periodic_boundary>'
        assert doc == truc,'could not change mode of rotation'
        angle = mdl.getRotationAngle(1)
        rx, ry, rz = mdl.getRotationDir(1)
        px, py, pz = mdl.getRotationCenter(1,'tr+rota2')
        m11, m12, m13, m21, m22, m23, m31, m32, m33 = mdl.getRotationMatrix(1,'tr+rota2')

    def checkSetSimCommStatus(self):
        """ Check whether the status of node simulation_communication could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setSimCommStatus('on')
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<simulation_communication status="on"/>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc == truc,'could not set status of node simulation_communication'

    def checkSetAsciiCommStatus(self):
        """ Check whether the status of node ascii_communication could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setAsciiCommStatus('on')
        truc1 = mdl.node_ecs.toString()
        doc1 = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<ascii_communication status="on"/>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc1 == truc1,'could not set status "on" of node ascii_communication'
        mdl.setAsciiCommStatus('off')
        truc2 = mdl.node_ecs.toString()
        doc2 = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone/>'\
              '</solution_domain>'
        assert doc2 == truc2,'could not set status "off" of node ascii_communication'

    def checkSetMeshCheckStatus(self):
        """ Check whether the status of node ascii_communication could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setMeshCheckStatus('on')
        truc1 = mdl.node_ecs.toString()
        doc1 = '<solution_domain>'\
                    '<meshes_list/>'\
                    '<standalone>'\
                        '<check_mesh status="on"/>'\
                    '</standalone>'\
               '</solution_domain>'
        assert doc1 == truc1,'could not set status "on" of node check_mesh'
        mdl.setMeshCheckStatus('off')
        truc2 = mdl.node_ecs.toString()
        doc2 = '<solution_domain>'\
                    '<meshes_list/>'\
                    '<standalone/>'\
               '</solution_domain>'
        assert doc2 == truc2,'could not set status "off" of node check_mesh'

    def checkSetPostAndMedStatus(self):
        """ Check whether the status of post-processing ensight and med format could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setEnsightStatus('on')
        mdl.setMedStatus('off')
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<post-processing format="ensight7 gold" status="on"/>'\
                    '<post-processing format="med" status="off"/>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc == truc,'could not set status of post-processing ensight and med format'

    def checkCreatePostDir(self):
        """ Check whether a post-processing directory could be created"""
        mdl = SolutionDomainModel(self.case)
        mdl.setEnsightStatus('on')
        mdl.setMedStatus('off')
        mdl.createPostDir("bonjour")
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<post-processing format="ensight7 gold" status="on"/>'\
                    '<post-processing format="med" status="off"/>'\
                    '<post_directory>bonjour</post_directory>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc == truc,'could not create post directory for post processing'

    def checkDelPostDir(self):
        """ Check whether a post-processing directory could be deleted """
        mdl = SolutionDomainModel(self.case)
        mdl.setEnsightStatus('on')
        mdl.setMedStatus('off')
        mdl.createPostDir("bonjour")
        mdl.delPostDir()
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<post-processing format="ensight7 gold" status="on"/>'\
                    '<post-processing format="med" status="off"/>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc == truc,'could not delete post directory for post processing'
        
    def checkSetPolygonalAndHedralNodesStatus(self):
        """ Check whether the status of node poly..._faces_splitting could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.setPolygonalNodeStatus('on')
        mdl.setPolyhedralNodeStatus('on')
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone>'\
                    '<polygonal_faces_cutting status="on"/>'\
                    '<polyhedral_faces_cutting status="on"/>'\
                '</standalone>'\
              '</solution_domain>'
        assert doc == truc,'could not set status for node poly..._faces_splitting'

    def checkdelPolygonalAndHedralNodes(self):
        """ Check whether  nodes poly..._faces_splitting could be deleted """
        mdl = SolutionDomainModel(self.case)
        mdl.setPolygonalNodeStatus('on')
        mdl.setPolyhedralNodeStatus('on')
        mdl.delPolygonalNode()
        mdl.delPolyhedralNode()
        truc = mdl.node_ecs.toString()
        doc = '<solution_domain>'\
                '<meshes_list/>'\
                '<standalone/>'\
              '</solution_domain>'
        assert doc == truc,'could not delete nodes poly..._faces_splitting'

    def checkMeshCommand(self):
        """ Check whether  command for meshes could be set """
        mdl = SolutionDomainModel(self.case)
        mdl.case['mesh_path'] = 'MAILLAGE'
        mdl.setMesh('fdc.des','des')
        mdl.setMesh('pic.des','des')
        mdl.setMesh('truc.machin','machin')
        cmd = mdl.getMeshCommand()

    def checkPasteAndCutCommand(self):
        """ Check whether  paste and cut command lines could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.case['mesh_path'] = 'MAILLAGE'
        mdl.setMesh('fdc.des','des')
        mdl.setMesh('pic.des','des')
        select = {}
        select['color'] = '1 2 3'
        select['group'] = 'toto'
        select['fraction'] = '0.1'
        select['plan'] = '0.8'
        select['type'] = ''
        select['reverse'] = 'off'
        select['semiconf'] = 'on'
        mdl.setPasteMeshesStatus('on')
        node = mdl.getNodeAdd(mdl.node_paste, 'faces_paste', 0)
        mdl.setFacesSelect(node,'faces_paste',select)
        mdl.setCutStatus('on')
        mdl.setCutAngle('0.05')
        truc = mdl.node_ecs.toString()
        cmd_paste = mdl.getPasteCommand()
        cmd_cut = mdl.getCutCommand()

    def checkPerioCommand(self):
        """ Check whether  perio command line could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setPeriodicStatus("on")
        mdl.setPeriodicTransformation(1,'rotation1')
        mdl.setRotationDir(1, 'rotation_x', '9.')
        mdl.setRotationDir(1, 'rotation_y', '8.')
        mdl.setRotationDir(1, 'rotation_z', '7.')
        mdl.setRotationAngle(1, '45.')
        mdl.setRotationCenter(1, 'rotation1', 'rotation_center_y', '66.')
        mdl.setPeriodicTransformation(1,'tr+rota2')
        mdl.setTranslationDir(1,'translation_y','3')
        mdl.setRotationMatrix(1,'tr+rota2', 'rotation_matrix_31', '31.31')
        cmd = mdl.getPerioCommand(1)

    def checkSyrthesCommand(self):
        """ Check whether  perio command line could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setSyrthesCouplingStatus('on')
        mdl.setSyrthes2dMeshStatus('on')
        select = {}
        select['color'] = '1 2 3'
        select['group'] = 'toto'
        select['reverse'] = 'off'
        select['semiconf'] = 'on'
        mdl = SolutionDomainModel(self.case)
        node = mdl.getNodeAdd(mdl.node_syrthes, 'faces_syrthes', 0)
        mdl.setFacesSelect(node,'faces_syrthes',select)
        cmd = mdl.getSyrthesCommand()


    def checkSimCommAndVerifMaillCommand(self):
        """ Check whether  perio command line could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setSimCommStatus('on')
        mdl.setMeshCheckStatus('on')
        cmd_sim = mdl.getSimCommCommand()
        cmd_verif = mdl.getVerifMaillCommand()


    def checkSelectCommand(self):
        """ Check whether  perio command line could be get """
        select = {}
        select['color'] = '1 2 3'
        select['group'] = 'toto'
        select['type'] = 'int'
        select['reverse'] = 'off'
        select['semiconf'] = 'on'
        mdl = SolutionDomainModel(self.case)
        node_select = mdl.getNodeAdd(mdl.node_standalone,'faces_select',0)
        mdl.setFacesSelect(node_select,'faces_select',select)
        cmd = mdl.getSelectCommand()

    def checkEnsAndMedCommand(self):
        """ Check whether  perio command line could be get """
        mdl = SolutionDomainModel(self.case)
        mdl.setEnsightStatus('on')
        mdl.setMedStatus('on')
        mdl.setPolygonalNodeStatus('on')
        mdl.setPolyhedralNodeStatus('on')
        cmd_ens = mdl.getEnsightCommand()
        cmd_med = mdl.getMedCommand()


def suite():
    testSuite = unittest.makeSuite(SolutionDomainTestCase, "check")
    return testSuite

def runTest():
    print "SolutionDomainTestCase"
    runner = unittest.TextTestRunner()
    runner.run(suite())










syntax highlighted by Code2HTML, v. 0.9.1