I was busy getting vaccinated today, and then trying to take it easy. So, I haven't touched code, but there is something I'm trying to work out.
I have a helper function that wraps errors, both expected and unexpected, from the open function in custom exceptions specific to the application. I want to be sure to test the branches for "I don't know how this happened, but I should account for it". But I can't test those by making the open function do stuff, because if I knew how to encounter those errors, then I'd need to write more specific error messages, and then inducing those errors wouldn't trigger the branches I want to test.
So, if I can't rely on the built-in function to trigger the branches I want to test, then I need to be able to substitute in a different function. I've thought of a few possible ways:
- Parameterize over the function to use. This would require me to figure out a "good-enough" signature for open, and I kind of don't want to bother.
- Put the exception handling in a context manager. This completely decouples the business logic from the diagnostic messages, and for all that "decoupling" and "weakly coupled" are popular buzzwords, I don't think that makes sense.
- Mock the open function. I'm leaning towards this, because it lets me defer refactorings, and I don't really have a refactoring that I want to do here.
I basically came to that conclusion while I was writing this post in my head, but I figured that was no reason not to write the post on my computer as well.
Anyway, once I take care of this idea, I should be on-track to properly integrate the prototype code and see how it treats me. Hopefully, I'll have that done in a week or two.