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
17 REPO_TEMPLATES = os.path.join( os.path.dirname(__file__), 'data')
21 from functools import wraps
24 def decorated(*args, **kwargs):
27 temp = tempfile.mkdtemp("", "testdir_" )
28 path = os.path.join(temp, 'repo')
29 shutil.copytree(os.path.join(REPO_TEMPLATES, name), path, False)
30 kwargs['library'] = MercurialLibrary(path)
34 #if not clean and self.response:
35 # print "RESULT", func.__name__, ">>>"
38 shutil.rmtree(temp, True)
40 decorated = make_decorator(func)(decorated)
46 def test_opening(library):
50 def test_main_cabinet(library):
51 mcab = library.main_cabinet
52 assert_equal(mcab.maindoc_name, '')
54 doclist = mcab.parts()
55 assert_equal( list(doclist), ['valid_file'])
58 def test_read_document(library):
59 doc = library.main_cabinet.retrieve('valid_file')
60 assert_equal(doc.read().strip(), 'Ala ma kota')
63 def test_read_UTF8_document(library):
64 doc = library.main_cabinet.retrieve('polish_file')
65 assert_equal(doc.read().strip(), u'Gąska!'.encode('utf-8'))
68 def test_write_document(library):
69 doc = library.main_cabinet.retrieve('valid_file')
70 assert_equal(doc.read().strip(), 'Ala ma kota')
71 STRING = u'Gąski lubią pływać!\n'.encode('utf-8')
73 assert_equal(doc.read(), STRING)
76 def test_create_document(library):
77 doc = library.main_cabinet.create("another_file", "Some text")
78 assert_equal( doc.read(), "Some text")
79 assert_true( os.path.isfile( os.path.join(library.ospath, "pub_another_file.xml")) )
82 def test_switch_branch(library):
83 tester_cab = library.cabinet("valid_file", "tester", create=False)
84 assert_equal( list(tester_cab.parts()), ['valid_file'])
86 @raises(wlrepo.CabinetNotFound)
88 def test_branch_not_found(library):
89 tester_cab = library.cabinet("ugh", "tester", create=False)
92 def test_no_branches(library):
99 assert_true( n3.parentof(n4) )
100 assert_false( n4.parentof(n3) )
101 assert_true( n0.parentof(n1) )
102 assert_false( n1.parentof(n0) )
103 assert_false( n0.parentof(n4) )
105 # def test_ancestor_of_simple(self):
106 assert_true( n3.ancestorof(n4) )
107 assert_true( n2.ancestorof(n4) )
108 assert_true( n1.ancestorof(n4) )
109 assert_true( n0.ancestorof(n4) )
111 assert_true( n2.ancestorof(n3) )
112 assert_true( n1.ancestorof(n3) )
113 assert_true( n0.ancestorof(n3) )
115 assert_false( n4.ancestorof(n4) )
116 assert_false( n4.ancestorof(n3) )
117 assert_false( n3.ancestorof(n2) )
118 assert_false( n3.ancestorof(n1) )
119 assert_false( n3.ancestorof(n0) )
121 # def test_common_ancestor_simple(self):
122 assert_true( n3.has_common_ancestor(n4) )
123 assert_true( n3.has_common_ancestor(n3) )
124 assert_true( n3.has_common_ancestor(n3) )
127 @temprepo('branched2')
128 def test_once_branched(library):
129 n7 = library.shelf(7)
130 n6 = library.shelf(6)
131 n5 = library.shelf(5)
132 n4 = library.shelf(4)
133 n3 = library.shelf(3)
134 n2 = library.shelf(2)
136 assert_true( n2.parentof(n3) )
137 assert_false( n3.parentof(n2) )
139 assert_true( n2.parentof(n5) )
140 assert_false( n5.parentof(n2) )
142 assert_false( n2.parentof(n4) )
143 assert_false( n2.parentof(n6) )
144 assert_false( n3.parentof(n5) )
145 assert_false( n5.parentof(n3) )
147 # def test_ancestorof_branched(self):
148 assert_true( n2.ancestorof(n7) )
149 assert_false( n7.ancestorof(n2) )
150 assert_true( n2.ancestorof(n6) )
151 assert_false( n6.ancestorof(n2) )
152 assert_true( n2.ancestorof(n5) )
153 assert_false( n5.ancestorof(n2) )
155 assert_false( n3.ancestorof(n5) )
156 assert_false( n5.ancestorof(n3) )
157 assert_false( n4.ancestorof(n5) )
158 assert_false( n5.ancestorof(n4) )
159 assert_false( n3.ancestorof(n7) )
160 assert_false( n7.ancestorof(n3) )
161 assert_false( n4.ancestorof(n6) )
162 assert_false( n6.ancestorof(n4) )
164 # def test_common_ancestor_branched(self):
165 assert_true( n2.has_common_ancestor(n4) )
166 assert_true( n2.has_common_ancestor(n7) )
167 assert_true( n2.has_common_ancestor(n6) )
169 # cause it's not in the right branch
170 assert_false( n5.has_common_ancestor(n3) )
171 assert_false( n7.has_common_ancestor(n4) )
174 def test_after_merge(library):
175 n8 = library.shelf(8)
176 n7 = library.shelf(7)
177 n6 = library.shelf(6)
179 assert_true( n7.parentof(n8) )
180 assert_false( n8.parentof(n7) )
182 assert_true( n7.ancestorof(n8) )
183 assert_true( n6.ancestorof(n8) )
186 assert_true( n7.has_common_ancestor(n8) )
187 # cause it's not in the right branch
188 assert_false( n8.has_common_ancestor(n7) )
190 @temprepo('merged_with_local_commit')
191 def test_after_merge_and_local_commit(library):
192 n9 = library.shelf(9)
193 n8 = library.shelf(8)
194 n7 = library.shelf(7)
195 n6 = library.shelf(6)
197 assert_true( n7.parentof(n8) )
198 assert_false( n8.parentof(n7) )
200 assert_true( n9.has_common_ancestor(n8) )
201 # cause it's not in the right branch
202 assert_false( n8.has_common_ancestor(n9) )
205 @temprepo('branched2')
206 def test_merge_personal_to_default(library):
207 main = library.shelf(2)
210 local = library.shelf(7)
213 document = library.document("ala", "admin")
214 shared = document.shared()
215 assert_true( shared is None )
216 document.share("Here is my copy!")
218 assert_equal( document.shelf(), local) # local didn't change
220 shared = document.shared()
221 assert_true( shared is not None )
223 print library.shelf()
225 new_main = shared.shelf()
226 assert_not_equal( new_main, main) # main has new revision
229 assert_true( main.parentof(new_main) )
230 assert_true( local.parentof(new_main) )
233 def test_create_branch(library):
234 tester_cab = library.cabinet("anotherone", "tester", create=True)
235 assert_equal( list(tester_cab.parts()), ['anotherone'])