Factorize common code in Pinfo #5014
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
One line description of pull request
Factorizes duplicated code in Pinfo.
Description:
In
plaso/cli/pinfo_tool.py, both methods_CalculateStorageCounters()and_CompareStores()have duplicated codes that only varies in data but not in behavior. Like any duplicated code, modifying one path implies to also modify all the other paths. This is error prone and it hurts extensibility.This merge request, factorize those code and provides a test basis for said methods. Also, it cuts the code footprint by half. The behavior should be identical and printing differences in storage preserves the same order.
Additional Context
I'm working on adding a new "data type counter" into the storage file. I already have a working patch but it hurts me to add another duplicated code in those paths. So, this is kinda of a "pre-requisite" patch.
Concerning this MR itself, I have a few questions (mostly regarding tests):
_CompareStores,testPrivateCompareStoressincetestCompareStoresalready exists. Is this name fine?testPrivateCompareStores. Is this how you would approach it or do you prefer checking it from an actual file instead?counterslist in_CompareStoressounds like something that should goes into class attribute, so we have a "single source of truth" (both in code and tests). What do you think about it?Regards,