diff --git a/docs/source/upcoming_release_notes/261-search_nums.rst b/docs/source/upcoming_release_notes/261-search_nums.rst new file mode 100644 index 00000000..79dde176 --- /dev/null +++ b/docs/source/upcoming_release_notes/261-search_nums.rst @@ -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 diff --git a/happi/cli.py b/happi/cli.py index 03749b05..5997b421 100644 --- a/happi/cli.py +++ b/happi/cli.py @@ -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)) else: logger.debug('Value %s interpreted as string', value) diff --git a/happi/tests/test_cli.py b/happi/tests/test_cli.py index 5d6993ed..5c3b1346 100644 --- a/happi/tests/test_cli.py +++ b/happi/tests/test_cli.py @@ -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 == '' + + 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')