1 # -*- encoding: utf-8 -*-
3 __author__= "Łukasz Rekucki"
4 __date__ = "$2009-09-18 14:43:27$"
5 __doc__ = "Tests for RAL mercurial backend."
7 from nose.tools import *
10 from wlrepo import MercurialLibrary
11 from wlrepo.backend_mercurial import *
13 import os, os.path, tempfile
16 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data/repos')
19 class testBasicLibrary(object):
22 self.path = tempfile.mkdtemp("", "testdir_" )
24 for subdir in os.listdir(REPO_TEMPLATES):
25 shutil.copytree(REPO_TEMPLATES + '/' + subdir, self.path + '/' + subdir, False)
28 if self.path is not None:
29 shutil.rmtree(self.path, True)
32 def test_opening(self):
33 library = MercurialLibrary(self.path + '/cleanrepo')
35 def test_main_cabinett(self):
36 library = MercurialLibrary(self.path + '/cleanrepo')
38 mcab = library.main_cabinet
39 assert_equal(mcab.maindoc_name, '')
41 # @type mcab MercurialCabinet
42 doclist = mcab.documents()
43 assert_equal( list(doclist), ['valid_file'])
46 def test_read_document(self):
47 library = MercurialLibrary(self.path + '/testrepoI')
48 doc = library.main_cabinet.retrieve('valid_file')
50 assert_equal(doc.read().strip(), 'Ala ma kota')
52 def test_read_UTF8_document(self):
53 library = MercurialLibrary(self.path + '/testrepoI')
54 doc = library.main_cabinet.retrieve('polish_file')
56 assert_equal(doc.read().strip(), u'Gąska!'.encode('utf-8'))
58 def test_write_document(self):
59 library = MercurialLibrary(self.path + '/testrepoI')
60 doc = library.main_cabinet.retrieve('valid_file')
62 assert_equal(doc.read().strip(), 'Ala ma kota')
64 STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
67 assert_equal(doc.read(), STRING)
69 def test_create_document(self):
70 repopath = os.path.join(self.path, 'testrepoI')
72 library = MercurialLibrary(repopath)
73 doc = library.main_cabinet.create("another_file", "Some text")
74 assert_equal( doc.read(), "Some text")
75 assert_true( os.path.isfile( os.path.join(repopath, "pub_another_file.xml")) )
77 def test_switch_branch(self):
78 library = MercurialLibrary(self.path + '/testrepoII')
80 tester_cab = library.cabinet("valid_file", "tester", create=False)
81 assert_equal( list(tester_cab.documents()), ['valid_file'])
83 @raises(wlrepo.CabinetNotFound)
84 def test_branch_not_found(self):
85 library = MercurialLibrary(self.path + '/testrepoII')
86 tester_cab = library.cabinet("ugh", "tester", create=False)
88 def test_no_branches(self):
89 library = MercurialLibrary(self.path + '/testrepoII')
96 assert_true( n3.parentof(n4) )
97 assert_false( n4.parentof(n3) )
98 assert_true( n0.parentof(n1) )
99 assert_false( n1.parentof(n0) )
100 assert_false( n0.parentof(n4) )
102 # def test_ancestor_of_simple(self):
103 assert_true( n3.ancestorof(n4) )
104 assert_true( n2.ancestorof(n4) )
105 assert_true( n1.ancestorof(n4) )
106 assert_true( n0.ancestorof(n4) )
108 assert_true( n2.ancestorof(n3) )
109 assert_true( n1.ancestorof(n3) )
110 assert_true( n0.ancestorof(n3) )
112 assert_false( n4.ancestorof(n4) )
113 assert_false( n4.ancestorof(n3) )
114 assert_false( n3.ancestorof(n2) )
115 assert_false( n3.ancestorof(n1) )
116 assert_false( n3.ancestorof(n0) )
118 # def test_common_ancestor_simple(self):
119 assert_true( n3.has_common_ancestor(n4) )
120 assert_true( n3.has_common_ancestor(n3) )
121 assert_true( n3.has_common_ancestor(n3) )
124 def test_once_branched(self):
125 library = MercurialLibrary(self.path + '/test3')
127 n7 = library.shelf(7)
128 n6 = library.shelf(6)
129 n5 = library.shelf(5)
130 n4 = library.shelf(4)
131 n3 = library.shelf(3)
132 n2 = library.shelf(2)
134 assert_true( n2.parentof(n3) )
135 assert_false( n3.parentof(n2) )
137 assert_true( n2.parentof(n5) )
138 assert_false( n5.parentof(n2) )
140 assert_false( n2.parentof(n4) )
141 assert_false( n2.parentof(n6) )
142 assert_false( n3.parentof(n5) )
143 assert_false( n5.parentof(n3) )
145 # def test_ancestorof_branched(self):
146 assert_true( n2.ancestorof(n7) )
147 assert_false( n7.ancestorof(n2) )
148 assert_true( n2.ancestorof(n6) )
149 assert_false( n6.ancestorof(n2) )
150 assert_true( n2.ancestorof(n5) )
151 assert_false( n5.ancestorof(n2) )
153 assert_false( n3.ancestorof(n5) )
154 assert_false( n5.ancestorof(n3) )
155 assert_false( n4.ancestorof(n5) )
156 assert_false( n5.ancestorof(n4) )
157 assert_false( n3.ancestorof(n7) )
158 assert_false( n7.ancestorof(n3) )
159 assert_false( n4.ancestorof(n6) )
160 assert_false( n6.ancestorof(n4) )
162 # def test_common_ancestor_branched(self):
163 assert_true( n2.has_common_ancestor(n4) )
164 assert_true( n2.has_common_ancestor(n7) )
165 assert_true( n2.has_common_ancestor(n6) )
167 # cause it's not in the right branch
168 assert_false( n5.has_common_ancestor(n3) )
169 assert_false( n7.has_common_ancestor(n4) )
171 def test_after_merge(self):
172 library = MercurialLibrary(self.path + '/test4')
173 n8 = library.shelf(8)
174 n7 = library.shelf(7)
175 n6 = library.shelf(6)
177 assert_true( n7.parentof(n8) )
178 assert_false( n8.parentof(n7) )
180 assert_true( n7.ancestorof(n8) )
181 assert_true( n6.ancestorof(n8) )
184 assert_true( n7.has_common_ancestor(n8) )
185 # cause it's not in the right branch
186 assert_false( n8.has_common_ancestor(n7) )
189 def test_after_merge_and_local_commit(self):
190 library = MercurialLibrary(self.path + '/test5b')
191 n9 = library.shelf(9)
192 n8 = library.shelf(8)
193 n7 = library.shelf(7)
194 n6 = library.shelf(6)
196 assert_true( n7.parentof(n8) )
197 assert_false( n8.parentof(n7) )
199 assert_true( n9.has_common_ancestor(n8) )
200 # cause it's not in the right branch
201 assert_false( n8.has_common_ancestor(n9) )
204 def test_merge_personal_to_default(self):
205 library = MercurialLibrary(self.path + '/test3')
207 main = library.shelf(2)
208 local = library.shelf(7)
210 document = library.document("ala", "admin")
211 shared = document.shared()
212 print document, shared
214 document.share("Here is my copy!")
216 assert_equal( document.shelf(), local) # local didn't change
219 new_main = shared.shelf()
220 assert_not_equal( new_main, main) # main has new revision
223 assert_true( main.parentof(new_main) )
224 assert_true( local.parentof(new_main) )
228 def testCreateBranch(self):
229 repopath = os.path.join(self.path, 'testrepoII')
230 library = MercurialLibrary(repopath)
232 tester_cab = library.cabinet("anotherone", "tester", create=True)
233 assert_equal( list(tester_cab.documents()), ['anotherone'])