1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozversion/tests/test_sources.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +#!/usr/bin/env python 1.5 + 1.6 +# This Source Code Form is subject to the terms of the Mozilla Public 1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 +# You can obtain one at http://mozilla.org/MPL/2.0/. 1.9 + 1.10 +import os 1.11 +import tempfile 1.12 +import unittest 1.13 + 1.14 +import mozfile 1.15 +from mozversion import get_version 1.16 + 1.17 + 1.18 +class SourcesTest(unittest.TestCase): 1.19 + """test getting version information from a sources xml""" 1.20 + 1.21 + application_ini = """[App]\nName = B2G\n""" 1.22 + sources_xml = """<?xml version="1.0" ?><manifest> 1.23 + <project path="build" revision="build_revision" /> 1.24 + <project path="gaia" revision="gaia_revision" /> 1.25 + <project path="gecko" revision="gecko_revision" /> 1.26 +</manifest> 1.27 +""" 1.28 + 1.29 + def setUp(self): 1.30 + self.cwd = os.getcwd() 1.31 + self.tempdir = tempfile.mkdtemp() 1.32 + 1.33 + self.binary = os.path.join(self.tempdir, 'binary') 1.34 + with open(self.binary, 'w') as f: 1.35 + f.write('foobar') 1.36 + 1.37 + def tearDown(self): 1.38 + os.chdir(self.cwd) 1.39 + mozfile.remove(self.tempdir) 1.40 + 1.41 + def test_sources(self): 1.42 + with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: 1.43 + f.writelines(self.application_ini) 1.44 + 1.45 + sources = os.path.join(self.tempdir, 'sources.xml') 1.46 + with open(sources, 'w') as f: 1.47 + f.writelines(self.sources_xml) 1.48 + 1.49 + os.chdir(self.tempdir) 1.50 + self._check_version(get_version(sources=sources)) 1.51 + 1.52 + def test_sources_in_current_directory(self): 1.53 + with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: 1.54 + f.writelines(self.application_ini) 1.55 + 1.56 + with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f: 1.57 + f.writelines(self.sources_xml) 1.58 + 1.59 + os.chdir(self.tempdir) 1.60 + self._check_version(get_version()) 1.61 + 1.62 + def test_invalid_sources_path(self): 1.63 + v = get_version(self.binary, os.path.join(self.tempdir, 'invalid')) 1.64 + self.assertEqual(v, {}) 1.65 + 1.66 + def test_missing_sources_file(self): 1.67 + v = get_version(self.binary) 1.68 + self.assertEqual(v, {}) 1.69 + 1.70 + def _check_version(self, version): 1.71 + self.assertEqual(version.get('build_changeset'), 'build_revision') 1.72 + self.assertEqual(version.get('gaia_changeset'), 'gaia_revision') 1.73 + self.assertEqual(version.get('gecko_changeset'), 'gecko_revision') 1.74 + self.assertIsNone(version.get('invalid_key')) 1.75 + 1.76 + 1.77 +if __name__ == '__main__': 1.78 + unittest.main()