Skip to content

MNT: add handling of mpod questionnaire#215

Open
cristinasewell wants to merge 2 commits intopcdshub:masterfrom
cristinasewell:mpod_questionnaire
Open

MNT: add handling of mpod questionnaire#215
cristinasewell wants to merge 2 commits intopcdshub:masterfrom
cristinasewell:mpod_questionnaire

Conversation

@cristinasewell
Copy link
Contributor

@cristinasewell cristinasewell commented Feb 26, 2021

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

assert led.__class__.__name__ == 'MPODChannelLV'

# if voltage > 50 => HV Channel
# with patch('pcdsdevices.mpod.MPODChannel.get_max_voltage',
Copy link
Contributor Author

@cristinasewell cristinasewell Feb 26, 2021

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

@cristinasewell cristinasewell Mar 1, 2021

Choose a reason for hiding this comment

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

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....

Copy link
Contributor Author

@cristinasewell cristinasewell Mar 26, 2021

Choose a reason for hiding this comment

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

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 ....

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