Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mpsonntag
Copy link
Contributor

The XMLParser.Reader comes with an option to ignore errors when opening a file while notifying the user with all encountered odml format problems, enabling users to fix problematic odml files using the odml library instead of having to directly manipulate the file content.

This option has now been added to the DictParser.Reader as well, also allowing to open and fix problematic odml JSON and YAML files.

The PR

  • adds all necessary changes in the DictParser.Reader to enable ignoring errors, collecting warnings and printing corresponding notifications. These changes close issue Implement 'DictReader.show_warnings' functionality #367.
  • changes the ODMLParser.Reader for JSON and YAML to now ignore_errors by default e.g. when using the odml.load function.
  • fixes a bug in format.revmap where the reverse mapping of an odml attribute would always return the case that the attribute is part of the format, even if it was not.
  • adds tests for parsing problematic JSON and YAML odml files.

Don't be afraid, most of the changes in this PR again increase the test coverage.

@coveralls
Copy link

coveralls commented Apr 23, 2020

Coverage Status

Coverage increased (+0.2%) to 76.945% when pulling 90a5810 on mpsonntag:dictParseIgnore into 206cbba on G-Node:master.

Copy link
Member

@jgrewe jgrewe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

One minor thing maybe for future tests, can we have the file creation strings (json, or yml) outside the sourcecode? it breaks the flow, methinks.

@achilleas-k achilleas-k linked an issue Apr 24, 2020 that may be closed by this pull request
@mpsonntag
Copy link
Contributor Author

I also don't particularly enjoy the way the file creation strings are formatted in these tests, but in most cases it makes it easier to see at one glance what is being tested and how. I am not dogmatic about it though, if there are any suggestions for a different setup, let me know! :)

except Exception as exc:
msg = "Section not created (%s)\n %s" % (sec_attrs, str(exc))
self.error(msg)
# If recovered in ignore_error mode, return empty list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue but I guess the list will only be empty if it's the first section right?

Could this do the same as the parse_properties() method and continue with the rest of the sections instead of returning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch; that's what it should do.

@achilleas-k
Copy link
Member

I also don't particularly enjoy the way the file creation strings are formatted in these tests, but in most cases it makes it easier to see at one glance what is being tested and how. I am not dogmatic about it though, if there are any suggestions for a different setup, let me know! :)

Could put them in a global fake constant in the file, right at the top, at indent level 0. Maybe something like:

file_content = """
Document:
  id: 82408bdb-1d9d-4fa9-b4dd-ad78831c797c
  sections:
  - id: d4f3120a-c02f-4102-a9fe-2e8b77d1d0d2
    name: sec

odml-version: '1.1'
""".strip()

That way you preserve the locality somewhat (it's in the same file), the content is indented as it will appear in the file without breaking flow, and the strip() takes care of removing leading and trailing newlines.

@jgrewe
Copy link
Member

jgrewe commented Apr 24, 2020

I would like that and it also gives you the option to call the variable e.g. something like: invalid_file_missing_id = "" or something similar

In the DictReader, do not stop and return after a Section.create
failed with an Exception, but continue with the next Section
in the list.
Moving file content in test_parser_json and test_parser_yaml
to increase readability.
Copy link
Member

@jgrewe jgrewe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
I think I really like this solution

@achilleas-k achilleas-k merged commit 1083db4 into G-Node:master Apr 27, 2020
@mpsonntag mpsonntag deleted the dictParseIgnore branch April 27, 2020 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement 'DictReader.show_warnings' functionality

4 participants