Exemplo n.º 1
0
def test_save_variables_cfg(config):
    # Create working dir
    assert config.episode_path is None
    config.set_episode_working_dir()
    assert config.episode_path is not None
    # Generate xml_tree and save it
    config.adapt_variables_to_cfg_and_idf()
    path_save = config.save_variables_cfg()
    # Read the first two lines and check is correct
    with open(path_save, "r") as f:
        assert f.readline().rstrip(
            '\n') == '<?xml version="1.0" encoding="ISO-8859-1"?>'
        assert f.readline().rstrip(
            '\n') == '<!DOCTYPE BCVTB-variables SYSTEM "variables.dtd">'
        f.close()
    # Read the path save cfg and check all is correct
    root = ElementTree.parse(path_save).getroot()
    # Check all values
    assert len(root.findall('variable')) == len(
        config.variables['observation']) + len(config.variables['action'])
    for i, variable in enumerate(root.findall('variable')):
        # If is not a comment
        assert variable.tag == 'variable'
        # obs
        if i < len(config.variables['observation']):
            assert variable.attrib['source'] == 'EnergyPlus'
            assert variable.find('EnergyPlus') is not None
            assert list(
                variable.find('EnergyPlus').attrib.keys()) == ['name', 'type']
        # action
        else:
            assert variable.attrib['source'] == 'Ptolemy'
            assert variable.find('EnergyPlus') is not None
            assert list(
                variable.find('EnergyPlus').attrib.keys()) == ['schedule']
Exemplo n.º 2
0
def test_save_building_model(config, eplus_path, idf_path):
    assert config.episode_path is None
    # Create episode path before save (else a exception will happen)
    config.set_episode_working_dir()
    assert config.episode_path is not None
    # save current model
    path_save = config.save_building_model()
    # Read the path save idf and check IDF saved
    idd = Idd(os.path.join(eplus_path, 'Energy+.idd'))
    building = Epm.from_idf(idf_path, idd_or_version=idd)
    assert (building.get_info() is not None) or (building.get_info() != '')
Exemplo n.º 3
0
def test_rm_past_history_dir(config):
    # Check num of dir in experiment path is less than 10
    n_dir = len([i for i in os.listdir(config.experiment_path)
                 if os.path.isdir(os.path.join(config.experiment_path, i))])
    assert n_dir < 10
    # Create more than 10 episodes dir
    for _ in range(15):
        config.set_episode_working_dir()
    # Check number of dirs is 10 (no more)
    n_dir = len([i for i in os.listdir(config.experiment_path)
                 if os.path.isdir(os.path.join(config.experiment_path, i))])
    assert n_dir == 10
Exemplo n.º 4
0
def test_set_episode_working_dir(config):
    # Check config has no episode path set up yet
    assert config.episode_path is None
    # Creating episode dir
    episode_path = config.set_episode_working_dir()
    # Check if new episode dir exists
    assert os.path.isdir(episode_path)
Exemplo n.º 5
0
def test_apply_weather_variability(config):
    # First set a epìsode dir in experiment
    assert config.episode_path is None
    config.set_episode_working_dir()
    assert config.episode_path is not None
    # Check apply None variation return original weather_path
    path_result = config.apply_weather_variability(variation=None)
    assert path_result == config._weather_path
    # Check with a variation
    variation = (1.0, 0.0, 0.001)
    path_result = config.apply_weather_variability(variation=variation)
    filename = config._weather_path.split('/')[-1]
    filename = filename.split('.epw')[0]
    filename += '_Random_%s_%s_%s.epw' % (
        str(variation[0]), str(variation[1]), str(variation[2]))
    path_expected = config.episode_path + '/' + filename
    assert path_result == path_expected
    assert os.path.exists(path_result)