2015-07-30 22:13:36 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
import optparse
|
|
|
|
import os
|
|
|
|
import re
|
2015-08-11 15:33:03 +02:00
|
|
|
import shutil
|
2015-07-30 22:13:36 +02:00
|
|
|
import sys
|
2015-08-11 15:33:03 +02:00
|
|
|
import tempfile
|
2015-07-30 22:13:36 +02:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
localmodule = os.path.realpath(
|
|
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
|
|
|
|
print('localmodule: ' + localmodule)
|
|
|
|
if localmodule not in sys.path:
|
|
|
|
sys.path.insert(0, localmodule)
|
|
|
|
|
|
|
|
import fdroidserver.build
|
|
|
|
import fdroidserver.common
|
|
|
|
|
|
|
|
|
|
|
|
class BuildTest(unittest.TestCase):
|
|
|
|
'''fdroidserver/build.py'''
|
|
|
|
|
|
|
|
def _set_build_tools(self):
|
|
|
|
build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools')
|
|
|
|
if os.path.exists(build_tools):
|
|
|
|
fdroidserver.common.config['build_tools'] = ''
|
|
|
|
for f in sorted(os.listdir(build_tools), reverse=True):
|
|
|
|
versioned = os.path.join(build_tools, f)
|
|
|
|
if os.path.isdir(versioned) \
|
|
|
|
and os.path.isfile(os.path.join(versioned, 'aapt')):
|
|
|
|
fdroidserver.common.config['build_tools'] = versioned
|
|
|
|
break
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
print 'no build-tools found: ' + build_tools
|
|
|
|
return False
|
|
|
|
|
|
|
|
def _find_all(self):
|
|
|
|
for cmd in ('aapt', 'adb', 'android', 'zipalign'):
|
|
|
|
path = fdroidserver.common.find_sdk_tools_cmd(cmd)
|
|
|
|
if path is not None:
|
|
|
|
self.assertTrue(os.path.exists(path))
|
|
|
|
self.assertTrue(os.path.isfile(path))
|
|
|
|
|
|
|
|
def test_adapt_gradle(self):
|
2015-08-11 15:33:03 +02:00
|
|
|
testsbase = os.path.join(os.path.dirname(__file__), '..', '.testfiles')
|
|
|
|
if not os.path.exists(testsbase):
|
|
|
|
os.makedirs(testsbase)
|
|
|
|
testsdir = tempfile.mkdtemp(prefix='test_adapt_gradle', dir=testsbase)
|
|
|
|
shutil.copytree(os.path.join(os.path.dirname(__file__), 'source-files'),
|
|
|
|
os.path.join(testsdir, 'source-files'))
|
2015-07-30 22:13:36 +02:00
|
|
|
teststring = 'FAKE_VERSION_FOR_TESTING'
|
|
|
|
fdroidserver.build.config = {}
|
|
|
|
fdroidserver.build.config['build_tools'] = teststring
|
2015-08-11 15:33:03 +02:00
|
|
|
fdroidserver.build.adapt_gradle(testsdir)
|
|
|
|
pattern = re.compile("buildToolsVersion[\s=]+'%s'\s+" % teststring)
|
|
|
|
for f in ('source-files/fdroid/fdroidclient/build.gradle',
|
|
|
|
'source-files/Zillode/syncthing-silk/build.gradle',
|
|
|
|
'source-files/open-keychain/open-keychain/build.gradle',
|
|
|
|
'source-files/osmandapp/osmand/build.gradle'):
|
|
|
|
filedata = open(os.path.join(testsdir, f)).read()
|
|
|
|
self.assertIsNotNone(pattern.search(filedata))
|
|
|
|
tp = os.path.join(testsdir,
|
|
|
|
'source-files/open-keychain/open-keychain/OpenKeychain/build.gradle')
|
|
|
|
filedata = open(tp).read()
|
|
|
|
self.assertIsNone(pattern.search(filedata))
|
2015-07-30 22:13:36 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = optparse.OptionParser()
|
|
|
|
parser.add_option("-v", "--verbose", action="store_true", default=False,
|
|
|
|
help="Spew out even more information than normal")
|
|
|
|
(fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
|
|
|
|
|
|
|
|
newSuite = unittest.TestSuite()
|
|
|
|
newSuite.addTest(unittest.makeSuite(BuildTest))
|
|
|
|
unittest.main()
|