Пример #1
0
 def _bld_case(self, rep, lines, name="c", srv=None):
     """Build an Aster case especially for tests"""
     case_rep = self.tmp_dir.add(rep)
     case = AS.build_case(name)
     case.use(AS.CommFile(self._write_comm(case_rep, lines, srv)))
     case.remove(AS.RRMedFile)
     return case
 def test_raise_error_if_no_profil_or_fname(self):
     FP = AS.FromProfil
     case = AS.build_case("c", FP)
     case.use_profil(AS.build_aster_profil())
     try:
         exf = case.build_export_file()
         self.fail()
     except ValueError, exc:
         self.assertEqual(exc.args[0], FP._fname_mess)
Пример #3
0
    def test_run_from_astk_export_file(self):
        rep = self.tmp_dir.add("from_astk_export_file")
        export = self.write_forma01a(rep)

        case = AS.build_case("from-export", AS.FromExport)
        case.load_export(export)
        job = case.run()
        self.assert_(self.srv.wait_cnt())
        self.assert_(job.wait_result() is AS.SUCCESS)
Пример #4
0
    def test_run_from_aster_profil(self):
        rep = self.tmp_dir.add("from_astk_profil")
        prof = AS.build_aster_profil(self.write_forma01a(rep))
        export = osp.join(rep, "profil.export")

        case = AS.build_case("from-profil", AS.FromProfil)
        case.use_profil(prof)
        case.use_fname(export)
        job = case.run()
        self.assert_(self.srv.wait_cnt())
        self.assert_(job.wait_result() is AS.SUCCESS)
class TestPrepareASTKCase(UT.TestCase):
    def setUp(self):
        self.tmp_dir = TmpDir("manipulate_astk_parameters")

    def tearDown(self):
        self.tmp_dir.clean()

    def test_be_built_with_default_params(self):
        cfg_def = AS.AstkBuilder().build_default_cfg()
        case = AS.build_case("forma01a")
        case_cfg = case.export_bld.get(AS.Cfg)
        self.assert_(case_cfg is not cfg_def)
        self.assert_(case_cfg.equal(cfg_def))

    def test_add_existing_comm_and_med_files(self):
        case = AS.build_case("c")
        bld = case.export_bld
        comm = get_data("forma01a.comm")
        case.use(AS.CommFile(comm))
        self.assertEqual(bld.get(AS.CommFile).fname, comm)

        med = get_data("forma01a.mmed")
        case.use(AS.MedFile(med))
        self.assertEqual(bld.get(AS.MedFile).fname, med)

        self.assertRaises(IOError, AS.CommFile, "wrong-file")
        self.assertRaises(IOError, AS.MedFile, "wrong-file")
    def test_use_comm_file_rep_if_no_rep_given(self):
        rep = self.tmp_dir.add("no_rep_given")
        cfg = AS.Cfg()
        cfg.add("name", AS.Param("nomjob", "test"))
        cfg.add("mode", AS.Param("mode", "batch"))
        comm = osp.join(rep, "f.comm")
        open(comm, "w").close()
        case = AS.build_case("f")
        case.use(cfg)
        case.use(AS.CommFile(comm))

        fname = case.build_export_file().fname

        self.assert_(osp.isfile(fname))
        self.assertEqual(osp.dirname(fname), rep)
        self.assert_(case.export_bld.working_dir is None)
Пример #7
0
 def _build_astk_case_for(self, astk_case_type):
     """Build the ASTK case (aster.astk.Case) for the given astk
     case type"""
     acs = astk.build_case(self.node.read_name(), astk_case_type)
     self.data.fill_astk_case(acs, self)
     self._aster_case = acs
     return acs
Пример #8
0
 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)
 def test_write_export_file_for_stanley(self):
     wdir = self.tmp_dir.add("write_stanley_export")
     basename = "/tmp/aster/base_dir"
     res = [
         "P nomjob stanley",
         "P mode bash",
         "P special stanley%%NEXT%%R base %s DC 0" % basename,
     ]
     cfg = AS.Cfg()
     cfg.add("name", AS.Param("nomjob", "stanley"))
     cfg.add("m", AS.Param("mode", "bash"))
     case = AS.build_case("run_stanley", AS.RunStanley)
     case.use_working_dir(wdir)
     case.use(cfg)
     case.use(AS.StanleyBase(basename))
     exf = case.build_export_file()
     fid = open(exf.fname)
     lines = fid.read().splitlines()
     for line in res:
         self.assert_(line in lines, line)
     fid.close()
    def test_build_case_for_astk_profil(self):
        source = self.write_export_file("astk-profil", [
            "P nomjob j",
            "P mode inter",
            "F comm /aster/case.comm D 1",
            "F mess /tmp/mess R 6",
            "F resu /tmp/resu R 8",
        ])
        prof = AS.build_aster_profil(source)
        prof["nomjob"] = "p"
        prof.Get("R", "resu")[0]["path"] = "/aster/case.resu"
        export = osp.join(osp.dirname(source), "profil.export")

        case = AS.build_case("c", AS.FromProfil)
        case.use_profil(prof)
        case.use_fname(export)
        exf = case.build_export_file()
        self.assertEqual(exf.fname, export)
        self.assertEqual(exf.get_nomjob(), "p")
        resu = exf.get_result(AS.ResuFile)
        self.assertEqual(resu.fname, "/aster/case.resu")
 def test_be_built_with_default_params(self):
     cfg_def = AS.AstkBuilder().build_default_cfg()
     case = AS.build_case("forma01a")
     case_cfg = case.export_bld.get(AS.Cfg)
     self.assert_(case_cfg is not cfg_def)
     self.assert_(case_cfg.equal(cfg_def))
        med = get_data("forma01a.mmed")
        case.use(AS.MedFile(med))
        self.assertEqual(bld.get(AS.MedFile).fname, med)

        self.assertRaises(IOError, AS.CommFile, "wrong-file")
        self.assertRaises(IOError, AS.MedFile, "wrong-file")

    def write_export_file(self, rep_name, lines):
        fname = osp.join(self.tmp_dir.add(rep_name), "astk.export")
        fid = open(fname, "w")
        fid.write(os.linesep.join(lines))
        fid.close()
        return fname

    def test_add_existing_export_file(self):
        case = AS.build_case("c", AS.FromExport)
        export = self.write_export_file("existing-file", [
            "P nomjob j",
            "P mode inter",
        ])
        case.load_export(export)
        self.assertEqual(case.export_file.fname, export)
        self.assertRaises(IOError, case.load_export, "wrong-file")

    def test_build_case_for_astk_profil(self):
        source = self.write_export_file("astk-profil", [
            "P nomjob j",
            "P mode inter",
            "F comm /aster/case.comm D 1",
            "F mess /tmp/mess R 6",
            "F resu /tmp/resu R 8",