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