Skip to content
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

ECS-6433 heuristic loading #231 #348

Merged

Conversation

janeliu-slac
Copy link
Contributor

@janeliu-slac janeliu-slac commented Oct 10, 2024

Description

  • Updated happi's load function to support searching and loading in one user-friendly expression. The load function gathers the results of each search term individually and loads the union of the results.
  • Cleaned up code by removing stray print statements.
  • Added unit tests for load function.
  • In load function of cli.py removed term=[] and replaced with [item] for readability.

Motivation and Context

It allows users to search and load device objects using one CLI expression.

#231

How Has This Been Tested?

Manual testing and unit tests.

Where Has This Been Documented?

Documentation is in the code and release notes.

Pre-merge checklist

  • Code works interactively
  • Code contains descriptive docstrings, including context and API
  • New/changed functions and methods are covered in the test suite where possible
  • Test suite passes locally
  • Test suite passes on GitHub Actions
  • Ran docs/pre-release-notes.sh and created a pre-release documentation page
  • Pre-release docs include context, functional descriptions, and contributors as appropriate

happi/cli.py Outdated Show resolved Hide resolved
happi/cli.py Outdated Show resolved Hide resolved
happi/cli.py Outdated Show resolved Hide resolved
@tangkong
Copy link
Contributor

As an aside, I think it's worthwhile developing the tests as you write the code. I'm often guilty of writing code then making tests after, but practicing proper test-driven development can often help speed up your development.

In this case, if you set up tests that ran the happi load CLI with various argument combinations, you'd have uncovered some of the bugs I mentioned above

happi/cli.py Outdated Show resolved Hide resolved
happi/cli.py Outdated Show resolved Hide resolved
@janeliu-slac
Copy link
Contributor Author

janeliu-slac commented Oct 16, 2024

I updated the test_load_glob_args function so for res in results will print out the name of each of the mock devices, but got stuck trying to get those names into runner.invoke(happi_cli, ['--path', happi_cfg, 'load', name1, name2]). Is there a way to add these names without hardcoding it into runner.invoke? Currently, client.search_regex(name='tst_base_.*') generates 2 results, but there may be more if someone adds more mock devices in the future.

def test_load_glob_args(
    caplog: pytest.LogCaptureFixture,
    client: happi.client.Client,
    happi_cfg: str,
    runner: CliRunner
):
    # get search results
    results = client.search_regex(name='tst_base_.*')

    for res in results:
        name = res.item['name']  # the results are 'tst_base_pim' and 'tst_base_pim2'
        print(name)

    # try to load the item
    with mock.patch.object(IPython, 'start_ipython') as m:
        _ = runner.invoke(
            happi_cli, ['--path', happi_cfg, 'load', 'tst_base_pim', 'tst_base_pim2']
        )
        m.assert_called_once_with(argv=['--quick'], user_ns=devices)        
    with caplog.at_level(logging.INFO):
        assert "Creating shell with devices" in caplog.text

@ZLLentz
Copy link
Member

ZLLentz commented Oct 16, 2024

Hi Jane, if you want to discuss your code you should push it so we can make in-line comments.
The test you show here calls runner.invoke without using the glob so I'm confused

@janeliu-slac
Copy link
Contributor Author

janeliu-slac commented Oct 16, 2024

It seems like client.load_device() isn't able to accept globs so I used client.search_regex(name='tst_base_.*'), which returns multiple SearchResult objects. I was able to get name from SearchResult objects but wasn't sure how to pass them into runner.invoke(). I rewrote the code and just commited it (it's definitely not passing pytest).

happi/tests/test_cli.py Outdated Show resolved Hide resolved
happi/tests/test_cli.py Outdated Show resolved Hide resolved
ZLLentz
ZLLentz previously approved these changes Oct 18, 2024
Copy link
Member

@ZLLentz ZLLentz left a comment

Choose a reason for hiding this comment

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

I think I'm happy with this, I'll leave my approval prior to my vacay

@janeliu-slac janeliu-slac dismissed ZLLentz’s stale review October 18, 2024 23:14

The merge-base changed after approval.

@tangkong
Copy link
Contributor

I swear these are my last nitpicks, then I think we're good to go

@janeliu-slac
Copy link
Contributor Author

Lol it's fine. I'm learning a lot and taking notes for future projects.

tangkong
tangkong previously approved these changes Oct 21, 2024
Copy link
Contributor

@tangkong tangkong left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@janeliu-slac janeliu-slac dismissed tangkong’s stale review October 21, 2024 21:49

The merge-base changed after approval.

tangkong
tangkong previously approved these changes Oct 21, 2024
@janeliu-slac janeliu-slac dismissed tangkong’s stale review October 21, 2024 22:21

The merge-base changed after approval.

@tangkong tangkong closed this Oct 21, 2024
@tangkong tangkong reopened this Oct 21, 2024
@janeliu-slac janeliu-slac merged commit e29373c into pcdshub:master Oct 21, 2024
22 checks passed
@janeliu-slac janeliu-slac deleted the ECS-6433_heuristic_loading_#231 branch October 21, 2024 22:28
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.

3 participants