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

Remove temporary file in JSON backend store function #330

Merged
merged 10 commits into from
Sep 18, 2023

Conversation

laura-king
Copy link
Contributor

@laura-king laura-king commented Sep 1, 2023

Description

Motivation and Context

Closes #304

If an error causes the temporary file in the json backend to not get copied properly, it would previously remain in the directory. It has not been needed so it will now be removed if left behind.

In addition, because this file is no longer needed, the datetime and username are no longer needed in the file name. It is now just the unique hash to prevent collisions. Imports previously used to add time and username are now removed from the file.

How Has This Been Tested?

Interactively, and a new test in test-backends.py

Where Has This Been Documented?

Issues #303, #304

Comments within function itself and test.

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

Copy link
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

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

Minor tweak, otherwise LGTM 👍

happi/backends/json_db.py Show resolved Hide resolved
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.

seems good to me, pending Ken's suggestion

@laura-king laura-king marked this pull request as draft September 7, 2023 17:09
@laura-king laura-king marked this pull request as ready for review September 7, 2023 21:53
Copy link
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

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

Looking good! One minor thing and then I think it's ready to go


# Ensure file is created, then throw error
def shutil_move_patch(*args, **kwargs):
assert os.path.isfile(os.path.join(os.getcwd(), temp_path))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be a bit careful here - this assertion might raise, and it'd be caught by with pytest.raises(BaseException) below. Assertions are AssertionError(Exception) which inherits from BaseException (standard library has a nice ASCII tree of this here)

The short of it is: I think you should switch the below clause on line 220 to be with pytest.raises(RuntimeError) to make sure we're catching line 215 and not line 214

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, and I'll update the raise.

I will look more into how assert works in pytest-for some reason I thought the test would just count as a fail and move on. Not sure why I thought of it as isolated

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 this is good to merge

Copy link
Contributor

@klauer klauer left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@tangkong tangkong merged commit d7594fe into pcdshub:master Sep 18, 2023
9 checks passed
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.

Clean up temporary file from #303
4 participants