Пример #1
0
    def test_display_astk_parameters_for_solver(self):
        cfg = astk.Cfg()
        cfg.add("dbg", astk.Param("debug", "nodebug"))
        cfg.add("mem", astk.Attr("memory", 128))

        cparams = aster_s.AstkParams(cfg)
        cparams.name = "p"
        params = cparams.build(self.std)
        pnode = params.node
        self.assertEqual(params.read_name(), "p")
        params.attach_cfg(cfg)
        dbg = ST.Line(pnode.find_node("dbg"))
        self.assertEqual(dbg.read_name(), "dbg")
        self.assertEqual(dbg.read_value(), "nodebug")
        self.assertEqual(params["dbg"], "nodebug")

        mem = ST.Line(pnode.find_node("mem"))
        self.assertEqual(mem.read_value(), 128)
        self.assertEqual(mem.read_visible_value(), '128')
        params["mem"] = 256
        self.assertEqual(mem.read_value(), 256)
        self.assertEqual(mem.read_visible_value(), '256')
        
        params["dbg"] = "debug"
        astk_cfg = params.get_cfg()
        self.assertEqual(astk_cfg["mem"].value, 256)
        self.assertEqual(astk_cfg["dbg"].value, "debug")
Пример #2
0
 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())
Пример #3
0
    def test_clear_section_when_new_configuration_attached(self):
        cfg = astk.Cfg()
        cfg.add("mem", astk.Attr("memory", 128))
        parent = AS.Elt(self.std.node.add_node("p"), AS.Elt)

        cparams = aster_s.AstkParams(cfg)
        params = cparams.build(parent)
        mem = params.get_elt("mem")
        self.assert_(mem.node.is_alive())
        
        cfg = astk.Cfg()
        cfg.add("dbg", astk.Param("debug"))
        params.attach_cfg(cfg)
        self.assert_(not mem.node.is_alive())
Пример #4
0
    def test_add_study_case_from_comm_file(self):
        std = self.std
        
        comm_file = __file__
        med_file = UT.__file__
        case = std.add_case("Aster case")
        self.assertEqual(case.read_name(), "Aster case")

        # Configuration
        cfg = case.get(aster_s.AstkParams)
        dcfg = astk.build_default_cfg()
        dcfg["name"].value = case.read_name()
        self.assert_(cfg.get_cfg().equal(dcfg))
        astk_cfg = astk.Cfg()
        cfg = aster_s.AstkParams(astk_cfg)
        case.use(cfg)
        self.assert_(case.get(aster_s.AstkParams).get_cfg().equal(astk_cfg))

        # Comm and med files
        Comm = aster_s.CommFile
        Med = aster_s.MedFile
        case.use(Comm(comm_file))
        case.use(Med(med_file))
        med = case.get(Med)
        self.assertEqual(med.read_fname(), med_file)
        comm = case.get(Comm)
        self.assertEqual(comm.read_fname(), comm_file)

        # Working directory
        Elt = aster_s.WorkingDir
        self.assert_(case.get(Elt) is None)
        case.use(Elt("/tmp/a"))
        self.assertEqual(case.get(Elt).read_value(), "/tmp/a")

        # Has rmed result
        Elt = aster_s.RemoveRmed
        # XXX should be removed
        self.assert_(case.get(Elt) is None)
        case.use(Elt())
        self.assert_(case.get(Elt).read_value())

        # Has base result 
        Elt = aster_s.HasBaseResult
        self.assert_(case.get(Elt) is None)
        case.use(Elt())
        self.assert_(case.get(Elt).read_value())
Пример #5
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)