Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test_with_attrfile bug and re-enable test #194

Merged
merged 2 commits into from
Jan 8, 2025
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
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
Loading