Skip to content

Commit

Permalink
Merge pull request #579 from VisLab/develop
Browse files Browse the repository at this point in the history
Corrected doc ref error and added subfolders to summary saving
  • Loading branch information
VisLab committed Jan 28, 2023
2 parents feac031 + 26ee51c commit 0362996
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 173 deletions.
160 changes: 0 additions & 160 deletions docs/source/api.rst

This file was deleted.

15 changes: 12 additions & 3 deletions hed/tools/remodeling/operations/base_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class BaseContext(ABC):
context_filename (str) Base filename for saving the context.
"""

INDIVIDUAL_SUMMARIES_PATH = 'individual_summaries'

def __init__(self, context_type, context_name, context_filename):
self.context_type = context_type
self.context_name = context_name
Expand Down Expand Up @@ -113,16 +116,22 @@ def save(self, save_dir, file_formats=['.txt'], include_individual=True, separat
self._save_separate(save_dir, file_format, time_stamp, summary)

def _save_separate(self, save_dir, file_format, time_stamp, summary):
file_name = os.path.realpath(os.path.join(save_dir, secure_filename(self.context_filename) + "_overall" +
this_save = os.path.join(save_dir, self.context_name + '/')
os.makedirs(os.path.realpath(this_save), exist_ok=True)
file_name = os.path.realpath(os.path.join(this_save, secure_filename(self.context_filename) + "_overall" +
time_stamp + file_format))

with open(file_name, 'w') as text_file:
text_file.write(summary["Dataset"])
individual = summary.get("Individual files", {})
individual= summary.get("Individual files", {})

if not individual:
return

individual_dir = os.path.join(this_save, self.INDIVIDUAL_SUMMARIES_PATH + '/')
os.makedirs(os.path.realpath(individual_dir), exist_ok=True)
for name, sum_str in individual.items():
file_name = os.path.realpath(os.path.join(save_dir,
file_name = os.path.realpath(os.path.join(individual_dir,
self.context_filename + "_" + name + time_stamp + file_format))
with open(file_name, 'w') as text_file:
text_file.write(sum_str)
Expand Down
24 changes: 16 additions & 8 deletions tests/tools/remodeling/operations/test_base_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
class TestContext(BaseContext):

def __init__(self):
super().__init__("TestContext", "Test", "test_context")
super().__init__("TestContext", "test", "test_context")
self.summary_dict["data1"] = "test data 1"
self.summary_dict["data2"] = "test data 2"


def _get_summary_details(self, include_individual=True):
summary = {"name": self.context_name}
if include_individual:
Expand Down Expand Up @@ -69,14 +68,23 @@ def test_save(self):
file_list1 = os.listdir(self.summary_dir)
self.assertFalse(file_list1)
test1.save(self.summary_dir, include_individual=True, separate_files=True)
file_list2 = os.listdir(self.summary_dir)
self.assertEqual(len(file_list2), 3)
dir_full = os.path.realpath(os.path.join(self.summary_dir, test1.context_name + '/'))
file_list2 = os.listdir(dir_full)
self.assertEqual(len(file_list2), 2)
dir_ind = os.path.realpath(os.path.join(self.summary_dir, test1.context_name + '/',
"individual_summaries/"))
file_list3 = os.listdir(dir_ind)
self.assertEqual(len(file_list3), 2)
test1.save(self.summary_dir, file_formats=['.json', '.tsv'], include_individual=False, separate_files=True)
file_list3 = os.listdir(self.summary_dir)
self.assertEqual(len(file_list3), 3+1)
file_list4 = os.listdir(dir_full)
self.assertEqual(len(file_list4), len(file_list2) + 1)
file_list5 = os.listdir(dir_ind)
self.assertEqual(len(file_list3), len(file_list5))
test1.save(self.summary_dir, file_formats=['.json', '.tsv'], include_individual=True, separate_files=True)
file_list3 = os.listdir(self.summary_dir)
self.assertEqual(len(file_list3), 3+1+3)
file_list6 = os.listdir(dir_full)
self.assertEqual(len(file_list6), len(file_list4) + 1)
file_list7 = os.listdir(dir_ind)
self.assertEqual(len(file_list7), len(file_list5) + 2)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/remodeling/test_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ def test_save_context(self):
dispatch1.save_context()
self.assertTrue(os.path.exists(summary_path))
file_list1 = os.listdir(summary_path)
self.assertEqual(len(file_list1), 4, "save_context creates correct number of summary files when run.")
self.assertEqual(len(file_list1), 2, "save_context creates correct number of summary files when run.")
dispatch1.save_context(save_formats=[])
file_list2 = os.listdir(summary_path)
self.assertEqual(len(file_list2), 4, "save_context must have a format to save")
self.assertEqual(len(file_list2), 2, "save_context must have a format to save")

def test_get_context_summaries(self):
with open(self.summarize_excerpt) as fp:
Expand Down

0 comments on commit 0362996

Please sign in to comment.