Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/usr/bin/env python |
michael@0 | 2 | |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 5 | # You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | import os |
michael@0 | 8 | import shutil |
michael@0 | 9 | import tempfile |
michael@0 | 10 | import unittest |
michael@0 | 11 | |
michael@0 | 12 | from manifestparser import convert |
michael@0 | 13 | |
michael@0 | 14 | class TestSymlinkConversion(unittest.TestCase): |
michael@0 | 15 | """ |
michael@0 | 16 | test conversion of a directory tree with symlinks to a manifest structure |
michael@0 | 17 | """ |
michael@0 | 18 | |
michael@0 | 19 | # Currently broken: see |
michael@0 | 20 | # https://bugzilla.mozilla.org/show_bug.cgi?id=902610 |
michael@0 | 21 | # https://bugzilla.mozilla.org/show_bug.cgi?id=920938 |
michael@0 | 22 | |
michael@0 | 23 | def create_stub(self, directory=None): |
michael@0 | 24 | """stub out a directory with files in it""" |
michael@0 | 25 | |
michael@0 | 26 | files = ('foo', 'bar', 'fleem') |
michael@0 | 27 | if directory is None: |
michael@0 | 28 | directory = tempfile.mkdtemp() |
michael@0 | 29 | for i in files: |
michael@0 | 30 | file(os.path.join(directory, i), 'w').write(i) |
michael@0 | 31 | subdir = os.path.join(directory, 'subdir') |
michael@0 | 32 | os.mkdir(subdir) |
michael@0 | 33 | file(os.path.join(subdir, 'subfile'), 'w').write('baz') |
michael@0 | 34 | return directory |
michael@0 | 35 | |
michael@0 | 36 | def test_relpath(self): |
michael@0 | 37 | """test convert `relative_to` functionality""" |
michael@0 | 38 | |
michael@0 | 39 | oldcwd = os.getcwd() |
michael@0 | 40 | stub = self.create_stub() |
michael@0 | 41 | try: |
michael@0 | 42 | # subdir with in-memory manifest |
michael@0 | 43 | files = ['../bar', '../fleem', '../foo', 'subfile'] |
michael@0 | 44 | subdir = os.path.join(stub, 'subdir') |
michael@0 | 45 | os.chdir(subdir) |
michael@0 | 46 | parser = convert([stub], relative_to='.') |
michael@0 | 47 | self.assertEqual([i['name'] for i in parser.tests], |
michael@0 | 48 | files) |
michael@0 | 49 | except: |
michael@0 | 50 | raise |
michael@0 | 51 | finally: |
michael@0 | 52 | shutil.rmtree(stub) |
michael@0 | 53 | os.chdir(oldcwd) |
michael@0 | 54 | |
michael@0 | 55 | def test_relpath_symlink(self): |
michael@0 | 56 | """ |
michael@0 | 57 | Ensure `relative_to` works in a symlink. |
michael@0 | 58 | Not available on windows. |
michael@0 | 59 | """ |
michael@0 | 60 | |
michael@0 | 61 | symlink = getattr(os, 'symlink', None) |
michael@0 | 62 | if symlink is None: |
michael@0 | 63 | return # symlinks unavailable on this platform |
michael@0 | 64 | |
michael@0 | 65 | oldcwd = os.getcwd() |
michael@0 | 66 | workspace = tempfile.mkdtemp() |
michael@0 | 67 | try: |
michael@0 | 68 | tmpdir = os.path.join(workspace, 'directory') |
michael@0 | 69 | os.makedirs(tmpdir) |
michael@0 | 70 | linkdir = os.path.join(workspace, 'link') |
michael@0 | 71 | symlink(tmpdir, linkdir) |
michael@0 | 72 | self.create_stub(tmpdir) |
michael@0 | 73 | |
michael@0 | 74 | # subdir with in-memory manifest |
michael@0 | 75 | files = ['../bar', '../fleem', '../foo', 'subfile'] |
michael@0 | 76 | subdir = os.path.join(linkdir, 'subdir') |
michael@0 | 77 | os.chdir(os.path.realpath(subdir)) |
michael@0 | 78 | for directory in (tmpdir, linkdir): |
michael@0 | 79 | parser = convert([directory], relative_to='.') |
michael@0 | 80 | self.assertEqual([i['name'] for i in parser.tests], |
michael@0 | 81 | files) |
michael@0 | 82 | finally: |
michael@0 | 83 | shutil.rmtree(workspace) |
michael@0 | 84 | os.chdir(oldcwd) |
michael@0 | 85 | |
michael@0 | 86 | # a more complicated example |
michael@0 | 87 | oldcwd = os.getcwd() |
michael@0 | 88 | workspace = tempfile.mkdtemp() |
michael@0 | 89 | try: |
michael@0 | 90 | tmpdir = os.path.join(workspace, 'directory') |
michael@0 | 91 | os.makedirs(tmpdir) |
michael@0 | 92 | linkdir = os.path.join(workspace, 'link') |
michael@0 | 93 | symlink(tmpdir, linkdir) |
michael@0 | 94 | self.create_stub(tmpdir) |
michael@0 | 95 | files = ['../bar', '../fleem', '../foo', 'subfile'] |
michael@0 | 96 | subdir = os.path.join(linkdir, 'subdir') |
michael@0 | 97 | subsubdir = os.path.join(subdir, 'sub') |
michael@0 | 98 | os.makedirs(subsubdir) |
michael@0 | 99 | linksubdir = os.path.join(linkdir, 'linky') |
michael@0 | 100 | linksubsubdir = os.path.join(subsubdir, 'linky') |
michael@0 | 101 | symlink(subdir, linksubdir) |
michael@0 | 102 | symlink(subdir, linksubsubdir) |
michael@0 | 103 | for dest in (subdir,): |
michael@0 | 104 | os.chdir(dest) |
michael@0 | 105 | for directory in (tmpdir, linkdir): |
michael@0 | 106 | parser = convert([directory], relative_to='.') |
michael@0 | 107 | self.assertEqual([i['name'] for i in parser.tests], |
michael@0 | 108 | files) |
michael@0 | 109 | finally: |
michael@0 | 110 | shutil.rmtree(workspace) |
michael@0 | 111 | os.chdir(oldcwd) |
michael@0 | 112 | |
michael@0 | 113 | |
michael@0 | 114 | if __name__ == '__main__': |
michael@0 | 115 | unittest.main() |