X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fyacsloader_swig%2FTest%2FStdAloneYacsLoaderTest1.py;h=776c1e5b6fc84905728cb71df68b3c7de62c819a;hb=255150e4eec79294bbd06c7c464f309b4a264960;hp=8fe5e26b7cd14b7969bff88b9aadb7162be99045;hpb=e3255204c864201f5bc1aa040d4273ed2f44e8cd;p=modules%2Fyacs.git diff --git a/src/yacsloader_swig/Test/StdAloneYacsLoaderTest1.py b/src/yacsloader_swig/Test/StdAloneYacsLoaderTest1.py index 8fe5e26b7..776c1e5b6 100644 --- a/src/yacsloader_swig/Test/StdAloneYacsLoaderTest1.py +++ b/src/yacsloader_swig/Test/StdAloneYacsLoaderTest1.py @@ -1,4 +1,5 @@ -# Copyright (C) 2006-2016 CEA/DEN, EDF R&D +#!/usr/bin/env python3 +# Copyright (C) 2006-2023 CEA, EDF # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,6 +22,8 @@ import pilot import SALOMERuntime import loader import unittest +import tempfile +import os class StdAloneYacsLoaderTest1(unittest.TestCase): @@ -28,6 +31,7 @@ class StdAloneYacsLoaderTest1(unittest.TestCase): SALOMERuntime.RuntimeSALOME_setRuntime() self.r = pilot.getRuntime() self.l = loader.YACSLoader()# self.l.load("foreachImbr_tmp.xml") + self.workdir = tempfile.mkdtemp(suffix=".yacstest") pass def test1(self): @@ -80,14 +84,15 @@ class StdAloneYacsLoaderTest1(unittest.TestCase): self.assertEqual(p.getState(),pilot.DONE) zeResu=node3.getOutputPort("o3").get() self.assertEqual(zeResu,[[[3.,3.],[4.,4.,4.]],[[12.],[13.,13.],[14.,14.,14.]],[[22.],[23.,23.],[24.,24.,24.],[25.,25.,25.,25.]]]) - p.saveSchema("foreachImbrBuildFS.xml") + fname = os.path.join(self.workdir, "foreachImbrBuildFS.xml") + p.saveSchema(fname) pass def test2(self): """ Non regression test. When input/output declared as pyobj hiding a string type to go to or from a ForEachLoop it previous lead to an error. """ - fname="BugPyObjStrInYacs.xml" + fname=os.path.join(self.workdir, "BugPyObjStrInYacs.xml") p=self.r.createProc("pr") tc0=p.createInterfaceTc("python:obj:1.0","pyobj",[]) tc1=p.createSequenceTc("list[pyobj]","list[pyobj]",tc0) @@ -131,7 +136,7 @@ class StdAloneYacsLoaderTest1(unittest.TestCase): def test3(self): """ Non regression test Mantis 23234 CEA1726""" - fname="test23234.xml" + fname=os.path.join(self.workdir, "test23234.xml") p=self.r.createProc("Test23234") ti=p.createType("int","int") initNode=self.r.createScriptNode("","init") @@ -178,7 +183,6 @@ def sum(i): def test4(self): """ test linked to TestSaveLoadRun.test20. This is a smaller test coming from EDF autotest""" - xmlFileName="test4.xml" p=self.r.createProc("test26") n=self.r.createScriptNode("","node1") n.setScript("import os") @@ -195,7 +199,7 @@ def sum(i): def test5(self): """ Test focusing P13268. If I connect a list[pyobj] output inside a ForEach to a list[pyobj] outside a foreach it works now.""" #self.assertTrue(False) - fname="testP1328.xml" + fname=os.path.join(self.workdir, "testP1328.xml") p=self.r.createProc("testP1328") tc0=p.createInterfaceTc("python:obj:1.0","pyobj",[]) tc1=p.createSequenceTc("list[pyobj]","list[pyobj]",tc0) @@ -232,7 +236,7 @@ def sum(i): def test6(self): """ Test focusing on P13766. Test of a connection of 2 foreach at same level where the output pyobj is connected to the list[pyobj] input samples of the 2nd foreach""" - fname="testP13766.xml" + fname=os.path.join(self.workdir, "testP13766.xml") p=self.r.createProc("testP13766") tc0=p.createInterfaceTc("python:obj:1.0","pyobj",[]) tc1=p.createSequenceTc("list[pyobj]","list[pyobj]",tc0) @@ -275,6 +279,74 @@ def sum(i): self.assertEqual(p.getState(),pilot.DONE) self.assertEqual(p.getChildByName("n3").getInputPort("i8").getPyObj(),[[0,0,0,0,0,0],[1,1,1,1,1,1],[2,2,2,2,2,2],[3,3,3,3,3,3],[4,4,4,4,4,4],[5,5,5,5,5,5],[6,6,6,6,6,6],[7,7,7,7,7,7],[8,8,8,8,8,8],[9,9,9,9,9,9]]) pass + + def test7(self): + """EDF17963 : Python3 porting. Py3 Pickeling generates more often byte(0) into the bytes. This reveals an incorrect management of Python Bytes -> Any String that leads to truncated bytes.""" + + entree_script="""Study = "toto" +print("Entree", Study)""" + + pyscript0_script="""entier = 42 +print("PyScript0",entier) +""" + + sortie_script="""import numpy as np +assert(isinstance(resultats,np.ndarray)) +assert(resultats==np.array(range(1),dtype=np.int32)) +""" + + nbWorkers=1 + + SALOMERuntime.RuntimeSALOME.setRuntime() + r=SALOMERuntime.getSALOMERuntime() + # + p0=r.createProc("run") + # + td=p0.createType("double","double") + ti=p0.createType("int","int") + ts=p0.createType("string","string") + tp=p0.createInterfaceTc("python:obj:1.0","pyobj",[]) + tdd=p0.createSequenceTc("seqdouble","seqdouble",td) + tds=p0.createSequenceTc("seqstr","seqstr",ts) + tdp=p0.createSequenceTc("list[pyobj]","list[pyobj]",tp) + # + n0 = r.createScriptNode("Salome","Entree") + n0.setExecutionMode("local") + n0.setScript(entree_script) + o0 = n0.edAddOutputPort("Study",tp) + p0.edAddChild(n0) + # + n1 = r.createOptimizerLoop("MainLoop","async_plugin.py","myalgosync",True) + n1.edGetNbOfBranchesPort().edInitInt(nbWorkers) + p0.edAddChild(n1) + # + n10=r.createScriptNode("Salome","PyScript0") + n10.setScript(pyscript0_script) + i1 = n10.edAddInputPort("double",td) + o1 = n10.edAddOutputPort("entier",ti) + n10.setExecutionMode("local") + n1.edAddChild(n10) + # + n2 = r.createScriptNode("Salome","Sortie") + n2.setExecutionMode("local") + n2.setScript(sortie_script) + i2 = n2.edAddInputPort("resultats",tp) + p0.edAddChild(n2) + # + p0.edAddCFLink(n0,n1) + p0.edAddCFLink(n1,n2) + # + p0.edAddLink(o0,n1.getInputPort("algoInit")) + p0.edAddLink(n1.getOutputPort("algoResults"),i2) + p0.edAddLink(n1.getOutputPort("evalSamples"),i1) + p0.edAddLink(o1,n1.getInputPort("evalResults")) + # + #p0.saveSchema(fname) + # + ex=pilot.ExecutorSwig() + ex.RunW(p0,0) + self.assertTrue(p0.getEffectiveState() == pilot.DONE) + pass def tearDown(self): del self.r