I have to extend some very badly written Python code (no documentation, very interdependent, barely any encapsulation, very static, everything hard-coded, etc..) and therefore do I obviously have to use some of its black-box, bug-prone functions.

Now I don't want to refactor this repository, as I am simply missing the time, as this seems to be the common answer or approach to most of the similar questions I found on stackexchange. My supervisor would like me to work with the existing code.

So how would I best handle the interfacing to this badly written Python code?

Spontaneous ideas of mine, which I consider questionable though, would be

  • Using the Python equivalent of C assert(), though that seems hardly manageable with huge very complex objects...!?!
  • Unit Tests for my own written code, though this mainly tests my code and only indirectly the badly written code I am interfacing...!?!