-
Notifications
You must be signed in to change notification settings - Fork 29
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
BUG: allow happi search
to match int numerics
#261
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
261 search_nums | ||
################# | ||
|
||
API Changes | ||
----------- | ||
- N/A | ||
|
||
Features | ||
-------- | ||
- N/A | ||
|
||
Bugfixes | ||
-------- | ||
- Allow int search values to match their float counterparts | ||
|
||
Maintenance | ||
----------- | ||
- N/A | ||
|
||
Contributors | ||
------------ | ||
- tangkong |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,8 +132,16 @@ def search( | |
continue | ||
|
||
elif is_number(value): | ||
logger.debug('Changed %s to float', value) | ||
# value = str(float(value)) | ||
if float(value) == int(float(value)): | ||
# value is an int, allow the float version (optional .0) | ||
logger.debug(f'looking for int value: {value}') | ||
value = f'^{int(float(value))}(\\.0+$)?$' | ||
|
||
# don't translate from glob | ||
client_args[criteria] = value | ||
continue | ||
else: | ||
value = str(float(value)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't a floating point value be somewhat problematic for regex mode? The above comment and continue gave me pause to think about it a bit:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are good points.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If someone is doing a regex search with a thing that looks like a floating point value... is it a floating point value or a regex? ... I think it's a regex and probably shouldn't go through the
Likely not - just trying to dig into the implications of the changes in my usual excessive way 😁 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is an annoyance with using regex in general to search for floating point numbers rather than a unique problem to happi Float-based values not partial matching almost seems like a feature rather than a bug... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point about the processing of regex, Ken There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think it's excessive, it's just thorough 😄
I wish I could claim credit for that haha |
||
else: | ||
logger.debug('Value %s interpreted as string', value) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -219,6 +219,29 @@ def test_search_z_range( | |
assert 'No devices found' in conflict_result.output | ||
|
||
|
||
def test_search_int_float(runner: CliRunner, happi_cfg: str): | ||
int_result = runner.invoke(happi_cli, ['--path', happi_cfg, | ||
'search', '--names', 'z=3']) | ||
float_result = runner.invoke(happi_cli, ['--path', happi_cfg, | ||
'search', '--names', 'z=3.0']) | ||
assert int_result.output == float_result.output | ||
|
||
# # TODO: add this test case once edit works on extraneous info | ||
# edit_result = runner.invoke( | ||
# happi_cli, | ||
# ['-v', '--path', happi_cfg, 'edit', 'tst_base_pim', 'z=3.001'], | ||
# input='y' | ||
# ) | ||
# assert edit_result.exit_code == 0 | ||
|
||
# int_result = runner.invoke(happi_cli, ['--path', happi_cfg, | ||
# 'search', '--names', 'z=3']) | ||
# float_result = runner.invoke(happi_cli, ['--path', happi_cfg, | ||
# 'search', '--names', 'z=3.0']) | ||
# assert int_result.output == '' | ||
# assert float_result.output == '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 for leaving a test for future use |
||
|
||
|
||
def test_both_range_and_regex_search(client: happi.client.Client): | ||
# we're only interested in getting this entry (TST_BASE_PIM2) | ||
res = client.search_regex(z='6.0') | ||
|
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 is good as you have it:
^...$
.0
.