Skip to content

Comments

Replace mock_open with temporary file#63

Merged
mikss merged 2 commits intoio_format_storage_viewfrom
fix-breakpoint
Jul 21, 2021
Merged

Replace mock_open with temporary file#63
mikss merged 2 commits intoio_format_storage_viewfrom
fix-breakpoint

Conversation

@JacobHayes
Copy link
Member

@JacobHayes JacobHayes commented Jul 20, 2021

When debugging a few pydantic issues in #62, adding a breakpoint before https://github.com/replicahq/artigraph/blob/556c7505fa573b81889632b50644c546fbf0c49d/src/arti/views/core.py#L28 while within https://github.com/replicahq/artigraph/blob/556c7505fa573b81889632b50644c546fbf0c49d/tests/arti/views/test_views.py#L24 would fail with a cryptic error. Traced it down to a file (stdin?) opened by pdb returning the pickled binary data, rather than the text it expected.

I tried to swap mock_open with NamedTemporaryFile, but that doesn't support re-opening the file on Windows. Instead, I added a named_temporary_file helper that uses NamedTemporaryDirectory under the hood instead for better portability.

@JacobHayes JacobHayes self-assigned this Jul 20, 2021
@JacobHayes JacobHayes requested a review from mikss July 20, 2021 21:30
Copy link
Contributor

@mikss mikss left a comment

Choose a reason for hiding this comment

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

I don't fully grasp the rules of thumb for when to use mock_open versus temporary files (or, whether mock_open is ever preferable), but this looks good to me.

@mikss mikss merged commit e43f470 into io_format_storage_view Jul 21, 2021
@mikss mikss deleted the fix-breakpoint branch July 21, 2021 13:38
@JacobHayes
Copy link
Member Author

I'm not a bit fan of patching/mocking generally (too easily coupled to drifting implementations), so I tend to use temp files more often (though mock_open certainly was shorter in this case).

JacobHayes added a commit that referenced this pull request Jul 21, 2021
* Add NamedTemporaryFile alternative that can be re-opened on Windows

* Use NamedTemporaryFile rather than mock_open (to fix breakpoint)
mikss added a commit that referenced this pull request Jul 21, 2021
* python view initial pass

* tests for views

* type fiddling

* remove validate method

* change multimethod to multidispatch

* Replace mock_open with temporary file (#63)

* Add NamedTemporaryFile alternative that can be re-opened on Windows

* Use NamedTemporaryFile rather than mock_open (to fix breakpoint)

* re-order format/storage/view, and move tests

* Remove LocalFile.path default

* Check before writing empty data

Co-authored-by: Jacob Hayes <[email protected]>
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.

2 participants