Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions
unit-JarMaker.TestJarMaker Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_a_simple_jar
def test_a_simple_symlink
def test_k_multi_relative_jar

Public Attributes

 tmpdir
 srcdir
 builddir
 refdir
 stagedir

Static Public Attributes

 debug = True

Private Member Functions

def _jar_and_compare
def _create_simple_setup

Detailed Description

Unit tests for JarMaker.py

Definition at line 138 of file unit-JarMaker.py.


Member Function Documentation

def unit-JarMaker.TestJarMaker._create_simple_setup (   self) [private]

Definition at line 202 of file unit-JarMaker.py.

00202 
00203     def _create_simple_setup(self):
00204         # create src content
00205         jarf = open(os.path.join(self.srcdir, 'jar.mn'), 'w')
00206         jarf.write('''test.jar:
00207  dir/foo (bar)
00208 ''')
00209         jarf.close()
00210         open(os.path.join(self.srcdir,'bar'),'w').write('content\n')
00211         # create reference
00212         refpath = os.path.join(self.refdir, 'chrome', 'test.jar', 'dir')
00213         os.makedirs(refpath)
00214         open(os.path.join(refpath, 'foo'), 'w').write('content\n')        

Here is the caller graph for this function:

def unit-JarMaker.TestJarMaker._jar_and_compare (   self,
  args,
  kwargs 
) [private]

Definition at line 160 of file unit-JarMaker.py.

00160 
00161     def _jar_and_compare(self, *args, **kwargs):
00162         jm = JarMaker(outputFormat='jar')
00163         kwargs['jardir'] = os.path.join(self.builddir, 'chrome')
00164         if 'topsourcedir' not in kwargs:
00165             kwargs['topsourcedir'] = self.srcdir
00166         jm.makeJars(*args, **kwargs)
00167         cwd = os.getcwd()
00168         os.chdir(self.builddir)
00169         try:
00170             # expand build to stage
00171             for path, dirs, files in os.walk('.'):
00172                 stagedir = os.path.join(self.stagedir, path)
00173                 if not os.path.isdir(stagedir):
00174                     os.mkdir(stagedir)
00175                 for file in files:
00176                     if file.endswith('.jar'):
00177                         # expand jar
00178                         stagepath = os.path.join(stagedir, file)
00179                         os.mkdir(stagepath)
00180                         zf = ZipFile(os.path.join(path, file))
00181                         # extractall is only in 2.6, do this manually :-(
00182                         for entry_name in zf.namelist():
00183                             segs = entry_name.split('/')
00184                             fname = segs.pop()
00185                             dname = os.path.join(stagepath, *segs)
00186                             if not os.path.isdir(dname):
00187                                 os.makedirs(dname)
00188                             if not fname:
00189                                 # directory, we're done
00190                                 continue
00191                             _c = zf.read(entry_name)
00192                             open(os.path.join(dname, fname), 'wb').write(_c)
00193                         zf.close()
00194                     else:
00195                         copy2(os.path.join(path, file), stagedir)
00196             # compare both dirs
00197             os.chdir('..')
00198             td = _TreeDiff('ref', 'stage')
00199             return td.allResults('reference', 'build')
00200         finally:
00201             os.chdir(cwd)

Here is the caller graph for this function:

def unit-JarMaker.TestJarMaker.setUp (   self)

Definition at line 143 of file unit-JarMaker.py.

00143 
00144     def setUp(self):
00145         self.tmpdir = mkdtemp()
00146         self.srcdir = os.path.join(self.tmpdir, 'src')
00147         os.mkdir(self.srcdir)
00148         self.builddir = os.path.join(self.tmpdir, 'build')
00149         os.mkdir(self.builddir)
00150         self.refdir = os.path.join(self.tmpdir, 'ref')
00151         os.mkdir(self.refdir)
00152         self.stagedir = os.path.join(self.tmpdir, 'stage')
00153         os.mkdir(self.stagedir)

def unit-JarMaker.TestJarMaker.tearDown (   self)

Definition at line 154 of file unit-JarMaker.py.

00154 
00155     def tearDown(self):
00156         if self.debug:
00157             print self.tmpdir
00158         else:
00159             rmtree(self.tmpdir)

def unit-JarMaker.TestJarMaker.test_a_simple_jar (   self)
Test a simple jar.mn

Definition at line 215 of file unit-JarMaker.py.

00215 
00216     def test_a_simple_jar(self):
00217         '''Test a simple jar.mn'''
00218         self._create_simple_setup()
00219         # call JarMaker
00220         rv = self._jar_and_compare((os.path.join(self.srcdir,'jar.mn'),),
00221                                    tuple(),
00222                                    sourcedirs = [self.srcdir])
00223         self.assertTrue(not rv, rv)

Here is the call graph for this function:

def unit-JarMaker.TestJarMaker.test_a_simple_symlink (   self)
Test a simple jar.mn with a symlink

Definition at line 224 of file unit-JarMaker.py.

00224 
00225     def test_a_simple_symlink(self):
00226         '''Test a simple jar.mn with a symlink'''
00227         if not symlinks_supported(self.srcdir):
00228             return
00229 
00230         self._create_simple_setup()
00231         jm = JarMaker(outputFormat='symlink')
00232         kwargs = {
00233             'sourcedirs': [self.srcdir],
00234             'topsourcedir': self.srcdir,
00235             'jardir': os.path.join(self.builddir, 'chrome'),
00236         }
00237         jm.makeJars((os.path.join(self.srcdir,'jar.mn'),), tuple(), **kwargs)
00238         # All we do is check that srcdir/bar points to builddir/chrome/test/dir/foo
00239         srcbar = os.path.join(self.srcdir, 'bar')
00240         destfoo = os.path.join(self.builddir, 'chrome', 'test', 'dir', 'foo')
00241         self.assertTrue(is_symlink_to(destfoo, srcbar),
00242                         "%s is not a symlink to %s" % (destfoo, srcbar))

Here is the call graph for this function:

def unit-JarMaker.TestJarMaker.test_k_multi_relative_jar (   self)
Test the API for multiple l10n jars, with different relative paths

Definition at line 243 of file unit-JarMaker.py.

00243 
00244     def test_k_multi_relative_jar(self):
00245         '''Test the API for multiple l10n jars, with different relative paths'''
00246         # create app src content
00247         def _mangle(relpath):
00248             'method we use to map relpath to srcpaths'
00249             return os.path.join(self.srcdir, 'other-' + relpath)
00250         jars = []
00251         for relpath in ('foo', 'bar'):
00252             ldir = os.path.join(self.srcdir, relpath, 'locales')
00253             os.makedirs(ldir)
00254             jp = os.path.join(ldir, 'jar.mn')
00255             jars.append(jp)
00256             open(jp, 'w').write('''ab-CD.jar:
00257 % locale app ab-CD %app
00258   app/''' + relpath + ' (%' + relpath + ''')
00259 ''')
00260             ldir = _mangle(relpath)
00261             os.mkdir(ldir)
00262             open(os.path.join(ldir, relpath), 'w').write(relpath+" content\n")
00263         # create reference
00264         mf = open(os.path.join(self.refdir, 'chrome.manifest'), 'w')
00265         mf.write('manifest chrome/ab-CD.manifest\n')
00266         mf.close()
00267 
00268         chrome_ref = os.path.join(self.refdir, 'chrome')
00269         os.mkdir(chrome_ref)
00270         mf = open(os.path.join(chrome_ref, 'ab-CD.manifest'), 'wb')
00271         mf.write('locale app ab-CD jar:ab-CD.jar!/app\n')
00272         mf.close()
00273         ldir = os.path.join(chrome_ref, 'ab-CD.jar', 'app')
00274         os.makedirs(ldir)
00275         for relpath in ('foo', 'bar'):
00276             open(os.path.join(ldir, relpath), 'w').write(relpath+" content\n")
00277         # call JarMaker
00278         difference = self._jar_and_compare(jars,
00279                                            (_mangle,),
00280                                            sourcedirs = [])
00281         self.assertTrue(not difference, difference)

Here is the call graph for this function:


Member Data Documentation

unit-JarMaker.TestJarMaker.builddir

Definition at line 147 of file unit-JarMaker.py.

Definition at line 142 of file unit-JarMaker.py.

unit-JarMaker.TestJarMaker.refdir

Definition at line 149 of file unit-JarMaker.py.

unit-JarMaker.TestJarMaker.srcdir

Definition at line 145 of file unit-JarMaker.py.

unit-JarMaker.TestJarMaker.stagedir

Definition at line 151 of file unit-JarMaker.py.

unit-JarMaker.TestJarMaker.tmpdir

Definition at line 144 of file unit-JarMaker.py.


The documentation for this class was generated from the following file: