3 # 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.common
20 import fdroidserver.lint
23 class LintTest(unittest.TestCase):
24 '''fdroidserver/lint.py'''
26 def test_check_for_unsupported_metadata_files(self):
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())
34 tmpdir = os.path.join(localmodule, '.testfiles')
35 tmptestsdir = tempfile.mkdtemp(prefix='test_check_for_unsupported_metadata_files-',
37 self.assertFalse(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
38 shutil.copytree(os.path.join(localmodule, 'tests', 'metadata'),
39 os.path.join(tmptestsdir, 'metadata'),
40 ignore=shutil.ignore_patterns('apk', 'dump', '*.json'))
41 self.assertFalse(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
42 shutil.copy(os.path.join(localmodule, 'tests', 'metadata', 'org.adaway.json'),
43 os.path.join(tmptestsdir, 'metadata'))
44 self.assertTrue(fdroidserver.lint.check_for_unsupported_metadata_files(tmptestsdir + '/'))
47 if __name__ == "__main__":
48 parser = optparse.OptionParser()
49 parser.add_option("-v", "--verbose", action="store_true", default=False,
50 help="Spew out even more information than normal")
51 (fdroidserver.lint.options, args) = parser.parse_args(['--verbose'])
52 fdroidserver.common.options = fdroidserver.lint.options
54 newSuite = unittest.TestSuite()
55 newSuite.addTest(unittest.makeSuite(LintTest))
56 unittest.main(failfast=False)