Skip to content

Commit

Permalink
feat(ModelFolder): add classmethod for model folder
Browse files Browse the repository at this point in the history
Added a classmethod to allow initiating the ModelFolder class using the path to model folder itself instead of project folder. This is especially useful to read a folder which already has been created.
  • Loading branch information
mostaphaRoudsari committed Jul 4, 2020
1 parent 7969ed8 commit e36d47f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions honeybee_radiance_folder/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ def __init__(self, project_folder, model_folder='model', config_file=None):
self._aperture_groups_load = True # boolean to keep track of first load
self._dynamic_scene_load = True # boolean to keep track of first load

@classmethod
def from_model_folder(cls, model_folder, config_file=None):
"""Use model folder instead of project folder.
Args:
model_folder (str): Model folder as string. The folder will be created on
write if it doesn't exist already.
config_file (str): Optional config file to modify the default folder names. By
default ``folder.cfg`` in ``honeybee-radiance-folder`` will be used.
"""
project_folder, folder_name = os.path.split(model_folder)
return cls(project_folder, folder_name, config_file)

def model_folder(self, full=False):
"""Model root folder.
Expand Down
26 changes: 26 additions & 0 deletions tests/folder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,32 @@ def test_writer():
shutil.rmtree(folder_path, ignore_errors=True)


def test_writer_model_folder():
"""Test creating a new folder."""
folder_path = r'./tests/assets/temp/rad_model'
shutil.rmtree(folder_path, ignore_errors=True)
rad_folder = Folder.from_model_folder(folder_path)
rad_folder.write(folder_type=2, overwrite=True)

assert os.path.isdir(rad_folder.folder)
root_folder = rad_folder.model_folder(full=True)
assert os.path.isdir(root_folder)
subfolders = [
f for f in os.listdir(root_folder)
if os.path.isdir(os.path.join(root_folder, f))
]

cfg_names = ['GRID', 'VIEW'] + [k for k, v in config.minimal.items() if v is True]
expected_subfolders = [rad_folder._get_folder_name(f) for f in cfg_names]

assert len(subfolders) == len(expected_subfolders)
for f in expected_subfolders:
assert f in subfolders

# try to remove the folder
shutil.rmtree(folder_path, ignore_errors=True)


def test_reader():
radiance_folder = r'./tests/assets/project_folder'
rad_folder = Folder(radiance_folder)
Expand Down

0 comments on commit e36d47f

Please sign in to comment.