2 # -*- coding: utf-8 -*-
6 from nose.tools import *
11 def clear_directory(top):
12 for root, dirs, files in os.walk(top, topdown=False):
14 os.remove(os.path.join(root, name))
16 os.rmdir(os.path.join(root, name))
23 class TestMercurialStorage(object):
25 self.repo_path = tempfile.mkdtemp()
26 self.repo = vstorage.VersionedStorage(self.repo_path)
29 clear_directory(self.repo_path)
31 def test_save_text(self):
34 author = u"test author"
35 comment = u"test comment"
36 self.repo.save_text(title, text, author, comment, parent=-1)
37 saved = self.repo.open_page(title).read()
40 def test_save_text_noparent(self):
43 author = u"test author"
44 comment = u"test comment"
45 self.repo.save_text(title, text, author, comment, parent=None)
46 saved = self.repo.open_page(title).read()
49 def test_save_merge_no_conflict(self):
52 author = u"test author"
53 comment = u"test comment"
54 self.repo.save_text(title, text, author, comment, parent=-1)
55 self.repo.save_text(title, text, author, comment, parent=-1)
56 saved = self.repo.open_page(title).read()
59 def test_save_merge_line_conflict(self):
60 text = u"test\ntest\n"
61 text1 = u"test\ntext\n"
62 text2 = u"text\ntest\n"
64 author = u"test author"
65 comment = u"test comment"
66 self.repo.save_text(title, text, author, comment, parent=-1)
67 self.repo.save_text(title, text1, author, comment, parent=0)
68 self.repo.save_text(title, text2, author, comment, parent=0)
69 saved = self.repo.open_page(title).read()
70 # Other conflict markers placement can also be correct
71 assert_equal(saved, u'''\
80 def test_delete(self):
83 author = u"test author"
84 comment = u"test comment"
85 self.repo.save_text(title, text, author, comment, parent=-1)
86 assert title in self.repo
87 self.repo.delete_page(title, author, comment)
88 assert title not in self.repo
90 @raises(vstorage.DocumentNotFound)
91 def test_document_not_found(self):
92 self.repo.open_page(u'unknown entity')
94 def test_open_existing_repository(self):
95 self.repo.save_text(u'Python!', u'ham and spam')
96 current_repo_revision = self.repo.repo_revision()
97 same_repo = vstorage.VersionedStorage(self.repo_path)
98 assert same_repo.repo_revision() == current_repo_revision