[microdecision] Remove unused imports + make pep8 happy

This commit is contained in:
Alexandre Aubin 2017-07-24 14:35:58 -04:00
parent 7e1712037f
commit 51ea069801
7 changed files with 25 additions and 19 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)