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 handling subclassed evidence support #80
Conversation
79cccd3
to
cd53b75
Compare
- Add FromEvidence named tuple - Add passing FromEvidence to with_*_evidences decorators - Add passing FromEvidence to evidences context manager - Replace os.path usage with pathlib.PurePath - Add content_as_json property to all Evidence objects - Updated docs
cd53b75
to
dff8b54
Compare
@cletomartin as discussed over Slack, at your suggestion, I've changed the FromEvidence named tuple functionality to be part of a class method ( |
- A dictionary where a key is an evidence short name and a value | ||
is either string path or a LazyLoader namedtuple | ||
|
||
Using the LazyLoader namedtuple tells this context manager to cast |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
compliance/evidence.py
Outdated
ev_class = None | ||
if isinstance(from_ev, LazyLoader): | ||
path = from_ev.path | ||
if issubclass(from_ev.ev_class, get_evidence_class(type_str)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could use an explanatory comment - if I'm reading it right, it'll make an instance of the class defined in the lazy loader if that class is a subclass of the type_str, otherwise will make the evidence be of the type in type_str.
How about:
if issubclass(from_ev.ev_class, get_evidence_class(type_str)): | |
ev_class = get_evidence_class(type_str) | |
if isinstance(from_ev, LazyLoader): | |
path = from_ev.path | |
if issubclass(from_ev.ev_class, get_evidence_class(type_str)): | |
ev_class = from_ev.ev_class |
and save an if.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in a96efa7
compliance/evidence.py
Outdated
path = from_ev.path | ||
if issubclass(from_ev.ev_class, get_evidence_class(type_str)): | ||
ev_class = from_ev.ev_class | ||
if not path.startswith(prefix): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if pathlib could be used here to avoid the if:
& the fstring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What
Why
How
Test
with_*_evidences
decorators andevidences
context manager is preservedtest_
function/method as the evidence specified as theev_class
otherwise the evidence is returned as either raw or external as appropriate.Context
N/A