otsaloma / gaupol

Editor for text-based subtitle files
https://otsaloma.io/gaupol/
GNU General Public License v3.0
247 stars 35 forks source link

Fix ResourceWarning in tests (and more) #225

Closed sbraz closed 3 weeks ago

sbraz commented 3 weeks ago

Hi @otsaloma, I noticed tests showed a lot of warnings so I attempted to fix those related to filehandles. Please let me know if I made any mistake, especially when I touched files that are not only used for tests.

otsaloma commented 3 weeks ago

Thanks! I think this is quite straight-forward, but can you post the command you're using to run the tests and what exact warning do you get related to these?

sbraz commented 3 weeks ago

You can try something like pytest -Wdefault aeidon/test/test_encodings.py and you will see the warnings with the master branch.

otsaloma commented 3 weeks ago

Oh, right. I've been using

export PYTEST_ADDOPTS="-p no:cacheprovider -p no:hypothesispytest -p no:warnings"

in my ~/.profile, probably because of excessive warnings from GTK.

It's this:

aeidon/test/test_encodings.py::TestModule::test_detect_bom__utf_8_sig
  /home/osmo/Source/gaupol/aeidon/test/test_encodings.py:199: ResourceWarning: unclosed file <_io.BufferedWriter name='/tmp/gaupol-lll8hiun.srt'>
    open(path, "wb").write(codecs.BOM_UTF8 + blob)

This might have been around for quite a while. I remember I left those open intentionally to squeeze three lines (open, write, close) into one. That was before with was added to the language. This is fine to fix now.