diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 3b2e69bd..01e57bcc 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -502,8 +502,8 @@ class _ExtendedSubParsersAction(argparse._SubParsersAction): class ExtendedArgumentParser(argparse.ArgumentParser): def __init__(self, *args, **kwargs): - super(ExtendedArgumentParser, self).__init__( - formatter_class=PositionalsFirstHelpFormatter, *args, **kwargs) + super(ExtendedArgumentParser, self).__init__(formatter_class=PositionalsFirstHelpFormatter, + *args, **kwargs) # Register additional actions self.register('action', 'callback', _CallbackAction) diff --git a/moulinette/utils/filesystem.py b/moulinette/utils/filesystem.py index 737bdd18..bbea872c 100644 --- a/moulinette/utils/filesystem.py +++ b/moulinette/utils/filesystem.py @@ -9,6 +9,7 @@ from moulinette.core import MoulinetteError # Files & directories -------------------------------------------------- + def read_file(file_path): """ Read a regular text file @@ -94,6 +95,7 @@ def write_to_file(file_path, data, file_mode="w"): m18n.g('error_writing_file', file=file_path, error=str(e))) + def append_to_file(file_path, data): """ Append a single string or a list of string to a text file. diff --git a/moulinette/utils/process.py b/moulinette/utils/process.py index 6475f056..e48f27a9 100644 --- a/moulinette/utils/process.py +++ b/moulinette/utils/process.py @@ -106,7 +106,7 @@ def call_async_output(args, callback, **kwargs): # Call multiple commands ----------------------------------------------- def run_commands(cmds, callback=None, separate_stderr=False, shell=True, - **kwargs): + **kwargs): """Run multiple commands with error management Run a list of commands and allow to manage how to treat errors either diff --git a/moulinette/utils/tests/conftest.py b/moulinette/utils/tests/conftest.py index 2bc5b2b5..515804ef 100644 --- a/moulinette/utils/tests/conftest.py +++ b/moulinette/utils/tests/conftest.py @@ -9,9 +9,13 @@ sys.path.append("..") old_init = moulinette.core.Moulinette18n.__init__ + + def monkey_path_i18n_init(self, package, default_locale="en"): old_init(self, package, default_locale) self.load_namespace("moulinette") + + moulinette.core.Moulinette18n.__init__ = monkey_path_i18n_init @@ -21,16 +25,23 @@ moulinette.core.Moulinette18n.__init__ = monkey_path_i18n_init old_translate = moulinette.core.Translator.translate + + def new_translate(self, key, *args, **kwargs): if key not in self._translations[self.default_locale].keys(): raise KeyError("Unable to retrieve key %s for default locale !" % key) return old_translate(self, key, *args, **kwargs) + + moulinette.core.Translator.translate = new_translate + def new_m18nn(self, key, *args, **kwargs): return self._global.translate(key, *args, **kwargs) + + moulinette.core.Moulinette18n.g = new_m18nn @@ -93,4 +104,3 @@ def pytest_cmdline_main(config): # Initialize moulinette moulinette.init(logging_config=logging, _from_source=False) - diff --git a/moulinette/utils/tests/test_filesystem.py b/moulinette/utils/tests/test_filesystem.py index c79bee40..bf4b1345 100644 --- a/moulinette/utils/tests/test_filesystem.py +++ b/moulinette/utils/tests/test_filesystem.py @@ -3,16 +3,14 @@ import os import pwd import pytest -import requests -import requests_mock # Moulinette specific from moulinette.core import MoulinetteError -from moulinette.utils.filesystem import ( - read_file, read_json, - write_to_file, append_to_file, write_to_json, - rm, - chmod, chown) +from moulinette.utils.filesystem import (read_file, read_json, + write_to_file, append_to_file, + write_to_json, + rm, + chmod, chown) # We define a dummy context with test folders and files @@ -61,7 +59,7 @@ def test_read_file(): def test_read_file_badfile(): with pytest.raises(MoulinetteError): - read_file(TMP_TEST_FILE+"nope") + read_file(TMP_TEST_FILE + "nope") def test_read_file_badpermissions(): @@ -295,5 +293,3 @@ def test_setpermissions_badgroup(): with pytest.raises(MoulinetteError): set_permissions(TMP_TEST_FILE, NON_ROOT_USER, "foo", 0111) - - diff --git a/moulinette/utils/tests/test_network.py b/moulinette/utils/tests/test_network.py index 588f7a3c..fd7add78 100644 --- a/moulinette/utils/tests/test_network.py +++ b/moulinette/utils/tests/test_network.py @@ -1,7 +1,5 @@ # General python lib -import os -import pwd import pytest import requests import requests_mock @@ -14,10 +12,12 @@ from moulinette.utils.network import download_text, download_json TEST_URL = "https://some.test.url/yolo.txt" + def setup_function(function): pass + def teardown_function(function): pass @@ -88,5 +88,3 @@ def test_download_json_badjson(): with pytest.raises(MoulinetteError): download_json(TEST_URL) - - diff --git a/moulinette/utils/tests/test_process.py b/moulinette/utils/tests/test_process.py index a37a0f3b..da77f80d 100644 --- a/moulinette/utils/tests/test_process.py +++ b/moulinette/utils/tests/test_process.py @@ -39,6 +39,7 @@ def switch_to_non_root_user(): # Test run shell commands # ############################################################################### + def test_run_shell_command_list(): commands = ["rm -f %s" % TMP_TEST_FILE] @@ -63,4 +64,3 @@ def test_run_shell_command_badpermissions(): switch_to_non_root_user() with pytest.raises(CalledProcessError): run_commands(commands) -