[wip] Automatic conversion 2to3

This commit is contained in:
ljf 2018-10-04 17:19:49 +02:00
parent f7802d724b
commit 74ae352221
11 changed files with 68 additions and 67 deletions

View file

@ -5,7 +5,7 @@ import re
import errno import errno
import logging import logging
import yaml import yaml
import cPickle as pickle import pickle as pickle
from time import time from time import time
from collections import OrderedDict from collections import OrderedDict
@ -154,7 +154,7 @@ class PatternParameter(_ExtraParameter):
# Use temporarly utf-8 encoded value # Use temporarly utf-8 encoded value
try: try:
v = unicode(arg_value, 'utf-8') v = str(arg_value, 'utf-8')
except: except:
v = arg_value v = arg_value
@ -240,7 +240,7 @@ class ExtraArgumentParser(object):
if iface in klass.skipped_iface: if iface in klass.skipped_iface:
continue continue
self.extra[klass.name] = klass self.extra[klass.name] = klass
logger.debug('extra parameter classes loaded: %s', self.extra.keys()) logger.debug('extra parameter classes loaded: %s', list(self.extra.keys()))
def validate(self, arg_name, parameters): def validate(self, arg_name, parameters):
""" """
@ -252,7 +252,7 @@ class ExtraArgumentParser(object):
""" """
# Iterate over parameters to validate # Iterate over parameters to validate
for p, v in parameters.items(): for p, v in list(parameters.items()):
klass = self.extra.get(p, None) klass = self.extra.get(p, None)
if not klass: if not klass:
# Remove unknown parameters # Remove unknown parameters
@ -300,9 +300,9 @@ class ExtraArgumentParser(object):
extra_args.update(self._extra_params.get(tid, {})) extra_args.update(self._extra_params.get(tid, {}))
# Iterate over action arguments with extra parameters # Iterate over action arguments with extra parameters
for arg_name, extra_params in extra_args.items(): for arg_name, extra_params in list(extra_args.items()):
# Iterate over available extra parameters # Iterate over available extra parameters
for p, cls in self.extra.items(): for p, cls in list(self.extra.items()):
try: try:
extra_value = extra_params[p] extra_value = extra_params[p]
except KeyError: except KeyError:
@ -593,7 +593,7 @@ class ActionsMap(object):
# * namespace define the top "name", for us it will always be # * namespace define the top "name", for us it will always be
# "yunohost" and there well be only this one # "yunohost" and there well be only this one
# * actionsmap is the actual actionsmap that we care about # * actionsmap is the actual actionsmap that we care about
for namespace, actionsmap in actionsmaps.items(): for namespace, actionsmap in list(actionsmaps.items()):
# Retrieve global parameters # Retrieve global parameters
_global = actionsmap.pop('_global', {}) _global = actionsmap.pop('_global', {})
@ -605,7 +605,7 @@ class ActionsMap(object):
# category_name is stuff like "user", "domain", "hooks"... # category_name is stuff like "user", "domain", "hooks"...
# category_values is the values of this category (like actions) # category_values is the values of this category (like actions)
for category_name, category_values in actionsmap.items(): for category_name, category_values in list(actionsmap.items()):
if "actions" in category_values: if "actions" in category_values:
actions = category_values.pop('actions') actions = category_values.pop('actions')
@ -623,7 +623,7 @@ class ActionsMap(object):
# action_name is like "list" of "domain list" # action_name is like "list" of "domain list"
# action_options are the values # action_options are the values
for action_name, action_options in actions.items(): for action_name, action_options in list(actions.items()):
arguments = action_options.pop('arguments', {}) arguments = action_options.pop('arguments', {})
tid = (namespace, category_name, action_name) tid = (namespace, category_name, action_name)
@ -647,7 +647,7 @@ class ActionsMap(object):
# subcategory_name is like "cert" in "domain cert status" # subcategory_name is like "cert" in "domain cert status"
# subcategory_values is the values of this subcategory (like actions) # subcategory_values is the values of this subcategory (like actions)
for subcategory_name, subcategory_values in subcategories.items(): for subcategory_name, subcategory_values in list(subcategories.items()):
actions = subcategory_values.pop('actions') actions = subcategory_values.pop('actions')
@ -656,7 +656,7 @@ class ActionsMap(object):
# action_name is like "status" of "domain cert status" # action_name is like "status" of "domain cert status"
# action_options are the values # action_options are the values
for action_name, action_options in actions.items(): for action_name, action_options in list(actions.items()):
arguments = action_options.pop('arguments', {}) arguments = action_options.pop('arguments', {})
tid = (namespace, category_name, subcategory_name, action_name) tid = (namespace, category_name, subcategory_name, action_name)

View file

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# TODO: Use Python3 to remove this fix! # TODO: Use Python3 to remove this fix!
from __future__ import absolute_import
import errno import errno
import logging import logging
import random import random
@ -232,7 +232,7 @@ class Authenticator(BaseAuthenticator):
Boolean | MoulinetteError Boolean | MoulinetteError
""" """
for attr, value in value_dict.items(): for attr, value in list(value_dict.items()):
if not self.search(filter=attr + '=' + value): if not self.search(filter=attr + '=' + value):
continue continue
else: else:

View file

@ -185,7 +185,7 @@ class Moulinette18n(object):
self.locale = locale self.locale = locale
self._global.set_locale(locale) self._global.set_locale(locale)
for n in self._namespaces.values(): for n in list(self._namespaces.values()):
n.set_locale(locale) n.set_locale(locale)
def g(self, key, *args, **kwargs): def g(self, key, *args, **kwargs):
@ -234,7 +234,7 @@ class MoulinetteSignals(object):
self.clear_handler(s) self.clear_handler(s)
# Iterate over signals to connect # Iterate over signals to connect
for s, h in kwargs.items(): for s, h in list(kwargs.items()):
self.set_handler(s, h) self.set_handler(s, h)
def set_handler(self, signal, handler): def set_handler(self, signal, handler):
@ -366,7 +366,7 @@ def init_interface(name, kwargs={}, actionsmap={}):
return interface(amap, **kwargs) return interface(amap, **kwargs)
def init_authenticator((vendor, name), kwargs={}): def init_authenticator(xxx_todo_changeme, kwargs={}):
"""Return a new authenticator instance """Return a new authenticator instance
Retrieve the given authenticator vendor and return a new instance of Retrieve the given authenticator vendor and return a new instance of
@ -378,6 +378,7 @@ def init_authenticator((vendor, name), kwargs={}):
- kwargs -- A dict of arguments for the authenticator profile - kwargs -- A dict of arguments for the authenticator profile
""" """
(vendor, name) = xxx_todo_changeme
try: try:
mod = import_module('moulinette.authenticators.%s' % vendor) mod = import_module('moulinette.authenticators.%s' % vendor)
except ImportError: except ImportError:

View file

@ -286,7 +286,7 @@ class BaseActionsMapParser(object):
"for 'authenticator'") "for 'authenticator'")
else: else:
auths = {} auths = {}
for auth_name, auth_conf in auth.items(): for auth_name, auth_conf in list(auth.items()):
# Add authenticator profile as a 3-tuple # Add authenticator profile as a 3-tuple
# (identifier, configuration, parameters) with # (identifier, configuration, parameters) with
# - identifier: the authenticator vendor and its # - identifier: the authenticator vendor and its
@ -518,7 +518,7 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
def dequeue_callbacks(self, namespace): def dequeue_callbacks(self, namespace):
queue = self._get_callbacks_queue(namespace, False) queue = self._get_callbacks_queue(namespace, False)
for _i in xrange(len(queue)): for _i in range(len(queue)):
c, v = queue.popleft() c, v = queue.popleft()
# FIXME: break dequeue if callback returns # FIXME: break dequeue if callback returns
c.execute(namespace, v) c.execute(namespace, v)
@ -539,7 +539,7 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
return queue return queue
def add_arguments(self, arguments, extraparser, format_arg_names=None, validate_extra=True): def add_arguments(self, arguments, extraparser, format_arg_names=None, validate_extra=True):
for argument_name, argument_options in arguments.items(): for argument_name, argument_options in list(arguments.items()):
# will adapt arguments name for cli or api context # will adapt arguments name for cli or api context
names = format_arg_names(str(argument_name), names = format_arg_names(str(argument_name),
argument_options.pop('full', None)) argument_options.pop('full', None))
@ -600,11 +600,11 @@ class ExtendedArgumentParser(argparse.ArgumentParser):
subcategories_subparser = copy.copy(action_group._group_actions[0]) subcategories_subparser = copy.copy(action_group._group_actions[0])
# Filter "action"-type and "subcategory"-type commands # Filter "action"-type and "subcategory"-type commands
actions_subparser.choices = OrderedDict([(k, v) for k, v in actions_subparser.choices.items() if v.type == "action"]) actions_subparser.choices = OrderedDict([(k, v) for k, v in list(actions_subparser.choices.items()) if v.type == "action"])
subcategories_subparser.choices = OrderedDict([(k, v) for k, v in subcategories_subparser.choices.items() if v.type == "subcategory"]) subcategories_subparser.choices = OrderedDict([(k, v) for k, v in list(subcategories_subparser.choices.items()) if v.type == "subcategory"])
actions_choices = actions_subparser.choices.keys() actions_choices = list(actions_subparser.choices.keys())
subcategories_choices = subcategories_subparser.choices.keys() subcategories_choices = list(subcategories_subparser.choices.keys())
actions_subparser._choices_actions = [c for c in choice_actions if c.dest in actions_choices] actions_subparser._choices_actions = [c for c in choice_actions if c.dest in actions_choices]
subcategories_subparser._choices_actions = [c for c in choice_actions if c.dest in subcategories_choices] subcategories_subparser._choices_actions = [c for c in choice_actions if c.dest in subcategories_choices]

View file

@ -82,7 +82,7 @@ class _HTTPArgumentParser(object):
return self._parser.get_default(dest) return self._parser.get_default(dest)
def add_arguments(self, arguments, extraparser, format_arg_names=None, validate_extra=True): def add_arguments(self, arguments, extraparser, format_arg_names=None, validate_extra=True):
for argument_name, argument_options in arguments.items(): for argument_name, argument_options in list(arguments.items()):
# will adapt arguments name for cli or api context # will adapt arguments name for cli or api context
names = format_arg_names(str(argument_name), names = format_arg_names(str(argument_name),
argument_options.pop('full', None)) argument_options.pop('full', None))
@ -149,7 +149,7 @@ class _HTTPArgumentParser(object):
arg_strings = append(arg_strings, args[dest]) arg_strings = append(arg_strings, args[dest])
# Iterate over optional arguments # Iterate over optional arguments
for dest, opt in self._optional.items(): for dest, opt in list(self._optional.items()):
if dest in args: if dest in args:
arg_strings = append(arg_strings, args[dest], opt[0]) arg_strings = append(arg_strings, args[dest], opt[0])
@ -262,7 +262,7 @@ class _ActionsMapPlugin(object):
for a in args: for a in args:
params[a] = True params[a] = True
# Append other request params # Append other request params
for k, v in request.params.dict.items(): for k, v in list(request.params.dict.items()):
v = _format(v) v = _format(v)
try: try:
curr_v = params[k] curr_v = params[k]
@ -558,7 +558,7 @@ class ActionsMapParser(BaseActionsMapParser):
@property @property
def routes(self): def routes(self):
"""Get current routes""" """Get current routes"""
return self._parsers.keys() return list(self._parsers.keys())
# Implement virtual properties # Implement virtual properties
@ -733,7 +733,7 @@ class Interface(BaseInterface):
# Append additional routes # Append additional routes
# TODO: Add optional authentication to those routes? # TODO: Add optional authentication to those routes?
for (m, p), c in routes.items(): for (m, p), c in list(routes.items()):
app.route(p, method=m, callback=c, skip=['actionsmap']) app.route(p, method=m, callback=c, skip=['actionsmap'])
self._app = app self._app = app

View file

@ -85,11 +85,11 @@ def plain_print_dict(d, depth=0):
for v in d: for v in d:
plain_print_dict(v, depth + 1) plain_print_dict(v, depth + 1)
elif isinstance(d, dict): elif isinstance(d, dict):
for k, v in d.items(): for k, v in list(d.items()):
print("{}{}".format("#" * (depth + 1), k)) print(("{}{}".format("#" * (depth + 1), k)))
plain_print_dict(v, depth + 1) plain_print_dict(v, depth + 1)
else: else:
if isinstance(d, unicode): if isinstance(d, str):
d = d.encode('utf-8') d = d.encode('utf-8')
print(d) print(d)
@ -104,7 +104,7 @@ def pretty_print_dict(d, depth=0):
- depth -- The recursive depth of the dictionary - depth -- The recursive depth of the dictionary
""" """
keys = d.keys() keys = list(d.keys())
if not isinstance(d, OrderedDict): if not isinstance(d, OrderedDict):
keys = sorted(keys) keys = sorted(keys)
for k in keys: for k in keys:
@ -115,23 +115,23 @@ def pretty_print_dict(d, depth=0):
if isinstance(v, list) and len(v) == 1: if isinstance(v, list) and len(v) == 1:
v = v[0] v = v[0]
if isinstance(v, dict): if isinstance(v, dict):
print("{:s}{}: ".format(" " * depth, k)) print(("{:s}{}: ".format(" " * depth, k)))
pretty_print_dict(v, depth + 1) pretty_print_dict(v, depth + 1)
elif isinstance(v, list): elif isinstance(v, list):
print("{:s}{}: ".format(" " * depth, k)) print(("{:s}{}: ".format(" " * depth, k)))
for key, value in enumerate(v): for key, value in enumerate(v):
if isinstance(value, tuple): if isinstance(value, tuple):
pretty_print_dict({value[0]: value[1]}, depth + 1) pretty_print_dict({value[0]: value[1]}, depth + 1)
elif isinstance(value, dict): elif isinstance(value, dict):
pretty_print_dict({key: value}, depth + 1) pretty_print_dict({key: value}, depth + 1)
else: else:
if isinstance(value, unicode): if isinstance(value, str):
value = value.encode('utf-8') value = value.encode('utf-8')
print("{:s}- {}".format(" " * (depth + 1), value)) print(("{:s}- {}".format(" " * (depth + 1), value)))
else: else:
if isinstance(v, unicode): if isinstance(v, str):
v = v.encode('utf-8') v = v.encode('utf-8')
print("{:s}{}: {}".format(" " * depth, k, v)) print(("{:s}{}: {}".format(" " * depth, k, v)))
def get_locale(): def get_locale():
@ -315,7 +315,7 @@ class ActionsMapParser(BaseActionsMapParser):
deprecated_alias=deprecated_alias) deprecated_alias=deprecated_alias)
def add_global_arguments(self, arguments): def add_global_arguments(self, arguments):
for argument_name, argument_options in arguments.items(): for argument_name, argument_options in list(arguments.items()):
# will adapt arguments name for cli or api context # will adapt arguments name for cli or api context
names = self.format_arg_names(str(argument_name), names = self.format_arg_names(str(argument_name),
argument_options.pop('full', None)) argument_options.pop('full', None))
@ -399,7 +399,7 @@ class Interface(BaseInterface):
if output_as == 'json': if output_as == 'json':
import json import json
from moulinette.utils.serialize import JSONExtendedEncoder from moulinette.utils.serialize import JSONExtendedEncoder
print(json.dumps(ret, cls=JSONExtendedEncoder)) print((json.dumps(ret, cls=JSONExtendedEncoder)))
else: else:
plain_print_dict(ret) plain_print_dict(ret)
elif isinstance(ret, dict): elif isinstance(ret, dict):
@ -433,7 +433,7 @@ class Interface(BaseInterface):
prompt = lambda m: getpass.getpass(colorize(m18n.g('colon', m), prompt = lambda m: getpass.getpass(colorize(m18n.g('colon', m),
color)) color))
else: else:
prompt = lambda m: raw_input(colorize(m18n.g('colon', m), color)) prompt = lambda m: input(colorize(m18n.g('colon', m), color))
value = prompt(message) value = prompt(message)
if confirm: if confirm:
@ -449,13 +449,13 @@ class Interface(BaseInterface):
Handle the core.MoulinetteSignals.display signal. Handle the core.MoulinetteSignals.display signal.
""" """
if isinstance(message, unicode): if isinstance(message, str):
message = message.encode('utf-8') message = message.encode('utf-8')
if style == 'success': if style == 'success':
print('{} {}'.format(colorize(m18n.g('success'), 'green'), message)) print(('{} {}'.format(colorize(m18n.g('success'), 'green'), message)))
elif style == 'warning': elif style == 'warning':
print('{} {}'.format(colorize(m18n.g('warning'), 'yellow'), message)) print(('{} {}'.format(colorize(m18n.g('warning'), 'yellow'), message)))
elif style == 'error': elif style == 'error':
print('{} {}'.format(colorize(m18n.g('error'), 'red'), message)) print(('{} {}'.format(colorize(m18n.g('error'), 'red'), message)))
else: else:
print(message) print(message)

View file

@ -20,7 +20,7 @@ def read_file(file_path):
Keyword argument: Keyword argument:
file_path -- Path to the text file file_path -- Path to the text file
""" """
assert isinstance(file_path, basestring) assert isinstance(file_path, str)
# Check file exists # Check file exists
if not os.path.isfile(file_path): if not os.path.isfile(file_path):
@ -98,14 +98,14 @@ def write_to_file(file_path, data, file_mode="w"):
file_mode -- Mode used when writing the file. Option meant to be used file_mode -- Mode used when writing the file. Option meant to be used
by append_to_file to avoid duplicating the code of this function. by append_to_file to avoid duplicating the code of this function.
""" """
assert isinstance(data, basestring) or isinstance(data, list) assert isinstance(data, str) or isinstance(data, list)
assert not os.path.isdir(file_path) assert not os.path.isdir(file_path)
assert os.path.isdir(os.path.dirname(file_path)) assert os.path.isdir(os.path.dirname(file_path))
# If data is a list, check elements are strings and build a single string # If data is a list, check elements are strings and build a single string
if not isinstance(data, basestring): if not isinstance(data, str):
for element in data: for element in data:
assert isinstance(element, basestring) assert isinstance(element, str)
data = '\n'.join(data) data = '\n'.join(data)
try: try:
@ -143,7 +143,7 @@ def write_to_json(file_path, data):
""" """
# Assumptions # Assumptions
assert isinstance(file_path, basestring) assert isinstance(file_path, str)
assert isinstance(data, dict) or isinstance(data, list) assert isinstance(data, dict) or isinstance(data, list)
assert not os.path.isdir(file_path) assert not os.path.isdir(file_path)
assert os.path.isdir(os.path.dirname(file_path)) assert os.path.isdir(os.path.dirname(file_path))
@ -162,7 +162,7 @@ def write_to_json(file_path, data):
file=file_path, error=str(e))) file=file_path, error=str(e)))
def mkdir(path, mode=0777, parents=False, uid=None, gid=None, force=False): def mkdir(path, mode=0o777, parents=False, uid=None, gid=None, force=False):
"""Create a directory with optional features """Create a directory with optional features
Create a directory and optionaly set its permissions to mode and its Create a directory and optionaly set its permissions to mode and its
@ -214,7 +214,7 @@ def chown(path, uid=None, gid=None, recursive=False):
raise ValueError("either uid or gid argument is required") raise ValueError("either uid or gid argument is required")
# Retrieve uid/gid # Retrieve uid/gid
if isinstance(uid, basestring): if isinstance(uid, str):
try: try:
uid = getpwnam(uid).pw_uid uid = getpwnam(uid).pw_uid
except KeyError: except KeyError:
@ -222,7 +222,7 @@ def chown(path, uid=None, gid=None, recursive=False):
m18n.g('unknown_user', user=uid)) m18n.g('unknown_user', user=uid))
elif uid is None: elif uid is None:
uid = -1 uid = -1
if isinstance(gid, basestring): if isinstance(gid, str):
try: try:
gid = grp.getgrnam(gid).gr_gid gid = grp.getgrnam(gid).gr_gid
except KeyError: except KeyError:

View file

@ -63,7 +63,7 @@ def call_async_output(args, callback, **kwargs):
if "stdinfo" in kwargs and kwargs["stdinfo"] != None: if "stdinfo" in kwargs and kwargs["stdinfo"] != None:
assert len(callback) == 3 assert len(callback) == 3
stdinfo = kwargs.pop("stdinfo") stdinfo = kwargs.pop("stdinfo")
os.mkfifo(stdinfo, 0600) os.mkfifo(stdinfo, 0o600)
# Open stdinfo for reading (in a nonblocking way, i.e. even # Open stdinfo for reading (in a nonblocking way, i.e. even
# if command does not write in the stdinfo pipe...) # if command does not write in the stdinfo pipe...)
stdinfo_f = os.open(stdinfo, os.O_RDONLY|os.O_NONBLOCK) stdinfo_f = os.open(stdinfo, os.O_RDONLY|os.O_NONBLOCK)

View file

@ -29,7 +29,7 @@ old_translate = moulinette.core.Translator.translate
def new_translate(self, key, *args, **kwargs): def new_translate(self, key, *args, **kwargs):
if key not in self._translations[self.default_locale].keys(): if key not in list(self._translations[self.default_locale].keys()):
raise KeyError("Unable to retrieve key %s for default locale !" % key) raise KeyError("Unable to retrieve key %s for default locale !" % key)
return old_translate(self, key, *args, **kwargs) return old_translate(self, key, *args, **kwargs)

View file

@ -72,7 +72,7 @@ def test_read_file_badpermissions():
def test_read_json(): def test_read_json():
content = read_json(TMP_TEST_JSON) content = read_json(TMP_TEST_JSON)
assert "foo" in content.keys() assert "foo" in list(content.keys())
assert content["foo"] == "bar" assert content["foo"] == "bar"
@ -162,8 +162,8 @@ def text_write_dict_to_json():
dummy_dict = {"foo": 42, "bar": ["a", "b", "c"]} dummy_dict = {"foo": 42, "bar": ["a", "b", "c"]}
write_to_json(TMP_TEST_FILE, dummy_dict) write_to_json(TMP_TEST_FILE, dummy_dict)
j = read_json(TMP_TEST_FILE) j = read_json(TMP_TEST_FILE)
assert "foo" in j.keys() assert "foo" in list(j.keys())
assert "bar" in j.keys() assert "bar" in list(j.keys())
assert j["foo"] == 42 assert j["foo"] == 42
assert j["bar"] == ["a", "b", "c"] assert j["bar"] == ["a", "b", "c"]
assert read_file(TMP_TEST_FILE) == "foo\nbar\nyolo\nswag" assert read_file(TMP_TEST_FILE) == "foo\nbar\nyolo\nswag"
@ -239,13 +239,13 @@ def test_setpermissions_file():
assert get_permissions(TMP_TEST_FILE) == ("root", "root", "700") assert get_permissions(TMP_TEST_FILE) == ("root", "root", "700")
# Change the permissions # Change the permissions
set_permissions(TMP_TEST_FILE, NON_ROOT_USER, NON_ROOT_GROUP, 0111) set_permissions(TMP_TEST_FILE, NON_ROOT_USER, NON_ROOT_GROUP, 0o111)
# Check the permissions got changed # Check the permissions got changed
assert get_permissions(TMP_TEST_FILE) == (NON_ROOT_USER, NON_ROOT_GROUP, "111") assert get_permissions(TMP_TEST_FILE) == (NON_ROOT_USER, NON_ROOT_GROUP, "111")
# Change the permissions again # Change the permissions again
set_permissions(TMP_TEST_FILE, "root", "root", 0777) set_permissions(TMP_TEST_FILE, "root", "root", 0o777)
# Check the permissions got changed # Check the permissions got changed
assert get_permissions(TMP_TEST_FILE) == ("root", "root", "777") assert get_permissions(TMP_TEST_FILE) == ("root", "root", "777")
@ -257,13 +257,13 @@ def test_setpermissions_directory():
assert get_permissions(TMP_TEST_DIR) == ("root", "root", "755") assert get_permissions(TMP_TEST_DIR) == ("root", "root", "755")
# Change the permissions # Change the permissions
set_permissions(TMP_TEST_DIR, NON_ROOT_USER, NON_ROOT_GROUP, 0111) set_permissions(TMP_TEST_DIR, NON_ROOT_USER, NON_ROOT_GROUP, 0o111)
# Check the permissions got changed # Check the permissions got changed
assert get_permissions(TMP_TEST_DIR) == (NON_ROOT_USER, NON_ROOT_GROUP, "111") assert get_permissions(TMP_TEST_DIR) == (NON_ROOT_USER, NON_ROOT_GROUP, "111")
# Change the permissions again # Change the permissions again
set_permissions(TMP_TEST_DIR, "root", "root", 0777) set_permissions(TMP_TEST_DIR, "root", "root", 0o777)
# Check the permissions got changed # Check the permissions got changed
assert get_permissions(TMP_TEST_DIR) == ("root", "root", "777") assert get_permissions(TMP_TEST_DIR) == ("root", "root", "777")
@ -274,22 +274,22 @@ def test_setpermissions_permissiondenied():
switch_to_non_root_user() switch_to_non_root_user()
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
set_permissions(TMP_TEST_FILE, NON_ROOT_USER, NON_ROOT_GROUP, 0111) set_permissions(TMP_TEST_FILE, NON_ROOT_USER, NON_ROOT_GROUP, 0o111)
def test_setpermissions_badfile(): def test_setpermissions_badfile():
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
set_permissions("/foo/bar/yolo", NON_ROOT_USER, NON_ROOT_GROUP, 0111) set_permissions("/foo/bar/yolo", NON_ROOT_USER, NON_ROOT_GROUP, 0o111)
def test_setpermissions_baduser(): def test_setpermissions_baduser():
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
set_permissions(TMP_TEST_FILE, "foo", NON_ROOT_GROUP, 0111) set_permissions(TMP_TEST_FILE, "foo", NON_ROOT_GROUP, 0o111)
def test_setpermissions_badgroup(): def test_setpermissions_badgroup():
with pytest.raises(MoulinetteError): with pytest.raises(MoulinetteError):
set_permissions(TMP_TEST_FILE, NON_ROOT_USER, "foo", 0111) set_permissions(TMP_TEST_FILE, NON_ROOT_USER, "foo", 0o111)

View file

@ -77,7 +77,7 @@ def test_download_json():
fetched_json = download_json(TEST_URL) fetched_json = download_json(TEST_URL)
assert "foo" in fetched_json.keys() assert "foo" in list(fetched_json.keys())
assert fetched_json["foo"] == "bar" assert fetched_json["foo"] == "bar"