Beispiel #1
0
    def test_store_params_into_section(self):
        cdata = aster_s.DataSection()
        data = cdata.build(self.std)

        self.assert_(data.get(aster_s.CommFile) is None)
        compo = aster_s.CommFile("file.txt")
        comm = data.use(compo)
        comm = ST.File(comm.node)
        self.assertEqual(comm.read_name(), "file.txt")
        self.assertEqual(comm.read_fname(), "file.txt")
        self.assert_(comm.load_type() is aster_s.CommFile)

        self.assert_(data.get(aster_s.MedFile) is None)
        fname = "/tmp/aster/mesh.mmed"
        med_fact = aster_s.MedFile(fname)
        med = data.use(med_fact)
        mmed = ST.File(med.node)
        self.assertEqual(mmed.read_name(), "mesh.mmed")
        self.assertEqual(mmed.read_fname(), fname)
        self.assert_(mmed.load_type() is aster_s.MedFile)

        self.assert_(data.get(aster_s.WorkingDir) is None)
        data.use(aster_s.WorkingDir("/tmp/aster"))
        rep = ST.Line(data.node.find_node("working-dir"))
        self.assertEqual(rep.read_value(), "/tmp/aster")
Beispiel #2
0
class TestCopyStudyCases(AsterStdTest):

    def test_copy_study_case(self):
        std = self.std
        cfg = astk.Cfg()
        case = std.add_case("c")
        case.use(aster_s.WorkingDir("/tmp/a"))
        case.use(aster_s.AstkParams(cfg))
        case.use(aster_s.CommFile("f"))
        case.use(aster_s.RemoveRmed())
        case._build_results()
        case.results.use(aster_s.MessFile("f.mess"))
        
        copy = case.copy()
        # New node used
        self.assertEqual([case.node.entry, copy.node.entry],
                         [node.entry for node in std.node.get_children()])
        # Data section
        self.assert_(copy.data.node.parent is copy.node)
        comms = copy.get_all(aster_s.CommFile)
        self.assertEqual(len(comms), 1)
        self.assertEqual(comms[0].read_fname(), "f")
        # Astk parameters 
        self.assert_(copy.params.node.parent is copy.node)
        pcfg = copy.params.get_cfg()
        self.assert_(pcfg is not cfg)
        self.assert_(pcfg.equal(cfg))
        # Results
        self.assert_(copy.results.node.parent is copy.node)
        mess = copy.get_all(aster_s.MessFile)
        self.assertEqual(len(mess), 1)
        self.assertEqual(mess[0].read_fname(), "f.mess")
        # Others
        self.assert_(copy.get(aster_s.RemoveRmed).read_value())

    def test_copy_study_case_several_times(self):
        case = self.std.add_case("c")
        case.use(aster_s.CommFile("c"))
        case.use(aster_s.MedFile("m"))
        case = AS.load_elt_from_node(case.node)
        case.copy()
        case = AS.load_elt_from_node(case.node)
        case.copy()
        data = case.get(aster_s.DataSection)
        self.assertEqual(len(data.get_all_elts()), 2)
Beispiel #3
0
    def test_add_case_with_eficas_and_med_file_entry(self):
        import aster_s.salome_tree as stree
        std = self.std
        # Adding fake eficas file
        fname = "/aster/case1/eficas-file.comm"
        eficas_node = std.sstd.add_root("eficas-file")
        eficas_node.get_attr(stree.Value).write(fname)
        eficas_node.get_attr(stree.Type).write(stree.EficasFile.ftype)
        med = aster_s.MedFile("f.mmed").build(std)

        creator = AM.add_study_case(self.mod)
        blds = [creator._params[key]._data_builder for key in ("comm", "mesh")]
        blds[0]._brw_node = eficas_node
        blds[1]._brw_node = med.node
        creator.build_case()
        case = self.std.get_all(aster_s.Case)[0]
        comm = case.get(aster_s.CommFile)
        self.assert_(comm.read_fname(), fname)
        self.assert_(case.get(aster_s.MedEntry))
Beispiel #4
0
    def test_build_astk_case(self):
        acfg = astk.Cfg()
        acfg.add("name", astk.Param("n")) 
        comm = __file__
        mmed = UT.__file__

        case = self.std.add_case("a")
        case.use(aster_s.AstkParams(acfg))
        case.use(aster_s.CommFile(comm))
        acs = case.build_astk_case()
        bld = acs.export_bld
        self.assert_(bld.working_dir is None)
        cfg = bld.get(astk.Cfg)
        self.assert_(cfg.equal(acfg))
        self.assertEqual(bld.name, "a")
        self.assertEqual(bld.get(astk.CommFile).fname, comm)
        self.assert_(not bld.get(astk.MedFile))

        case.use(aster_s.WorkingDir("/tmp/a"))
        acs = case.build_astk_case()
        self.assertEqual(acs.export_bld.working_dir, "/tmp/a")

        case.use(aster_s.MedFile(mmed))
        case.write_name("c")
        acs = case.build_astk_case()
        bld = acs.export_bld
        self.assertEqual(bld.name, "c")
        self.assertEqual(bld.get(astk.MedFile).fname, mmed)

        case.use(aster_s.HasBaseResult())
        acs = case.build_astk_case()
        bld = acs.export_bld
        self.assert_(bld.get(astk.Base))

        comm_file = case.get(aster_s.CommFile)
        med_file = case.get(aster_s.MedFile)
        case = self.std.add_case("d")
        case.use(aster_s.CommEntry(comm_file.node.entry))
        case.use(aster_s.MedEntry(med_file.node.entry))
        acs = case.build_astk_case()
        bld = acs.export_bld
        self.assertEqual(bld.get(astk.CommFile).fname, comm)
        self.assertEqual(bld.get(astk.MedFile).fname, mmed)
Beispiel #5
0
    def test_update_case_on_new_entries(self):
        std = self.std
        case = self.case
        comms = [aster_s.CommFile(name).build(std) for name in ("c1", "c2")]
        med_fname = ST.get_data("forma01a.mmed")
        mesh = std.sstd.load_meshes_from(med_fname)[0]
        case.use(aster_s.CommEntry(comms[0].node.entry))
        case.use(aster_s.MedFile("m"))

        editor = AM.edit(self.mod, self.case)
        datas = [editor._params[key] for key in ("comm", "mesh")]
        for data in datas:
            data._selector.setCurrentIndex(0)
        blds = [data._data_builder for data in datas]
        blds[0]._brw_node = comms[1].node
        blds[1]._brw_node = mesh.node
        editor.build_case()

        centry = case.get(aster_s.CommEntry)
        self.assertEqual(centry.node.give_source().entry, comms[1].node.entry)
        self.assert_(not case.get(aster_s.MedFile))
        self.assert_(case.get(aster_s.SMeshEntry))
Beispiel #6
0
class TestEditCases(UT.TestCase):
    def setUp(self):
        self.mod = AM.GuiBuilder().give_mod()
        self.std = self.mod.give_aster_study()
        bcase = self.std.add_case("Aster case")
        self.case = AS.load_elt_from_node(bcase.node)

    def tearDown(self):
        self.case.remove()

    def test_display_name(self):
        editor = AM.edit(self.mod, self.case)
        self.assertEqual(editor._name.text(), self.case.read_name())

    def test_edit_comm_and_med_files(self):
        case = self.case
        case.use(aster_s.CommFile("/aster/f.comm"))
        case.use(aster_s.MedFile("f.mmed"))
        editor = AM.edit(self.mod, case)
        sels = [editor._params[key] for key in ("comm", "mesh")]
        fnames = [sel._data_builder.fname_entry.text() for sel in sels]
        self.assertEqual(fnames, ["/aster/f.comm", "f.mmed"])
        idxs = [sel._selector.currentIndex() for sel in sels]
        self.assertEqual(idxs, [1, 1])
Beispiel #7
0
        self.assertEqual(editor._name.text(), self.case.read_name())

    def test_edit_comm_and_med_files(self):
        case = self.case
        case.use(aster_s.CommFile("/aster/f.comm"))
        case.use(aster_s.MedFile("f.mmed"))
        editor = AM.edit(self.mod, case)
        sels = [editor._params[key] for key in ("comm", "mesh")]
        fnames = [sel._data_builder.fname_entry.text() for sel in sels]
        self.assertEqual(fnames, ["/aster/f.comm", "f.mmed"])
        idxs = [sel._selector.currentIndex() for sel in sels]
        self.assertEqual(idxs, [1, 1])

    def test_not_write_comm_and_med_files_if_none(self):
        case = self.case
        compos = [aster_s.CommFile(""), aster_s.MedFile("")]
        felts = [case.use(compo) for compo in compos]
        self.assert_([felt.read_fname() for felt in felts], [None, None])
        editor = AM.edit(self.mod, case)
        fnames = [
            editor._params[key]._data_builder.fname_entry.text()
            for key in ("comm", "mesh")
        ]
        self.assertEqual(fnames, ["", ""])

    def test_edit_comm_and_med_entries(self):
        case = self.case
        compos = (aster_s.CommFile("c"), aster_s.MedFile("m"))
        felts = [compo.build(self.std) for compo in compos]
        fentries = [felt.node.entry for felt in felts]
        case.use(aster_s.CommEntry(felts[0].node.entry))
 def build_case_from_fname(self, std, case):
     """Add a med file to the aster case"""
     fname = str(self.fname_entry.text())
     case.use(aster_s.MedFile(fname))