Esempio n. 1
0
 def test_tree_attr(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources',
                             'xmltest.xml')
     xt = read_xml(xml_path)
     res = xt.get_sub_trees('global_params')
     res[0].get_tree_attr()
     self.assertTrue(res[0].get_tree_attr().get('fun') == '1')
Esempio n. 2
0
 def test_read(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources',
                             'simulation_cfg.xml')
     tr = simpy.read_from_xml(xml_path)
     self.assertTrue(tr.test_list.__len__() == 1)
     self.assertTrue(isinstance(tr.test_list, list))
     self.assertTrue(tr.param_configurations.__len__() == 2)
     self.assertTrue(isinstance(tr.param_configurations, dict))
     self.assertTrue(isinstance(tr.global_param, dict))
Esempio n. 3
0
 def test_sub_tree(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources',
                             'xmltest.xml')
     xt = read_xml(xml_path)
     res = xt.get_sub_trees('global_params')
     self.assertTrue(isinstance(res, list))
     self.assertTrue(res.__len__() > 0)
     res = xt.get_sub_trees('global_par222ams')
     self.assertTrue(res.__len__() == 0)
Esempio n. 4
0
 def test_iter_loop(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources',
                             'simulation_cfg.xml')
     tr = simpy.read_from_xml(xml_path)
     c = 0
     for t in tr:
         c += 1
         self.assertTrue(t.get_name() == 'blabla23')
         self.assertTrue(t.get_param('loss_q') == 1.812)
     self.assertTrue(c == 1)
     self.assertTrue(tr.get_global_param('cross_validation_k') == 40)
Esempio n. 5
0
    def test_enum(self):
        xml_path = os.path.join(get_current_folder_path(), 'resources',
                                'enum_example.xml')
        tr = simpy.read_from_xml(xml_path)

        class TestEnum(Enum):
            Test0 = 0
            Test2 = 1
            Test1 = 2

        for t in tr:
            er = t.read_enum(TestEnum)
            self.assertTrue(isinstance(er, list))
            self.assertTrue(er.__len__() == 2)
            self.assertTrue(TestEnum.Test0 in er)
            self.assertTrue(TestEnum.Test2 in er)
Esempio n. 6
0
'''
Created on Nov 6, 2017

@author: haih
'''
import simpy
from simpy.tests.tutils import get_current_folder_path
import os
import numpy as np


class ExampleSimulation(simpy.SimulationManger):
    def __init__(self, xml_path):
        self.sc = self.create(xml_path)  # generate simulation control

    def run(self):
        for t in self.sc.get_tests():  # loop over test
            result = t.generate_test_result('res_a', np.random.rand(1))
            self.sc.add_result(result)

        for i in self.sc.get_results():
            print(i.get_test_name())
            print(i.get_result('res_a'))


if __name__ == "__main__":
    xml_path = os.path.join(get_current_folder_path(),
                            'simulation_cfg.xml')  # set xml path
    test = ExampleSimulation(xml_path)  # init simulation
    test.run()  # run simulation
Esempio n. 7
0
 def test_overwrite(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources',
                             'test_example_overwrite.xml')
     tr = simpy.read_from_xml(xml_path)
     for t in tr:
         self.assertTrue(t.get_param('decay_steps') == 20)
Esempio n. 8
0
 def test_group_read(self):
     xml_path = os.path.join(get_current_folder_path(), 'resources', 'simulation_cfg_groups.xml')
     tr = simpy.read_from_xml(xml_path)
     self.assertTrue(tr.test_list.__len__() == 4)