2 # -*- coding: utf-8 -*-
4 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
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)
19 import fdroidserver.build
20 import fdroidserver.common
23 class BuildTest(unittest.TestCase):
24 '''fdroidserver/build.py'''
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
38 print 'no build-tools found: ' + build_tools
42 for cmd in ('aapt', 'adb', 'android', 'zipalign'):
43 path = fdroidserver.common.find_sdk_tools_cmd(cmd)
45 self.assertTrue(os.path.exists(path))
46 self.assertTrue(os.path.isfile(path))
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))
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'])
63 newSuite = unittest.TestSuite()
64 newSuite.addTest(unittest.makeSuite(BuildTest))