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 testOpening(self):
33 library = MercurialLibrary(self.path + '/cleanrepo')
35 def testMainCabinet(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 testReadDocument(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 testReadUTF8Document(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 testWriteDocument(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 testCreateDocument(self):
70 repopath = os.path.join(self.path, 'testrepoI')
72 library = MercurialLibrary(repopath)
73 doc = library.main_cabinet.create("another_file")
74 doc.write("Some text")
75 assert_equal( doc.read(), "Some text")
76 assert_true( os.path.isfile( os.path.join(repopath, "pub_another_file.xml")) )
78 def testSwitchBranch(self):
79 library = MercurialLibrary(self.path + '/testrepoII')
81 tester_cab = library.cabinet("valid_file", "tester", create=False)
82 assert_equal( list(tester_cab.documents()), ['valid_file'])
84 @raises(wlrepo.CabinetNotFound)
85 def testNoBranch(self):
86 library = MercurialLibrary(self.path + '/testrepoII')
87 tester_cab = library.cabinet("ugh", "tester", create=False)
90 def testCreateBranch(self):
91 repopath = os.path.join(self.path, 'testrepoII')
92 library = MercurialLibrary(repopath)
94 tester_cab = library.cabinet("anotherone", "tester", create=True)
95 assert_equal( list(tester_cab.documents()), ['anotherone'])