diff --git a/for_tests/plugin-ExtraTemplate b/for_tests/plugin-ExtraTemplate deleted file mode 160000 index 82e17cc..0000000 --- a/for_tests/plugin-ExtraTemplate +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82e17cc6280f5f12fe389b2a2bc6419b105cb8a7 diff --git a/tests/asciidoc2markdown.sh b/tests/asciidoc2markdown.sh new file mode 100644 index 0000000..5509bc0 --- /dev/null +++ b/tests/asciidoc2markdown.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# Adapted from https://tinyapps.org/blog/nix/201701240700_convert_asciidoc_to_markdown.html +# Using asciidoctor 1.5.6.1 and pandoc 2.0.0.1 +# Install pandoc and asciidoctor + +if [ -f /etc/redhat-release ]; then + su - c "dnf install asciidoctor pandoc" +fi + +if [ -f /etc/lsb-release ]; then + sudo apt install asciidoctor + wget https://github.com/jgm/pandoc/releases/download/2.0.0.1/pandoc-2.0.0.1-1-amd64.deb + sudo dpkg -i pandoc-2.0.0.1-1-amd64.deb +fi + + +# Convert asciidoc to docbook using asciidoctor + +asciidoctor -b docbook index.asciidoc + +# foo.xml will be output into the same directory as foo.adoc + +# Convert docbook to markdown + +pandoc -f docbook -t gfm index.xml -o index.md + +# Unicode symbols were mangled in foo.md. Quick workaround: + +iconv -t utf-8 index.xml | pandoc -f docbook -t gfm | iconv -f utf-8> index.md + +# Pandoc inserted hard line breaks at 72 characters. Removed like so: + +pandoc -f docbook -t gfm --wrap=none # don't wrap lines at all + +pandoc -f docbook -t gfm --columns=120 # extend line breaks to 120 + diff --git a/tests/tests_File.py b/tests/tools/tests_File.py similarity index 100% rename from tests/tests_File.py rename to tests/tools/tests_File.py diff --git a/tests/tests_IO.py b/tests/tools/tests_IO.py similarity index 100% rename from tests/tests_IO.py rename to tests/tools/tests_IO.py diff --git a/tests/tests_Jeedom.py b/tests/tools/tests_Jeedom.py similarity index 100% rename from tests/tests_Jeedom.py rename to tests/tools/tests_Jeedom.py diff --git a/tests/tests_PHPFile.py b/tests/tools/tests_PHPFile.py similarity index 100% rename from tests/tests_PHPFile.py rename to tests/tools/tests_PHPFile.py diff --git a/tests/tests_add_ajax.py b/tests/tools/tests_add_ajax.py similarity index 100% rename from tests/tests_add_ajax.py rename to tests/tools/tests_add_ajax.py diff --git a/tests/tests_add_core_class.py b/tests/tools/tests_add_core_class.py similarity index 100% rename from tests/tests_add_core_class.py rename to tests/tools/tests_add_core_class.py diff --git a/tests/tests_add_cron.py b/tests/tools/tests_add_cron.py similarity index 100% rename from tests/tests_add_cron.py rename to tests/tools/tests_add_cron.py diff --git a/tests/tests_add_language.py b/tests/tools/tests_add_language.py similarity index 100% rename from tests/tests_add_language.py rename to tests/tools/tests_add_language.py diff --git a/tests/tests_interface.py b/tests/tools/tests_interface.py similarity index 91% rename from tests/tests_interface.py rename to tests/tools/tests_interface.py index f42dfb6..f787b89 100644 --- a/tests/tests_interface.py +++ b/tests/tools/tests_interface.py @@ -118,6 +118,20 @@ def test_change_author(self, side_effect): content = info_file.read() self.assertIn('"author": "Me",', content) + @patch('builtins.input', side_effect=['2', + '2', + '5', + '1', + '', + '', + '']) + def test_change_category(self, side_effect): + self.wizard_menu.start() + with open('plugin-ExtraTemplate/plugin_info/info.json', + 'r') as info_file: + content = info_file.read() + self.assertIn('"category": "security",', content) + @patch('builtins.input', side_effect=['2', '3', '1', diff --git a/tests/tests_rename_plugin.py b/tests/tools/tests_rename_plugin.py similarity index 99% rename from tests/tests_rename_plugin.py rename to tests/tools/tests_rename_plugin.py index 2a2a598..06291ee 100644 --- a/tests/tests_rename_plugin.py +++ b/tests/tools/tests_rename_plugin.py @@ -123,4 +123,3 @@ def test_rename_not_found(self): result = self.root_menu.rename_plugin('NotThat') self.assertFalse(result) self.assertTrue(os.path.exists(test_file)) - diff --git a/tests/tests_replace_info_json.py b/tests/tools/tests_replace_info_json.py similarity index 100% rename from tests/tests_replace_info_json.py rename to tests/tools/tests_replace_info_json.py diff --git a/tests/tests_tools.py b/tests/tools/tests_tools.py similarity index 100% rename from tests/tests_tools.py rename to tests/tools/tests_tools.py diff --git a/tests/tools/tests_tools_script.py b/tests/tools/tests_tools_script.py new file mode 100644 index 0000000..7cd6c1b --- /dev/null +++ b/tests/tools/tests_tools_script.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +import inspect +import os +import shutil +import sys +import unittest +from unittest.mock import patch + +current_path = os.path.abspath(inspect.getsourcefile(lambda: 0)) +current_dir = os.path.dirname(current_path) +parent_dir = current_dir[:current_dir.rfind(os.path.sep)] +sys.path.insert(0, parent_dir) +import tools + + +class TestToolsScript(unittest.TestCase): + @patch('builtins.input', side_effect=['2', + '0', + '0']) + def test_start_tools(self, side_effect): + sys.argv = ['./tools.py'] + tools.start() + self.assertTrue(os.path.exists('plugin-ExtraTemplate')) + shutil.rmtree('plugin-ExtraTemplate') diff --git a/tests/tests_update_languages.py b/tests/tools/tests_update_languages.py similarity index 100% rename from tests/tests_update_languages.py rename to tests/tools/tests_update_languages.py diff --git a/tests/tests_wizard.py b/tests/tools/tests_wizard.py similarity index 80% rename from tests/tests_wizard.py rename to tests/tools/tests_wizard.py index 3daac2e..67d3d4d 100644 --- a/tests/tests_wizard.py +++ b/tests/tools/tests_wizard.py @@ -18,7 +18,8 @@ class TestWizard(unittest.TestCase): def tearDown(self): - shutil.rmtree('plugin-PluginName') + if os.path.exists('plugin-PluginName'): + shutil.rmtree('plugin-PluginName') @patch('builtins.input', side_effect=['Plugin Name', 'PluginName', @@ -48,8 +49,6 @@ def test_default_choices(self, side_effect): self.assertIn('"id": "PluginName"', info_content) self.assertIn('"name": "Plugin Name', info_content) - - @patch('builtins.input', side_effect=['Plugin Name', 'PluginName', 'A small description', @@ -66,8 +65,10 @@ def test_choices(self, side_effect): plugin_dir = 'plugin-PluginName' info_json = os.path.join(plugin_dir, 'plugin_info', 'info.json') self.assertTrue(os.path.exists(os.path.join(plugin_dir, 'desktop', - 'php', 'PluginName.php'))) - self.assertTrue(os.path.exists(os.path.join(plugin_dir, 'core', 'php'))) + 'php', + 'PluginName.php'))) + self.assertTrue( + os.path.exists(os.path.join(plugin_dir, 'core', 'php'))) self.assertTrue(os.path.exists(info_json)) with open(info_json, 'r') as info: info_content = info.read() @@ -95,16 +96,33 @@ def test_choices_with_config(self, side_effect): with self.assertRaises(SystemExit): WizardMenu.start_wizard() plugin_dir = 'plugin-PluginName' - config = os.path.join(plugin_dir, 'plugin_info', 'configuration.php') + config = os.path.join(plugin_dir, 'plugin_info', + 'configuration.php') self.assertTrue(os.path.exists(config)) with open(config, 'r') as config_file: config_content = config_file.read() self.assertIn('{{Name}}', config_content) self.assertIn( - '', + '', config_content) self.assertIn('{{Valid ?}}', config_content) self.assertIn( '', config_content) + + @patch('builtins.input', side_effect=['0', + '0']) + def test_git_extratemplate(self, side_effect): + WizardMenu.git_extratemplate() + self.assertTrue(os.path.exists('plugin-ExtraTemplate')) + shutil.rmtree('plugin-ExtraTemplate') + + @patch('builtins.input', side_effect=['0', + '0']) + def test_git_extratemplate_exists(self, side_effect): + os.system('mkdir plugin-ExtraTemplate') + WizardMenu.git_extratemplate() + self.assertFalse(os.path.exists('plugin-ExtraTemplate/plugin_info')) + shutil.rmtree('plugin-ExtraTemplate') diff --git a/tools.py b/tools.py index b0d4bb3..89aaf14 100755 --- a/tools.py +++ b/tools.py @@ -108,6 +108,7 @@ class PluginName extends eqLogic include_file('desktop', '404', 'php'); die(); } +?> """ wizard_core_class = """ @@ -286,7 +287,7 @@ def sed_replace(regexp, replacement, target_file): :type target_file: str """ sed_replace_pattern = "sed -i'' 's/{}/{}/g' {} 2> /dev/null" - if 'darwin' in sys.platform: + if 'darwin' in sys.platform: # pragma: no cover sed_replace_pattern = "sed -i '' 's/{}/{}/g' {} 2> /dev/null" os.system(sed_replace_pattern.format(regexp, replacement, target_file)) @@ -390,7 +391,7 @@ def write_json_file(file_path, json_data): """ result = False with open(file_path, 'w') as dest: - if sys.version_info[0] < 3: + if sys.version_info[0] < 3: # pragma: no cover dump = json.dumps(json_data, sort_keys=True, indent=4, ensure_ascii=False) dump = dump.encode('utf-8').decode('string-escape') @@ -447,7 +448,7 @@ def is_string(obj): """ str_type = str - if sys.version_info[0] < 3: + if sys.version_info[0] < 3: # pragma: no cover str_type = basestring # pylint: disable=undefined-variable return isinstance(obj, str_type) @@ -461,7 +462,7 @@ def get_user_input(msg): :rtype: str """ result = None - if sys.version_info[0] < 3: + if sys.version_info[0] < 3: # pragma: no cover result = raw_input(msg) # pylint: disable=undefined-variable else: result = input(msg) @@ -641,7 +642,7 @@ def merge_i18n_json(plugin_path, base_json, scan_data): file_path = Jeedom.transform_path_to_i18n_path(plugin_path, data['file_path']) # Décode l'unicode si besoin - if not isinstance(file_path, str): + if not isinstance(file_path, str): # pragma: no cover file_path = file_path.encode('ascii') # Création du dictionnaire vide @@ -672,7 +673,7 @@ def transform_path_to_i18n_path(plugin_path, file_path): os.sep + file_path_striped # En fonction du path fournit, il peut y avoir des doublons normal_path = normal_path.replace('//', '/') - return normal_path #.replace('/', '\/') + return normal_path # .replace('/', '\/') @staticmethod def scan_for_strings(path, result=None): @@ -1048,7 +1049,7 @@ def __init__(self, plugin_path, plugin_name): :type plugin_path: str :type plugin_name: str """ - if sys.version_info[0] < 3: + if sys.version_info[0] < 3: # pragma: no cover super(FeaturesMenu, self).__init__() else: super().__init__() @@ -1796,13 +1797,20 @@ def git_extratemplate(): """Télécharge une copie du plugin ExtraTemplate :params data: Inutilisé """ - sys_return = os.system('git clone ' + config['plugin_template_repo'] + - ' 2> /dev/null') - if sys_return == 0: - IO.print_success('Le plugin plugin-ExtraTemplate a été téléchargé') + if not os.path.exists('plugin-ExtraTemplate'): + sys_return = os.system( + 'git clone ' + config['plugin_template_repo'] + + ' 2> /dev/null') + if sys_return == 0: + IO.print_success( + 'Le plugin plugin-ExtraTemplate a été téléchargé') + else: + IO.print_error('Erreur dans le téléchargement de ' + 'plugin-ExtraTemplate.') else: IO.print_error( 'Le plugin plugin-ExtraTemplate est déjà téléchargé.') + WizardMenu.start_tools(['plugin-ExtraTemplate', 'ExtraTemplate']) @staticmethod @@ -1815,13 +1823,11 @@ def start_tools(plugin_data): root_menu.start() -# Gestion des accents pour python 2 -if sys.version_info[0] < 3: - reload(sys) # pylint: disable=undefined-variable - sys.setdefaultencoding('utf8') # pylint: disable=no-member +def start(): + """ + Point de d'entrée en mode CLI + """ -if __name__ == '__main__': - # Point de d'entrée en mode CLI readed_args = Tools.parse_args(sys.argv) if readed_args is not None: plugins_list = [] @@ -1829,3 +1835,12 @@ def start_tools(plugin_data): plugins_list = Tools.get_plugins_in_dir('.') wizard_menu = WizardMenu(plugins_list) wizard_menu.start() + + +# Gestion des accents pour python 2 +if sys.version_info[0] < 3: # pragma: no cover + reload(sys) # pylint: disable=undefined-variable + sys.setdefaultencoding('utf8') # pylint: disable=no-member + +if __name__ == '__main__': + start() # pragma: no cover

AltStyle によって変換されたページ (->オリジナル) /