1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mozbase/mozversion/tests/test_b2g.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 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 +import zipfile 1.14 + 1.15 +import mozfile 1.16 +from mozversion import get_version 1.17 + 1.18 + 1.19 +class SourcesTest(unittest.TestCase): 1.20 + """test getting version information from a sources xml""" 1.21 + 1.22 + def setUp(self): 1.23 + self.tempdir = tempfile.mkdtemp() 1.24 + 1.25 + self.binary = os.path.join(self.tempdir, 'binary') 1.26 + with open(self.binary, 'w') as f: 1.27 + f.write('foobar') 1.28 + 1.29 + with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f: 1.30 + f.writelines("""[App]\nName = B2G\n""") 1.31 + 1.32 + def tearDown(self): 1.33 + mozfile.remove(self.tempdir) 1.34 + 1.35 + def _create_zip(self, revision, date='date'): 1.36 + zip_path = os.path.join( 1.37 + self.tempdir, 'gaia', 'profile', 'webapps', 1.38 + 'settings.gaiamobile.org', 'application.zip') 1.39 + os.makedirs(os.path.dirname(zip_path)) 1.40 + app_zip = zipfile.ZipFile(zip_path, 'w') 1.41 + app_zip.writestr('resources/gaia_commit.txt', revision + '\n' + date) 1.42 + app_zip.close() 1.43 + 1.44 + def test_gaia_commit(self): 1.45 + self._create_zip('a' * 40, 'date') 1.46 + v = get_version(self.binary) 1.47 + self.assertEqual(v.get('gaia_changeset'), 'a' * 40) 1.48 + self.assertEqual(v.get('gaia_date'), 'date') 1.49 + 1.50 + def test_invalid_gaia_commit(self): 1.51 + self._create_zip('a' * 41) 1.52 + v = get_version(self.binary) 1.53 + self.assertIsNone(v.get('gaia_changeset')) 1.54 + 1.55 + def test_missing_gaia_commit(self): 1.56 + v = get_version(self.binary) 1.57 + self.assertIsNone(v.get('gaia_changeset')) 1.58 + self.assertIsNone(v.get('gaia_date')) 1.59 + 1.60 + 1.61 +if __name__ == '__main__': 1.62 + unittest.main()