chiark / gitweb /
scanner: fix tests so they work on all tested platforms
[fdroidserver.git] / tests / scanner.TestCase
1 #!/usr/bin/env python3
2
3 import glob
4 import inspect
5 import logging
6 import optparse
7 import os
8 import sys
9 import unittest
10
11 localmodule = os.path.realpath(
12     os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
13 print('localmodule: ' + localmodule)
14 if localmodule not in sys.path:
15     sys.path.insert(0, localmodule)
16
17 import fdroidserver.common
18 import fdroidserver.metadata
19 import fdroidserver.scanner
20
21
22 class ScannerTest(unittest.TestCase):
23
24     def setUp(self):
25         logging.basicConfig(level=logging.INFO)
26         self.basedir = os.path.join(localmodule, 'tests')
27
28     def test_scan_source_files(self):
29         source_files = os.path.join(self.basedir, 'source-files')
30         projects = {
31             'Zillode': 1,
32             'firebase-suspect': 1
33         }
34         for d in glob.glob(os.path.join(source_files, '*')):
35             build = fdroidserver.metadata.Build()
36             fatal_problems = fdroidserver.scanner.scan_source(d, build)
37             self.assertEqual(projects.get(os.path.basename(d), 0),
38                              fatal_problems)
39
40
41 if __name__ == "__main__":
42     parser = optparse.OptionParser()
43     parser.add_option("-v", "--verbose", action="store_true", default=False,
44                       help="Spew out even more information than normal")
45     (fdroidserver.common.options, args) = parser.parse_args(['--verbose'])
46
47     newSuite = unittest.TestSuite()
48     newSuite.addTest(unittest.makeSuite(ScannerTest))
49     unittest.main(failfast=False)