def test_load_element_from_entry(self): std = self.std fact = aster_s.CommFile("fname.comm") elt = fact.build(std) lelt = std.load_elt_from_entry(elt.node.entry) self.assert_(ST.load_cls(elt.node) is aster_s.CommFile) self.assertEqual(lelt.node, elt.node)
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_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")
def build_case_from_brw_entry(self, std, case): """Add a command file from the object browser to the Aster case""" node = self._brw_node if node: if ST.is_eficas_file(node): efile = ST.attach_eficas_file(node) case.use(aster_s.CommFile(efile.read_fname())) else: case.use(aster_s.CommEntry(node.entry))
def test_run_comm_file_from_salome(self): fname = AT.write_comm(self.tmp_dir.add("comm_file_from_salome"), [ "DEBUT()", "FIN()", ]) case = self.std.add_case("c") case.use(aster_s.CommFile(fname)) case.use(aster_s.RemoveRmed()) self.check_status(case)
def add_case(self, name): """Add the Aster study case with the given name. 'command-file' and 'mesh' fields must be registered""" mod = self._mod std = mod.give_aster_study() prefs = aster_s_gui.AsterPreferences() case = std.add_case(self.find_new_name(std, name)) case.use(aster_s.CommFile(self.get_str("command-file"))) case.use(aster_s.SMeshEntry(self.give_field("mesh").node.entry)) if prefs.get(aster_s_gui.InteractiveFollowUp): case.use(aster_s.InteractivFollowUp())
def test_add_study_case_from_element_entry(self): std = self.std case = std.add_case("from-elt-file") comm_file = case.use(aster_s.CommFile("fname.comm")) case = std.add_case("from-elt-entry") comm_ref = case.use(aster_s.CommEntry(comm_file.node.entry)) self.assertEqual(comm_ref.node.give_source(), comm_file.node) self.assertEqual(comm_ref.read_name(), comm_file.read_name()) med_entry = aster_s.MedEntry(comm_file.node.entry) self.assertRaises(TypeError, case.use, med_entry)
def test_add_case_with_comm_and_mesh_entries(self): std = self.std comm = aster_s.CommFile("f.comm").build(std) mesh = std.sstd.load_meshes_from(self.med_fname)[0] data = ( ("comm", comm.node), ("mesh", mesh.node), ) creator = AM.add_study_case(self.mod) params = creator._params for key, node in data: params[key]._data_builder._brw_node = node creator.build_case() case = self.std.get_all(aster_s.Case)[0] self.assert_(case.get(aster_s.CommEntry)) self.assert_(case.get(aster_s.SMeshEntry))
def test_copy_section(self): root = AS.Elt(self.std.node, AS.Elt) cdata = aster_s.DataSection() cdata.name = "stest" data = cdata.build(root) data.use(aster_s.CommFile("f")) data.use(aster_s.WorkingDir("r")) copy = data.copy_to(root) self.assert_(copy is not data) self.assert_(copy.node.parent is root.node) self.assertEqual(copy.read_name(), "stest") self.assertEqual(copy.get(aster_s.CommFile).read_fname(), data.get(aster_s.CommFile).read_fname()) self.assert_(copy.get(aster_s.MedFile) is None) self.assertEqual(copy.get(aster_s.WorkingDir).read_value(), data.get(aster_s.WorkingDir).read_value())
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)
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))
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])
def test_copy_study_case_building_objects(self): root = AS.Elt(self.std.node.add_node("root"), AS.Elt) dest = AS.Elt(self.std.node.add_node("dest"), AS.Elt) sfile_fact = aster_s.CommFile("fcomm") sfile = sfile_fact.build(root) copy = sfile.copy_to(dest) self.assert_(copy is not dest) self.assert_(copy.node.parent is dest.node) self.assertEqual(copy.read_name(), "fcomm") self.assertEqual(copy.read_fname(), "fcomm") self.assert_(copy.sfile.load_type() is aster_s.CommFile) self.assert_(isinstance(copy, AS.File)) version = aster_s.Value("version", "STA10.0") velt = version.build(root) copy = velt.copy_to(dest) self.assert_(ST.load_cls(copy.node) is aster_s.Value) entry_compo = aster_s.CommEntry(sfile.node.entry) centry = entry_compo.build(root) copy = centry.copy_to(dest) self.assertEqual(copy.node.give_source().entry, centry.node.give_source().entry)
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))
class TestLoadDataFromObjectBrowser(AsterStdTest): def setUp(self): AsterStdTest.setUp(self) self.tmp_dir = SAT.TmpDir("load_data_from_object_browser") def tearDown(self): self.tmp_dir.clean() AsterStdTest.tearDown(self) def test_give_aster_study(self): std = self.std elt = AS.Elt(std.node.add_node("test"), AS.Elt) estd = elt.give_aster_study() self.assertEqual(estd.sstd.idx, std.sstd.idx) def test_load_element_from_entry(self): std = self.std fact = aster_s.CommFile("fname.comm") elt = fact.build(std) lelt = std.load_elt_from_entry(elt.node.entry) self.assert_(ST.load_cls(elt.node) is aster_s.CommFile) self.assertEqual(lelt.node, elt.node) 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) def test_build_med_file_from_smesh_entry_for_astk_case(self): std = self.std mesh = std.sstd.load_meshes_from(SAT.get_data("forma01a.mmed"))[0] wdir = self.tmp_dir.add("mesh_file_for_astk") med_fname = osp.join(wdir, "%s.mmed") cases = [] for idx in range(3): case = std.add_case("c%i" % idx) case._aster_case = astk.build_case("acs") cases.append(case) cases[0].use(aster_s.CommFile(osp.join(wdir, "fname.comm"))) cases[1].use(aster_s.WorkingDir(wdir)) fact = AS.find_factory(aster_s.SMeshEntry) for case in cases[:-1]: mesh_ref = case.use(aster_s.SMeshEntry(mesh.node.entry)) fact.add_to(case._aster_case, case, mesh_ref) bld = case._aster_case.export_bld self.assertEqual(bld.get(astk.MedFile).fname, med_fname % case.read_name()) case = cases[-1] mentry = case.use(aster_s.SMeshEntry(mesh.node.entry)) self.assertRaises(ValueError, fact.add_to, case._aster_case, case, mentry)
def build_case_from_fname(self, std, case): """Add a command file from disk to the Aster case""" fname = str(self.fname_entry.text()) case.use(aster_s.CommFile(fname))