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

Add sorting to the list of paths before storing them to the golden copy #56

Conversation

juzen2003
Copy link
Collaborator

@juzen2003 juzen2003 commented Sep 12, 2024

Updates:

  • Update the test framework to sort the list of paths before storing to the golden copies. With --update param, now the golden copies are updated only if:
    • The golden copy doesn't exists
    • The file paths in the list are different than those in the golden copies.
  • If a list of paths has the same contents (paths) but different order than ones in the golden copy, they will be considered the same. And we won't update the golden copy in this case.
  • Update all of the golden copies in the test results folder:
    • The dictionary keys of opus products are sorted by 'group' and then 'priority'
    • The lists of paths in the golden copies are sorted.

Copy link
Collaborator

@rfrenchseti rfrenchseti left a comment

Choose a reason for hiding this comment

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

This pull has conflicts with the main branch that need to be resolved

with open(path, 'w') as f:
pprint.pp(data, stream=f)
print('\nCreate the golden copy', path)
# If the update param is given, compare the file first to make sure we don't write
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to do this? If the output is sorted properly, writing a new output file with identical content is fine.

import ast
from collections import OrderedDict
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to use OrderedDict. Python 3 guarantees that the order of dictionary keys will stay the same. This was only needed for Python 2.

@@ -39,22 +40,41 @@ def read_or_update_golden_copy(data, path, update):
"""

path = Path(path)
# Create the golden copy by using the current output
# Create the golden copy by using the current output if or the update param is given
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove "if OR the update"

return read_file(path)

def read_file(path):
"""Return data from the read file
Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW if we're going to start putting docstrings in, we should make them in Google Docstyle format. Less work to do later to change them.

@rfrenchseti rfrenchseti merged commit d963560 into main Sep 20, 2024
11 checks passed
@rfrenchseti rfrenchseti deleted the add_sorting_to_test_results_dictionary_before_storing_to_golden_copy branch September 20, 2024 23:08
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.

2 participants