Skip to content

Commit

Permalink
Merge pull request #194 from e10harvey/issue3_sanitized
Browse files Browse the repository at this point in the history
Fix test_with_attrfile bug and re-enable test
  • Loading branch information
e10harvey authored Jan 8, 2025
2 parents b2addd5 + 315e02b commit ade2669
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 23 deletions.
22 changes: 1 addition & 21 deletions opencsp/common/lib/file/AttributesManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,7 @@ def get_parser(
if parser_class in self.generic_parsers:
return self.generic_parsers[parser_class]

# find all parsers that are a subclass of the requested parser_class
subclass_parsers: list[aap.AbstractAttributeParser] = []
for parser in self.parsers:
if isinstance(parser, parser_class):
subclass_parsers.append(parser)
if len(subclass_parsers) == 1:
return subclass_parsers[0]
if len(subclass_parsers) == 0:
if error_on_not_found:
lt.error_and_raise(
RuntimeError,
"Programmer error in AttributesManager.get_parser(): "
+ f"there is an unregistered parser class {parser_class}! All AbstractAttributeParsers should "
+ "register themselves with RegisterClass() when their file is imported to prevent this error.",
)
else:
return None

# more than one subclass found, just return the first one
lt.debug(f"In AttributesManager.get_parser(): found more than one parser matching parser class {parser_class}")
return subclass_parsers[0]
return None

def set_parser(self, parser: aap.AbstractAttributeParser):
"""Sets the given parser as the default parser for the given class."""
Expand Down
2 changes: 1 addition & 1 deletion opencsp/common/lib/render/ImageAttributeParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def __init__(
attributes_file = os.path.join(opath, f"{oname}.txt")
self._previous_attr = am.AttributesManager()
self._previous_attr.load(attributes_file)
except:
except Exception as e:
pass
if self._previous_attr != None:
prev_image_attr: ImageAttributeParser = self._previous_attr.get_parser(self.__class__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_has_contents(self):
parser = iap.ImageAttributeParser(notes="")
self.assertEqual(True, parser.has_contents())

@pytest.mark.skip("See https://github.com/sandialabs/OpenCSP/issues/3")
def test_with_attrfile(self):
"""Load all values from the associated attributes file. Use the new current_image_source value."""
parser = iap.ImageAttributeParser(current_image_source=self.img_file)
Expand Down
2 changes: 2 additions & 0 deletions opencsp/common/lib/tool/file_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ def path_components(input_dir_body_ext: str):
See also: body_ext_given_file_dir_body_ext()
"""

dir = os.path.dirname(input_dir_body_ext)
body_ext = os.path.basename(input_dir_body_ext)
body, ext = os.path.splitext(body_ext)

return dir, body, ext


Expand Down

0 comments on commit ade2669

Please sign in to comment.