IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

29 lines
896B

  1. from focker.jail import backup_file
  2. import tempfile
  3. import os
  4. def test_backup_file():
  5. with tempfile.TemporaryDirectory() as d:
  6. fname = os.path.join(d, 'dummy.conf')
  7. with open(fname, 'w') as f:
  8. f.write('init')
  9. nbackups = 10
  10. for i in range(15):
  11. backup_file(fname, nbackups=nbackups, chmod=0o640)
  12. with open(fname, 'w') as f:
  13. f.write(str(i))
  14. fname = os.path.join(d, 'dummy.conf')
  15. with open(fname, 'r') as f:
  16. assert f.read() == '14'
  17. for i in range(nbackups):
  18. fname = os.path.join(d, 'dummy.conf.%d' % i)
  19. assert os.path.exists(fname)
  20. with open(fname, 'r') as f:
  21. if i < 5:
  22. assert f.read() == str(i + 9)
  23. else:
  24. assert f.read() == str(i - 1)