Skip to content

Comments

Add function to instrument to validate all gettable parameters#347

Closed
peendebak wants to merge 3 commits intomasterfrom
feat/validate_status
Closed

Add function to instrument to validate all gettable parameters#347
peendebak wants to merge 3 commits intomasterfrom
feat/validate_status

Conversation

@peendebak
Copy link
Contributor

This is useful when connecting to an instrument for the first time to check that all values are in the required range.

@giulioungaretti @alexcjohnson

Copy link
Contributor

@AdriaanRol AdriaanRol left a comment

Choose a reason for hiding this comment

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

@peendebak I like this addition 👍 , I have some small questions regarding the tests but other than that I think it should be ok to merge (leaving the final decision to @giulioungaretti of course)

instrument.dac1._save_val(1000) # overrule the validator
try:
instrument.validate_status()
except:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a blind except, I would always use except Exception: to prevent keyboard interrupts and the like to be caught here.

# TODO (giulioungaretti) remove ( does nothing ?)
pass

def validate_function(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

If you start the function name with test_validate_function unittest will run this function. I'm not sure, did you test that this runs (I did not so I may be wrong)

instrument.validate_status()
except:
pass
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

unittest contains a with self.assertRaises(Exception): construction where you can test for a specific exception without the need for the try except else construction.

@peendebak peendebak force-pushed the feat/validate_status branch from f5dc71b to 3b0a34f Compare October 21, 2016 11:32
@peendebak
Copy link
Contributor Author

@AdriaanRol Thanks for the suggestions.
@giulioungaretti Can you review?

@peendebak
Copy link
Contributor Author

@AdriaanRol @giulioungaretti For the review of Adriaan I have two options: see review or dismiss review. I would have expected an option like `handled review'. Should I dismiss the review if I feel the issues have been addressed?

cls.source = MockSource(model=cls.model, server_name='')
cls.meter = MockMeter(model=cls.model, keep_history=False, server_name='')
cls.meter = MockMeter(
model=cls.model, keep_history=False, server_name='')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this acutally good PEP8 ? model should be aligned with the ( , no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My autopep8 formatter says its fine

Copy link
Contributor

Choose a reason for hiding this comment

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

cool

'only be used in Loops with background=False.')

def validate_status(self, verbose=0):
""" Validate the values of all gettable parameters """
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer verbose to be a real bool, than the 0 (which suggests a level of verbosity rather than a switch. ).

And what happens if the parameter is gettable, but not settable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The verbose parameter is an int on purpose. In general I use the convetion: 0: no output, 1: normal output, >=2: used for debugging, output not stable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the parameter is gettable but not settable, then nothing happens. The assumption here is that if there is no .set, then there is probably no meaningfull .validate.
If we want we can remove the check on has_set, since every parameter has a .validate function.

Copy link
Contributor

Choose a reason for hiding this comment

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

a) Cool, just write the assumption in the docstring !

b) In this function 2 and 1 are the same then, which I don't like, and I don't see it documented or understandable from the code.
Change to true and false in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peendebak peendebak mentioned this pull request Oct 27, 2016
@giulioungaretti giulioungaretti deleted the feat/validate_status branch October 31, 2016 14:23
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.

4 participants