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!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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)