Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions hed/models/definition_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def get_definition(self, replace_tag, placeholder_value=None, return_copy_of_tag
replace_tag = replace_tag.copy()
output_contents = [replace_tag]
if self.contents:
output_group = self.contents
output_group = copy.deepcopy(self.contents)
if placeholder_value:
output_group = copy.deepcopy(self.contents)
placeholder_tag = output_group.find_placeholder_tag()
if not placeholder_tag:
raise ValueError("Internal error related to placeholders in definition mapping")
Expand Down
57 changes: 56 additions & 1 deletion tests/models/test_string_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
from hed import HedString, load_schema_version
from hed.models.string_util import split_base_tags, split_def_tags
from hed.models.string_util import split_base_tags, split_def_tags, gather_descriptions
import copy


Expand Down Expand Up @@ -131,5 +131,60 @@ def test_case_5(self):
self.check_split_def_tags(hed_string, def_names, expected_string, expected_string2)


class TestGatherDescriptions(unittest.TestCase):
def setUp(self):
self.schema = load_schema_version()

def test_gather_single_description(self):
input_str = "Sensory-event, Description/This is a test."
hed_string = HedString(input_str, hed_schema=self.schema)

result = gather_descriptions(hed_string)
expected_result = "This is a test."

self.assertEqual(result, expected_result)
self.assertNotIn("Description", str(result))

def test_gather_multiple_descriptions(self):
input_str = "Sensory-event, Description/First description, Second-tag, Description/Second description."
hed_string = HedString(input_str, hed_schema=self.schema)

result = gather_descriptions(hed_string)
expected_result = "First description. Second description."

self.assertEqual(result, expected_result)
self.assertNotIn("Description", str(result))

def test_gather_no_descriptions(self):
input_str = "Sensory-event, No-description-here, Another-tag"
hed_string = HedString(input_str, hed_schema=self.schema)

result = gather_descriptions(hed_string)
expected_result = ""

self.assertEqual(result, expected_result)
self.assertNotIn("Description", str(result))

def test_gather_descriptions_mixed_order(self):
input_str = "Sensory-event, Description/First., Another-tag, Description/Second, Third-tag, Description/Third."
hed_string = HedString(input_str, hed_schema=self.schema)

result = gather_descriptions(hed_string)
expected_result = "First. Second. Third."

self.assertEqual(result, expected_result)
self.assertNotIn("Description", str(result))

def test_gather_descriptions_missing_period(self):
input_str = "Sensory-event, Description/First, Description/Second"
hed_string = HedString(input_str, hed_schema=self.schema)

result = gather_descriptions(hed_string)
expected_result = "First. Second."

self.assertEqual(result, expected_result)
self.assertNotIn("Description", str(result))


if __name__ == '__main__':
unittest.main()