From c3b755d379bb5b21331de9f0b0b866dc5e3edead Mon Sep 17 00:00:00 2001 From: tangkong Date: Wed, 8 Jun 2022 13:51:52 -0700 Subject: [PATCH 1/3] BUG: ints match float counterparts in search --- happi/cli.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) From 1c31ad8e20723b5f57f7647a0b7051caf6be1809 Mon Sep 17 00:00:00 2001 From: tangkong Date: Wed, 8 Jun 2022 13:52:28 -0700 Subject: [PATCH 2/3] TST: test_search_int_float --- happi/tests/test_cli.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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') From b1c487634a3c9f0c48373d3fb11d5eaa85da85e7 Mon Sep 17 00:00:00 2001 From: tangkong Date: Wed, 8 Jun 2022 14:24:39 -0700 Subject: [PATCH 3/3] DOC: pre-release notes --- .../261-search_nums.rst | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/source/upcoming_release_notes/261-search_nums.rst 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