From f21481ca81a6120b6ac8b9db095c4c417069ea59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Mon, 20 Jan 2020 23:16:34 +0100 Subject: [PATCH] add some simple tests for main --- tests/main.TestCase | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100755 tests/main.TestCase diff --git a/tests/main.TestCase b/tests/main.TestCase new file mode 100755 index 00000000..82adac46 --- /dev/null +++ b/tests/main.TestCase @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 + +import inspect +import logging +import optparse +import os +import shutil +import sys +import unittest +import tempfile +import textwrap +from unittest import mock + +localmodule = os.path.realpath( + os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')) +print('localmodule: ' + localmodule) +if localmodule not in sys.path: + sys.path.insert(0, localmodule) + +from fdroidserver import common +import fdroidserver.__main__ + + +class FdroidTest(unittest.TestCase): + '''this tests fdroid.py''' + + def test_commands(self): + """make sure the built in sub-command defs didn't change unintentionally""" + self.assertListEqual([x for x in fdroidserver.__main__.commands.keys()], + ['build', + 'init', + 'publish', + 'gpgsign', + 'update', + 'deploy', + 'verify', + 'checkupdates', + 'import', + 'install', + 'readmeta', + 'rewritemeta', + 'lint', + 'scanner', + 'dscanner', + 'stats', + 'server', + 'signindex', + 'btlog', + 'signatures', + 'nightly', + 'mirror']) + + def test_call_init(self): + co = mock.Mock() + with mock.patch('sys.argv', ['', 'init', '-h']): + with mock.patch('fdroidserver.init.main', co): + with mock.patch('sys.exit', lambda x: None): + fdroidserver.__main__.main() + co.assert_called_once() + + def test_call_deploy(self): + co = mock.Mock() + with mock.patch('sys.argv', ['', 'deploy', '-h']): + with mock.patch('fdroidserver.server.main', co): + with mock.patch('sys.exit', lambda x: None): + fdroidserver.__main__.main() + co.assert_called_once() + + +if __name__ == "__main__": + os.chdir(os.path.dirname(__file__)) + + parser = optparse.OptionParser() + parser.add_option("-v", "--verbose", action="store_true", default=False, + help="Spew out even more information than normal") + (common.options, args) = parser.parse_args(['--verbose']) + + newSuite = unittest.TestSuite() + newSuite.addTest(unittest.makeSuite(FdroidTest)) + unittest.main(failfast=False)