3 # 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))
51 logging.basicConfig(level=logging.DEBUG)
52 self.basedir = os.path.join(localmodule, 'tests')
53 self.tmpdir = os.path.abspath(os.path.join(self.basedir, '..', '.testfiles'))
54 if not os.path.exists(self.tmpdir):
55 os.makedirs(self.tmpdir)
56 os.chdir(self.basedir)
58 def test_force_gradle_build_tools(self):
59 testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir)
60 shutil.copytree(os.path.join(os.path.dirname(__file__), 'source-files'),
61 os.path.join(testdir, 'source-files'))
62 teststring = 'FAKE_VERSION_FOR_TESTING'
63 fdroidserver.build.force_gradle_build_tools(testdir, teststring)
64 pattern = re.compile(bytes("buildToolsVersion[\s=]+'%s'\s+" % teststring, 'utf8'))
65 for p in ('source-files/fdroid/fdroidclient/build.gradle',
66 'source-files/Zillode/syncthing-silk/build.gradle',
67 'source-files/open-keychain/open-keychain/build.gradle',
68 'source-files/osmandapp/osmand/build.gradle',
69 'source-files/open-keychain/open-keychain/OpenKeychain/build.gradle'):
70 with open(os.path.join(testdir, p), 'rb') as f:
72 self.assertIsNotNone(pattern.search(filedata))
75 if __name__ == "__main__":
76 parser = optparse.OptionParser()
77 parser.add_option("-v", "--verbose", action="store_true", default=False,
78 help="Spew out even more information than normal")
79 (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
81 newSuite = unittest.TestSuite()
82 newSuite.addTest(unittest.makeSuite(BuildTest))
83 unittest.main(failfast=False)