2 # -*- coding: utf-8 -*-
4 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
15 localmodule = os.path.realpath(
16 os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
17 print('localmodule: ' + localmodule)
18 if localmodule not in sys.path:
19 sys.path.insert(0, localmodule)
21 import fdroidserver.build
22 import fdroidserver.common
25 class BuildTest(unittest.TestCase):
26 '''fdroidserver/build.py'''
28 def _set_build_tools(self):
29 build_tools = os.path.join(fdroidserver.common.config['sdk_path'], 'build-tools')
30 if os.path.exists(build_tools):
31 fdroidserver.common.config['build_tools'] = ''
32 for f in sorted(os.listdir(build_tools), reverse=True):
33 versioned = os.path.join(build_tools, f)
34 if os.path.isdir(versioned) \
35 and os.path.isfile(os.path.join(versioned, 'aapt')):
36 fdroidserver.common.config['build_tools'] = versioned
40 print 'no build-tools found: ' + build_tools
44 for cmd in ('aapt', 'adb', 'android', 'zipalign'):
45 path = fdroidserver.common.find_sdk_tools_cmd(cmd)
47 self.assertTrue(os.path.exists(path))
48 self.assertTrue(os.path.isfile(path))
50 def test_adapt_gradle(self):
51 testsbase = os.path.join(os.path.dirname(__file__), '..', '.testfiles')
52 if not os.path.exists(testsbase):
53 os.makedirs(testsbase)
54 testsdir = tempfile.mkdtemp(prefix='test_adapt_gradle', dir=testsbase)
55 shutil.copytree(os.path.join(os.path.dirname(__file__), 'source-files'),
56 os.path.join(testsdir, 'source-files'))
57 teststring = 'FAKE_VERSION_FOR_TESTING'
58 fdroidserver.build.config = {}
59 fdroidserver.build.config['build_tools'] = teststring
60 fdroidserver.build.adapt_gradle(testsdir)
61 pattern = re.compile("buildToolsVersion[\s=]+'%s'\s+" % teststring)
62 for p in ('source-files/fdroid/fdroidclient/build.gradle',
63 'source-files/Zillode/syncthing-silk/build.gradle',
64 'source-files/open-keychain/open-keychain/build.gradle',
65 'source-files/osmandapp/osmand/build.gradle',
66 'source-files/open-keychain/open-keychain/OpenKeychain/build.gradle'):
67 with open(os.path.join(testsdir, p), 'r') as f:
69 self.assertIsNotNone(pattern.search(filedata))
71 if __name__ == "__main__":
72 parser = optparse.OptionParser()
73 parser.add_option("-v", "--verbose", action="store_true", default=False,
74 help="Spew out even more information than normal")
75 (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
77 newSuite = unittest.TestSuite()
78 newSuite.addTest(unittest.makeSuite(BuildTest))