PageRenderTime 47ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/test-filelog.py

https://bitbucket.org/mirror/mercurial/
Python | 55 lines | 47 code | 6 blank | 2 comment | 13 complexity | 0b436f6f2d0bc6ade41e970409a048c9 MD5 | raw file
Possible License(s): GPL-2.0
  1. #!/usr/bin/env python
  2. """
  3. Tests the behaviour of filelog w.r.t. data starting with '\1\n'
  4. """
  5. from mercurial import ui, hg
  6. from mercurial.node import nullid, hex
  7. myui = ui.ui()
  8. repo = hg.repository(myui, path='.', create=True)
  9. fl = repo.file('foobar')
  10. def addrev(text, renamed=False):
  11. if renamed:
  12. # data doesn't matter. Just make sure filelog.renamed() returns True
  13. meta = {'copyrev': hex(nullid), 'copy': 'bar'}
  14. else:
  15. meta = {}
  16. lock = t = None
  17. try:
  18. lock = repo.lock()
  19. t = repo.transaction('commit')
  20. node = fl.add(text, meta, t, 0, nullid, nullid)
  21. return node
  22. finally:
  23. if t:
  24. t.close()
  25. if lock:
  26. lock.release()
  27. def error(text):
  28. print 'ERROR: ' + text
  29. textwith = '\1\nfoo'
  30. without = 'foo'
  31. node = addrev(textwith)
  32. if not textwith == fl.read(node):
  33. error('filelog.read for data starting with \\1\\n')
  34. if fl.cmp(node, textwith) or not fl.cmp(node, without):
  35. error('filelog.cmp for data starting with \\1\\n')
  36. if fl.size(0) != len(textwith):
  37. error('FIXME: This is a known failure of filelog.size for data starting '
  38. 'with \\1\\n')
  39. node = addrev(textwith, renamed=True)
  40. if not textwith == fl.read(node):
  41. error('filelog.read for a renaming + data starting with \\1\\n')
  42. if fl.cmp(node, textwith) or not fl.cmp(node, without):
  43. error('filelog.cmp for a renaming + data starting with \\1\\n')
  44. if fl.size(1) != len(textwith):
  45. error('filelog.size for a renaming + data starting with \\1\\n')
  46. print 'OK.'