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

Get string representation of validation results the way print_results() displays #192

Open
jondricek opened this issue May 3, 2022 · 1 comment

Comments

@jondricek
Copy link

It would be great to be able to get the results of the stix2validator.print_results() function as a string representation. Take the base example currently in the Readme:

from stix2validator import validate_file, print_results

results = validate_file("stix_file.json")
print_results(results)

It would be nice to do e.g. foo = print_results(results) or something similar to get that as a string to work with.

Alternately maybe the results variable (a stix2validator.validators.FileValidationResults object) could have a __repr__ function built into it that provides the same output? If it went that direction it could probably make use of the FileValidationResults.as_dict() function here. Maybe?

Any thoughts on best way to implement this before I go off and make something up that works for me and do a pull request?

@clenk
Copy link
Contributor

clenk commented May 9, 2022

It might make sense to define __str__ on the FileValidationResults class, that calls .as_dict() as you propose. Then print_results() could aggregate the string representations of all the results and return it after it calls .log() on them.

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

No branches or pull requests

2 participants