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=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 + '/'))
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
53 newSuite = unittest.TestSuite()
54 newSuite.addTest(unittest.makeSuite(LintTest))
55 unittest.main(failfast=False)