chiark / gitweb /
433c07875d8f39755f6af072bc7c113d3b2455e6
[fdroidserver.git] / tests / lint.TestCase
1 #!/usr/bin/env python3
2
3 # http://www.drdobbs.com/testing/unit-testing-with-python/240165163
4
5 import inspect
6 import optparse
7 import os
8 import shutil
9 import sys
10 import tempfile
11 import unittest
12
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)
18
19 import fdroidserver.common
20 import fdroidserver.lint
21
22
23 class LintTest(unittest.TestCase):
24     '''fdroidserver/lint.py'''
25
26     def test_check_for_unsupported_metadata_files(self):
27         config = dict()
28         fdroidserver.common.fill_config_defaults(config)
29         config['accepted_formats'] = ('txt', 'yml')
30         fdroidserver.common.config = config
31         fdroidserver.lint.config = config
32         self.assertTrue(fdroidserver.lint.check_for_unsupported_metadata_files())
33
34         tmpdir = os.path.join(localmodule, '.testfiles')
35         tmptestsdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=tmpdir)
36         self.assertFalse(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
37         shutil.copytree(os.path.join(localmodule, 'tests', 'metadata'),
38                         os.path.join(tmptestsdir, 'metadata'),
39                         ignore=shutil.ignore_patterns('apk', 'dump', '*.json'))
40         self.assertFalse(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
41         shutil.copy(os.path.join(localmodule, 'tests', 'metadata', 'org.adaway.json'),
42                     os.path.join(tmptestsdir, 'metadata'))
43         self.assertTrue(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
44
45
46 if __name__ == "__main__":
47     parser = optparse.OptionParser()
48     parser.add_option("-v", "--verbose", action="store_true", default=False,
49                       help="Spew out even more information than normal")
50     (fdroidserver.lint.options, args) = parser.parse_args(['--verbose'])
51     fdroidserver.common.options = fdroidserver.lint.options
52
53     newSuite = unittest.TestSuite()
54     newSuite.addTest(unittest.makeSuite(LintTest))
55     unittest.main(failfast=False)