def test_no_unicode_in_help_strings(self, mock_stdout): helps = ['--help', 'topics'] for key in help._TOPICS.keys(): helps.append(str(key)) # Get a list of plugins import snapcraft.plugins import os from pathlib import Path for plugin in Path(snapcraft.plugins.__path__[0]).glob('*.py'): if (os.path.isfile(str(plugin)) and not os.path.basename(str(plugin)).startswith('_')): helps.append(os.path.basename(str(plugin)[:-3])) for key in helps: mock_stdout.truncate(0) mock_stdout.seek(0) with self.subTest(key=key): if key is '--help': from snapcraft import main print(main.__doc__) else: help.main([key]) try: mock_stdout.getvalue().encode('ascii') except UnicodeEncodeError: self.fail('Non-ASCII characters in help text for ' '{!r}'.format(key))
def test_print_topics(self, mock_stdout): help.main(['topics']) output = mock_stdout.getvalue().strip().split('\n') for t in help._TOPICS: self.assertTrue(t in output, 'Missing topic: {!r} in {!r}'.format(t, output))
def test_print_topics(self, mock_stdout): help.main(['topics']) output = mock_stdout.getvalue().strip().split('\n') for t in help._TOPICS: self.assertTrue( t in output, 'Missing topic: {!r} in {!r}'.format(t, output))
def test_print_module_help_for_valid_plugin(self, mock_stdout): help.main(['nil']) expected = 'The nil plugin is' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual(output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_print_topic_help_for_valid_topic(self, mock_stdout): help.main(['sources']) expected = 'Common keywords for plugins that use common source' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual(output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_print_module_help_for_valid_plugin(self, mock_stdout): help.main(['nil']) expected = 'The nil plugin is' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual( output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_print_topic_help_for_valid_topic(self, mock_stdout): help.main(['sources']) expected = 'Common keywords for plugins that use common source' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual( output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_show_module_help_with_devel_for_valid_plugin(self, mock_stdout): help.main(['nil', '--devel']) expected = 'Help on module snapcraft.plugins.nil in snapcraft.plugins' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual(output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_print_module_help_for_valid_plugin(self, mock_stdout): help.main(["nil"]) expected = "The nil plugin is" output = mock_stdout.getvalue()[: len(expected)] self.assertEqual( output, expected, "The help message does not start with {!r} but with " "{!r} instead".format(expected, output), )
def test_show_module_help_with_devel_for_valid_plugin(self, mock_stdout): help.main(['nil', '--devel']) expected = 'Help on module snapcraft.plugins.nil in snapcraft.plugins' output = mock_stdout.getvalue()[:len(expected)] self.assertEqual( output, expected, 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected, output))
def test_topic_and_plugin_not_found_exits_with_tip(self): fake_logger = fixtures.FakeLogger() self.useFixture(fake_logger) with self.assertRaises(SystemExit) as raised: help.main(['does-not-exist']) self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.') self.assertEqual('The plugin does not exist. Run `snapcraft ' 'list-plugins` to see the available plugins.\n', fake_logger.output)
def test_show_module_help_with_devel_for_valid_plugin(self, mock_stdout): help.main(["nil", "--devel"]) expected = "Help on module snapcraft.plugins.nil in snapcraft.plugins" output = mock_stdout.getvalue()[: len(expected)] self.assertEqual( output, expected, "The help message does not start with {!r} but with " "{!r} instead".format(expected, output), )
def test_topic_and_plugin_not_found_exits_with_tip(self): fake_logger = fixtures.FakeLogger() self.useFixture(fake_logger) with self.assertRaises(SystemExit) as raised: help.main(['does-not-exist']) self.assertEqual(raised.exception.code, 1, 'Wrong exit code returned.') self.assertEqual( 'The plugin does not exist. Run `snapcraft ' 'list-plugins` to see the available plugins.\n', fake_logger.output)
def test_print_topic_help_with_devel_for_valid_topic(self, mock_stdout): expected = {"sources": "Help on module snapcraft", "plugins": "Help on package snapcraft"} for key in help._TOPICS: mock_stdout.truncate(0) mock_stdout.seek(0) with self.subTest(key=key): help.main([key, "--devel"]) output = mock_stdout.getvalue()[: len(expected[key])] self.assertEqual( output, expected[key], "The help message does not start with {!r} but with " "{!r} instead".format(expected[key], output), )
def test_print_topic_help_with_devel_for_valid_topic(self, mock_stdout): expected = { 'sources': 'Help on module snapcraft', 'plugins': 'Help on package snapcraft', } for key in help._TOPICS: mock_stdout.truncate(0) mock_stdout.seek(0) with self.subTest(key=key): help.main([key, '--devel']) output = mock_stdout.getvalue()[:len(expected[key])] self.assertEqual( output, expected[key], 'The help message does not start with {!r} but with ' '{!r} instead'.format(expected[key], output))
def test_print_topics(self, mock_stdout): help.main(["topics"]) output = mock_stdout.getvalue().strip().split("\n") for t in help._TOPICS: self.assertTrue(t in output, "Missing topic: {!r} in {!r}".format(t, output))
def test_print_module_help_when_no_help_for_valid_plugin( self, mock_stdout): help.main(['jdk']) self.assertEqual('The plugin has no documentation\n', mock_stdout.getvalue())