MNT: add handling of mpod questionnaire#215
MNT: add handling of mpod questionnaire#215cristinasewell wants to merge 2 commits intopcdshub:masterfrom
Conversation
happi/tests/test_backends.py
Outdated
| assert led.__class__.__name__ == 'MPODChannelLV' | ||
|
|
||
| # if voltage > 50 => HV Channel | ||
| # with patch('pcdsdevices.mpod.MPODChannel.get_max_voltage', |
There was a problem hiding this comment.
Anybody knows how to 'cleanup' or 'close' in a way a mock when using with patch?
It seems like the first patch is leaking over to the second one, even if I make a new test function.
I can avoid using with and use the monkeypatch or the mocker.patch.object instead and I think it would work fine, but I did not want to have to import pcdsdevices module in this file 😀
Or I can just leave only one test with either Low Voltage or High Voltage
There was a problem hiding this comment.
I like to use a pattern similar to:
@pytest.mark.fixture(scope='function')
def my_modified_obj(monkeypatch):
obj = ...
monkeypatch.setattr(obj, 'attr', 'value')
yield obj
# any cleanup if necessary, the `yield` above makes this fixture a context manager effectively
def test_mytest(my_modified_obj):
assert my_modified_obj.attr == 'value'It keeps the monkeypatch scoped to a specific test and is pretty explicit about it.
That said, the with block you use should have reset the original attribute value - not sure why it didn't, or if maybe something else is going on there.
There was a problem hiding this comment.
Thank you Ken, yeah I think something else is going on, only if I test them separately it works though.
I am not calling this function that I need to mock (get_max_voltage) anywhere directly here - I probably have to mock something else instead to be able to test both option.
I think it is related to mockqsbackend having a module scope.... so it just mocks my function once per module with the first mock I define - maybe not....
There was a problem hiding this comment.
Coming back to this guy, I tested it with some dummy PVs and no mocking get_max_voltage and it seems like it is working, which is good:
'led': MPODChannelLV(csewell:mpod:l:CH:001, name=led), 'blower': MPODChannelHV(csewell:mpod:h:CH:001, name=blower)}
MPODChannelLV(csewell:mpod:l:CH:001, name=led)
MPODChannelHV(csewell:mpod:h:CH:001, name=blower)
caget csewell:mpod:h:CH:001:GetMaxVoltage
csewell:mpod:h:CH:001:GetMaxVoltage 51
caget csewell:mpod:l:CH:001:GetMaxVoltage
csewell:mpod:l:CH:001:GetMaxVoltage 49
Later I realized that I had to use use_cash=False in order for it to work fine for testing:
d = load_devices(*c.all_devices, pprint=False, use_cache=False).__dict__
I was getting here:
https://github.com/cristinasewell/happi/blob/d5c24dc8c4416d852f98d4e1c0b3dc62d9a4c6a5/happi/loader.py#L122
if I did not set use_cash=False , and the second mpod was created the same as the first one (E.g.: if the first one was HV the second one was HV too ...
I am not sure if I understand why was this happening exactly ... it is probably a combination of how the mockqsbackend is setup and the fact that I am looking at the voltage to create the mpod channel ....
Description
Add support to create mpod channels from the questionnaire entries.
Motivation and Context
This change goes with the additions from this PR: pcdshub/pcdsdevices#690 . This PR was recently merged, and I don't know if this one should get merged too or not yet, but I wanted to open it so I don't forget about it.
How Has This Been Tested?
Only locally.
Where Has This Been Documented?
N/A