test_unused.py 967 B

1234567891011121314151617181920212223242526272829303132
  1. import pytest
  2. from .unused import UnusedCleaner
  3. from .config import get_conf
  4. @pytest.fixture
  5. def unusedcleaner():
  6. return UnusedCleaner(get_conf(prefix="LARIGIRATEST_"))
  7. # this test suite heavily assumes that TMPDIR == /tmp/, which is the default
  8. # indeed. However, the code does not rely on this assumption.
  9. def test_watch_file(unusedcleaner):
  10. # despite not existing, the file is added
  11. unusedcleaner.watch("file:///tmp/gnam")
  12. assert len(unusedcleaner.waiting_removal_files) == 1
  13. assert list(unusedcleaner.waiting_removal_files)[0] == "/tmp/gnam"
  14. def test_watch_path_error(unusedcleaner):
  15. """paths are not valid thing to watch. URIs only, thanks"""
  16. unusedcleaner.watch("/tmp/foo")
  17. assert len(unusedcleaner.waiting_removal_files) == 0
  18. def test_watch_notmp_error(unusedcleaner):
  19. """Files not in TMPDIR are not added"""
  20. unusedcleaner.watch("file:///not/in/tmp")
  21. assert len(unusedcleaner.waiting_removal_files) == 0