Example #1
0
def test_dump_datastate_archive(core, project, var_tree, tmpdir):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)
                                   
    hydro_branch = var_tree.get_branch(core, project, "Mock Module")
    hydro_branch.read_test_data(core,
                                project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
                                             
    eco_branch = var_tree.get_branch(core, project, "Mock Theme")
    eco_branch.read_test_data(core,
                              project,
                              os.path.join(dir_path,
                                           "inputs_economics.pkl"))

    datastate_file_name = "my_datastate.dts"
    datastate_file_path = os.path.join(str(tmpdir), datastate_file_name)
    
    core.dump_datastate(project, datastate_file_path)
    
    assert os.path.isfile(datastate_file_path)
Example #2
0
def test_dump_datastate_nodir(core, project, var_tree):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)

    with pytest.raises(ValueError):
        core.dump_datastate(project, "some_path")
Example #3
0
def test_load_project_archive(core, project, var_tree, tmpdir):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)
                                   
    hydro_branch = var_tree.get_branch(core, project, "Mock Module")
    hydro_branch.read_test_data(core,
                                project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
                                             
    eco_branch = var_tree.get_branch(core, project, "Mock Theme")
    eco_branch.read_test_data(core,
                              project,
                              os.path.join(dir_path,
                                           "inputs_economics.pkl"))

    project_file_name = "my_project.prj"
    project_file_path = os.path.join(str(tmpdir), project_file_name)
    
    core.dump_project(project, project_file_path)

    del(project)
    
    assert os.path.isfile(project_file_path)
    
    new_root = os.path.join(str(tmpdir), "test")
    os.makedirs(new_root)
    
    move_file_path = os.path.join(str(tmpdir), "test", project_file_name)
    
    shutil.copy2(project_file_path, move_file_path)
    
    loaded_project = core.load_project(move_file_path)
    active_sim = loaded_project.get_simulation()

    assert loaded_project.check_integrity()
    assert active_sim.get_title() == "Default"
    assert "Mock Module" in module_menu.get_scheduled(core, loaded_project)
Example #4
0
def test_OrderedSim_get_output_ids_valid_statuses(core, project):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)
    test = project.get_simulation()
    
    result = test.get_output_ids(valid_statuses=["satisfied"])
        
    assert set(result) == set(['hidden.pipeline_active'])
Example #5
0
def test_OrderedSim_get_output_ids_hub_id(core, project):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)
    test = project.get_simulation()
    
    result = test.get_output_ids(hub_id="modules")
        
    assert set(result) == set(['project.annual_energy',
                               'project.number_of_devices',
                               'project.layout'])
Example #6
0
def test_load_datastate_bad_id(core, project, var_tree, tmpdir):
    
    project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, project, "Mock Module")
    theme_menu.activate(core, project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, project)
                                   
    hydro_branch = var_tree.get_branch(core, project, "Mock Module")
    hydro_branch.read_test_data(core,
                                project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
                                             
    eco_branch = var_tree.get_branch(core, project, "Mock Theme")
    eco_branch.read_test_data(core,
                              project,
                              os.path.join(dir_path,
                                           "inputs_economics.pkl"))
    core.dump_datastate(project, str(tmpdir))
    
    # Modify the json file with an entry not in the catalogue
    datastate_file_path = os.path.join(str(tmpdir), "datastate_dump.json")
    
    with open(datastate_file_path, 'r') as f:
        data = json.load(f)
        data["data"]["fake.entry"] = ""
    
    # Rewrite the file
    os.remove(datastate_file_path)
    
    with open(datastate_file_path, 'w') as f:
        json.dump(data, f)
    
    # Try to load the datastate
    core.load_datastate(project, str(tmpdir))
    
    assert True
Example #7
0
def test_load_datastate_archive(core, project, var_tree, tmpdir):
    
    temp_project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, temp_project, "Mock Module")
    theme_menu.activate(core, temp_project,  "Mock Theme")
    
    project_menu.initiate_dataflow(core, temp_project)
                                   
    hydro_branch = var_tree.get_branch(core, temp_project, "Mock Module")
    hydro_branch.read_test_data(core,
                                temp_project,
                                os.path.join(dir_path,
                                             "inputs_wp2_tidal.pkl"))
                                             
    eco_branch = var_tree.get_branch(core, temp_project, "Mock Theme")
    eco_branch.read_test_data(core,
                              temp_project,
                              os.path.join(dir_path,
                                           "inputs_economics.pkl"))


    datastate_file_name = "my_datastate.dts"
    datastate_file_path = os.path.join(str(tmpdir), datastate_file_name)
    
    core.dump_datastate(temp_project, datastate_file_path)
    
    del(temp_project)
    
    assert os.path.isfile(datastate_file_path)
    
    new_root = os.path.join(str(tmpdir), "test")
    os.makedirs(new_root)
    
    move_file_path = os.path.join(str(tmpdir), "test", datastate_file_name)
    shutil.copy2(datastate_file_path, move_file_path)
    
    temp_project = deepcopy(project) 

    project_menu = ProjectMenu()
    module_menu = ModuleMenu()
    theme_menu = ThemeMenu()

    module_menu.activate(core, temp_project, "Mock Module")
    
    project_menu.initiate_dataflow(core, temp_project)
    
    assert not core.has_data(temp_project, "device.turbine_interdistance")
    
    core.load_datastate(temp_project, move_file_path)

    assert temp_project.check_integrity()
    assert core.has_data(temp_project, "device.turbine_interdistance")
Example #8
0
def theme_menu(core):
    '''Share a ModuleMenu object'''  
    
    return ThemeMenu()