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 tempfile |
michael@0 | 9 | import unittest |
michael@0 | 10 | |
michael@0 | 11 | import mozfile |
michael@0 | 12 | from mozversion import get_version |
michael@0 | 13 | |
michael@0 | 14 | |
michael@0 | 15 | class SourcesTest(unittest.TestCase): |
michael@0 | 16 | """test getting version information from a sources xml""" |
michael@0 | 17 | |
michael@0 | 18 | application_ini = """[App]\nName = B2G\n""" |
michael@0 | 19 | sources_xml = """<?xml version="1.0" ?><manifest> |
michael@0 | 20 | <project path="build" revision="build_revision" /> |
michael@0 | 21 | <project path="gaia" revision="gaia_revision" /> |
michael@0 | 22 | <project path="gecko" revision="gecko_revision" /> |
michael@0 | 23 | </manifest> |
michael@0 | 24 | """ |
michael@0 | 25 | |
michael@0 | 26 | def setUp(self): |
michael@0 | 27 | self.cwd = os.getcwd() |
michael@0 | 28 | self.tempdir = tempfile.mkdtemp() |
michael@0 | 29 | |
michael@0 | 30 | self.binary = os.path.join(self.tempdir, 'binary') |
michael@0 | 31 | with open(self.binary, 'w') as f: |
michael@0 | 32 | f.write('foobar') |
michael@0 | 33 | |
michael@0 | 34 | def tearDown(self): |
michael@0 | 35 | os.chdir(self.cwd) |
michael@0 | 36 | mozfile.remove(self.tempdir) |
michael@0 | 37 | |
michael@0 | 38 | def test_sources(self): |
michael@0 | 39 | with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: |
michael@0 | 40 | f.writelines(self.application_ini) |
michael@0 | 41 | |
michael@0 | 42 | sources = os.path.join(self.tempdir, 'sources.xml') |
michael@0 | 43 | with open(sources, 'w') as f: |
michael@0 | 44 | f.writelines(self.sources_xml) |
michael@0 | 45 | |
michael@0 | 46 | os.chdir(self.tempdir) |
michael@0 | 47 | self._check_version(get_version(sources=sources)) |
michael@0 | 48 | |
michael@0 | 49 | def test_sources_in_current_directory(self): |
michael@0 | 50 | with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: |
michael@0 | 51 | f.writelines(self.application_ini) |
michael@0 | 52 | |
michael@0 | 53 | with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f: |
michael@0 | 54 | f.writelines(self.sources_xml) |
michael@0 | 55 | |
michael@0 | 56 | os.chdir(self.tempdir) |
michael@0 | 57 | self._check_version(get_version()) |
michael@0 | 58 | |
michael@0 | 59 | def test_invalid_sources_path(self): |
michael@0 | 60 | v = get_version(self.binary, os.path.join(self.tempdir, 'invalid')) |
michael@0 | 61 | self.assertEqual(v, {}) |
michael@0 | 62 | |
michael@0 | 63 | def test_missing_sources_file(self): |
michael@0 | 64 | v = get_version(self.binary) |
michael@0 | 65 | self.assertEqual(v, {}) |
michael@0 | 66 | |
michael@0 | 67 | def _check_version(self, version): |
michael@0 | 68 | self.assertEqual(version.get('build_changeset'), 'build_revision') |
michael@0 | 69 | self.assertEqual(version.get('gaia_changeset'), 'gaia_revision') |
michael@0 | 70 | self.assertEqual(version.get('gecko_changeset'), 'gecko_revision') |
michael@0 | 71 | self.assertIsNone(version.get('invalid_key')) |
michael@0 | 72 | |
michael@0 | 73 | |
michael@0 | 74 | if __name__ == '__main__': |
michael@0 | 75 | unittest.main() |