chiark / gitweb /
e6d9997c2e23f7ff765af24ecfbc12655e2ca4a1
[fdroidserver.git] / tests / build.TestCase
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
5
6 import inspect
7 import optparse
8 import os
9 import re
10 import sys
11 import unittest
12
13 localmodule = os.path.realpath(
14     os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
15 print('localmodule: ' + localmodule)
16 if localmodule not in sys.path:
17     sys.path.insert(0, localmodule)
18
19 import fdroidserver.build
20 import fdroidserver.common
21
22
23 class BuildTest(unittest.TestCase):
24     '''fdroidserver/build.py'''
25
26     def _set_build_tools(self):
27         build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools')
28         if os.path.exists(build_tools):
29             fdroidserver.common.config['build_tools'] = ''
30             for f in sorted(os.listdir(build_tools), reverse=True):
31                 versioned = os.path.join(build_tools, f)
32                 if os.path.isdir(versioned) \
33                         and os.path.isfile(os.path.join(versioned, 'aapt')):
34                     fdroidserver.common.config['build_tools'] = versioned
35                     break
36             return True
37         else:
38             print 'no build-tools found: ' + build_tools
39             return False
40
41     def _find_all(self):
42         for cmd in ('aapt', 'adb', 'android', 'zipalign'):
43             path = fdroidserver.common.find_sdk_tools_cmd(cmd)
44             if path is not None:
45                 self.assertTrue(os.path.exists(path))
46                 self.assertTrue(os.path.isfile(path))
47
48     def test_adapt_gradle(self):
49         teststring = 'FAKE_VERSION_FOR_TESTING'
50         fdroidserver.build.config = {}
51         fdroidserver.build.config['build_tools'] = teststring
52         fdroidserver.build.adapt_gradle(os.path.dirname(__file__))
53         filedata = open(os.path.join(os.path.dirname(__file__), 'build.gradle')).read()
54         self.assertIsNotNone(re.search("\s+buildToolsVersion = '%s'\s+" % teststring, filedata))
55
56
57 if __name__ == "__main__":
58     parser = optparse.OptionParser()
59     parser.add_option("-v", "--verbose", action="store_true", default=False,
60                       help="Spew out even more information than normal")
61     (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
62
63     newSuite = unittest.TestSuite()
64     newSuite.addTest(unittest.makeSuite(BuildTest))
65     unittest.main()