test_snapshot.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. from borgmatic.borg.pattern import Pattern
  2. from borgmatic.hooks.data_source import snapshot as module
  3. def test_get_contained_patterns_without_candidates_returns_empty():
  4. assert module.get_contained_patterns('/mnt', {}) == ()
  5. def test_get_contained_patterns_with_self_candidate_returns_self():
  6. candidates = {Pattern('/foo'), Pattern('/mnt'), Pattern('/bar')}
  7. assert module.get_contained_patterns('/mnt', candidates) == (Pattern('/mnt'),)
  8. assert candidates == {Pattern('/foo'), Pattern('/bar')}
  9. def test_get_contained_patterns_with_self_candidate_and_caret_prefix_returns_self():
  10. candidates = {Pattern('^/foo'), Pattern('^/mnt'), Pattern('^/bar')}
  11. assert module.get_contained_patterns('/mnt', candidates) == (Pattern('^/mnt'),)
  12. assert candidates == {Pattern('^/foo'), Pattern('^/bar')}
  13. def test_get_contained_patterns_with_child_candidate_returns_child():
  14. candidates = {Pattern('/foo'), Pattern('/mnt/subdir'), Pattern('/bar')}
  15. assert module.get_contained_patterns('/mnt', candidates) == (Pattern('/mnt/subdir'),)
  16. assert candidates == {Pattern('/foo'), Pattern('/bar')}
  17. def test_get_contained_patterns_with_grandchild_candidate_returns_child():
  18. candidates = {Pattern('/foo'), Pattern('/mnt/sub/dir'), Pattern('/bar')}
  19. assert module.get_contained_patterns('/mnt', candidates) == (Pattern('/mnt/sub/dir'),)
  20. assert candidates == {Pattern('/foo'), Pattern('/bar')}