Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring: enable pylint checks for R0801 #1803

Merged
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions common/encfstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,8 @@ class EncFS_SSH(EncFS_mount):
rsync will then sync the encrypted view on / to the remote path
"""
def __init__(self, cfg = None, profile_id = None, mode = None, parent = None,*args, **kwargs):
self.config = cfg
if self.config is None:
self.config = config.Config()
self.profile_id = profile_id
if self.profile_id is None:
self.profile_id = self.config.currentProfile()
self.config = cfg or config.Config()
buhtz marked this conversation as resolved.
Show resolved Hide resolved
self.profile_id = profile_id or self.config.currentProfile()
self.mode = mode
if self.mode is None:
self.mode = self.config.snapshotsMode(self.profile_id)
Expand Down
28 changes: 9 additions & 19 deletions common/mount.py
buhtz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,18 @@ def postUmountCheck(self):
return True

"""
import getpass
import json
import os
import subprocess
import json
import getpass
from zlib import crc32
from time import sleep
from zlib import crc32

import config
import logger
import tools
import password
from exceptions import MountException, HashCollision
import tools
from exceptions import HashCollision, MountException


class Mount(object):
Expand Down Expand Up @@ -143,14 +143,8 @@ def __init__(self,
profile_id = None,
tmp_mount = False,
parent = None):
self.config = cfg
if self.config is None:
self.config = config.Config()

self.profile_id = profile_id
if self.profile_id is None:
self.profile_id = self.config.currentProfile()

self.config = cfg or config.Config()
self.profile_id = profile_id or self.config.currentProfile()
self.tmp_mount = tmp_mount
self.parent = parent

Expand Down Expand Up @@ -437,13 +431,9 @@ def __init__(self,
self.mountproc = None
self.symlink_subfolder = None

self.config = cfg
if self.config is None:
self.config = config.Config()
self.config = cfg or config.Config()

self.profile_id = profile_id
if self.profile_id is None:
self.profile_id = self.config.currentProfile()
self.profile_id = profile_id or self.config.currentProfile()

self.tmp_mount = tmp_mount
self.hash_id = hash_id
Expand Down
13 changes: 13 additions & 0 deletions common/test/constants.py
buhtz marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
This file contains constants that are used in the test files.
"""
import grp
import os
import pwd

CURRENTUID = os.geteuid()
CURRENTUSER = pwd.getpwuid(CURRENTUID).pw_name
CURRENTGID = os.getegid()
CURRENTGROUP = grp.getgrgid(CURRENTGID).gr_name
CURRENTUID = os.geteuid()
CURRENTGID = os.getegid()
9 changes: 5 additions & 4 deletions common/test/test_applicationinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# with this program; if not, write to the Free Software Foundation,Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import subprocess
import os
import sys
from unittest.mock import patch
from threading import Thread

from test import generic

sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
Expand Down Expand Up @@ -70,9 +70,10 @@ def _createProcess(self):

def _killProcess(self):
if self.subproc:
self.subproc.kill()
self.subproc.wait()
self.subproc = None
subproc = self.subproc
subproc.kill()
subproc.wait()
self.subproc = None

def test_create_and_remove_pid_file(self):
# create pid file
Expand Down
71 changes: 47 additions & 24 deletions common/test/test_config_crontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@

See also test_schedule.py for low-level-Cron-behavior implemented in schedule
module."""
import unittest
import pyfakefs.fake_filesystem_unittest as pyfakefs_ut
import sys
import inspect
import os
import sys
import tempfile
import inspect
import unittest
from pathlib import Path
from unittest import mock

import pyfakefs.fake_filesystem_unittest as pyfakefs_ut

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import config


Expand Down Expand Up @@ -80,26 +83,46 @@ def setUp(self):

def _create_config_file(self, parent_path):
"""Minimal config file"""
cfg_content = inspect.cleandoc('''
config.version=6
profile1.snapshots.include.1.type=0
profile1.snapshots.include.1.value=rootpath/source
profile1.snapshots.include.size=1
profile1.snapshots.no_on_battery=false
profile1.snapshots.notify.enabled=true
profile1.snapshots.path=rootpath/destination
profile1.snapshots.path.host=test-host
profile1.snapshots.path.profile=1
profile1.snapshots.path.user=test-user
profile1.snapshots.preserve_acl=false
profile1.snapshots.preserve_xattr=false
profile1.snapshots.remove_old_snapshots.enabled=true
profile1.snapshots.remove_old_snapshots.unit=80
profile1.snapshots.remove_old_snapshots.value=10
profile1.snapshots.rsync_options.enabled=false
profile1.snapshots.rsync_options.value=
profiles.version=1
''')
config_data = """
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain me the advantage of this solution compared to the previous one?

config.version={config_version}
profile1.snapshots.include.1.type={snapshot_type}
profile1.snapshots.include.1.value={snapshot_value}
profile1.snapshots.include.size={snapshot_size}
profile1.snapshots.no_on_battery={no_on_battery}
profile1.snapshots.notify.enabled={notify_enabled}
profile1.snapshots.path={snapshot_path}
profile1.snapshots.path.host={snapshot_host}
profile1.snapshots.path.profile={snapshot_profile}
profile1.snapshots.path.user={snapshot_user}
profile1.snapshots.preserve_acl={preserve_acl}
profile1.snapshots.preserve_xattr={preserve_xattr}
profile1.snapshots.remove_old_snapshots.enabled={remove_old_snapshots_enabled}
profile1.snapshots.remove_old_snapshots.unit={remove_old_snapshots_unit}
profile1.snapshots.remove_old_snapshots.value={remove_old_snapshots_value}
profile1.snapshots.rsync_options.enabled={rsync_options_enabled}
profile1.snapshots.rsync_options.value={rsync_options_value}
profiles.version={profiles_version}
""".format(
config_version=6,
snapshot_type=0,
snapshot_value='rootpath/source',
snapshot_size=1,
no_on_battery='false',
notify_enabled='true',
snapshot_path='rootpath/destination',
snapshot_host='test-host',
snapshot_profile=1,
snapshot_user='test-user',
preserve_acl='false',
preserve_xattr='false',
remove_old_snapshots_enabled='true',
remove_old_snapshots_unit=80,
remove_old_snapshots_value=10,
rsync_options_enabled='false',
rsync_options_value='',
profiles_version=1
)
cfg_content = inspect.cleandoc(config_data)

# config file location
config_fp = parent_path / 'config_path' / 'config'
Expand Down
3 changes: 2 additions & 1 deletion common/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ def test_with_pylint(self):
'R0201', # no-self-use
'R0202', # no-classmethod-decorator
'R0203', # no-staticmethod-decorator
'R0801', # duplicate-code

# Enable asap. This list is a selection of existing (not all!)
# problems currently existing in the BIT code base. Quite easy to fix
# because their count is low.
# 'R0801', # duplicate-code
# 'W0237', # arguments-renamed
# 'W0221', # arguments-differ
# 'W0603', # global-statement
]
Expand Down
68 changes: 44 additions & 24 deletions common/test/test_plugin_usercallback.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import sys
import inspect
import tempfile
from pathlib import Path
import stat
import io
import unittest
import unittest.mock as mock
from contextlib import redirect_stdout, redirect_stderr
from ast import literal_eval
from contextlib import redirect_stderr, redirect_stdout
from pathlib import Path

# This workaround will become obsolet when migrating to src-layout
sys.path.append(str(Path(__file__).parent))
sys.path.append(str(Path(__file__).parent / 'plugins'))

import pluginmanager
from config import Config
from snapshots import Snapshots
Expand Down Expand Up @@ -206,26 +205,47 @@ def _create_source_and_destination_folders(cls, parent_path):

@classmethod
def _create_config_file(cls, parent_path):
cfg_content = inspect.cleandoc('''
config.version=6
profile1.snapshots.include.1.type=0
profile1.snapshots.include.1.value={rootpath}/{source}
profile1.snapshots.include.size=1
profile1.snapshots.no_on_battery=false
profile1.snapshots.notify.enabled=true
profile1.snapshots.path={rootpath}/{destination}
profile1.snapshots.path.host=test-host
profile1.snapshots.path.profile=1
profile1.snapshots.path.user=test-user
profile1.snapshots.preserve_acl=false
profile1.snapshots.preserve_xattr=false
profile1.snapshots.remove_old_snapshots.enabled=true
profile1.snapshots.remove_old_snapshots.unit=80
profile1.snapshots.remove_old_snapshots.value=10
profile1.snapshots.rsync_options.enabled=false
profile1.snapshots.rsync_options.value=
profiles.version=1
''')
"""Minimal config file"""
config_data = """
config.version={config_version}
profile1.snapshots.include.1.type={snapshot_type}
profile1.snapshots.include.1.value={snapshot_value}
profile1.snapshots.include.size={snapshot_size}
profile1.snapshots.no_on_battery={no_on_battery}
profile1.snapshots.notify.enabled={notify_enabled}
profile1.snapshots.path={snapshot_path}
profile1.snapshots.path.host={snapshot_host}
profile1.snapshots.path.profile={snapshot_profile}
profile1.snapshots.path.user={snapshot_user}
profile1.snapshots.preserve_acl={preserve_acl}
profile1.snapshots.preserve_xattr={preserve_xattr}
profile1.snapshots.remove_old_snapshots.enabled={remove_old_snapshots_enabled}
profile1.snapshots.remove_old_snapshots.unit={remove_old_snapshots_unit}
profile1.snapshots.remove_old_snapshots.value={remove_old_snapshots_value}
profile1.snapshots.rsync_options.enabled={rsync_options_enabled}
profile1.snapshots.rsync_options.value={rsync_options_value}
profiles.version={profiles_version}
""".format(
config_version=6,
snapshot_type=0,
snapshot_value=f'{parent_path}/{cls.NAME_SOURCE}',
snapshot_size=1,
no_on_battery='false',
notify_enabled='true',
snapshot_path=f'{parent_path}/{cls.NAME_DESTINATION}',
snapshot_host='test-host',
snapshot_profile=1,
snapshot_user='test-user',
preserve_acl='false',
preserve_xattr='false',
remove_old_snapshots_enabled='true',
remove_old_snapshots_unit=80,
remove_old_snapshots_value=10,
rsync_options_enabled='false',
rsync_options_value='',
profiles_version=1
)
cfg_content = inspect.cleandoc(config_data)

cfg_content = cfg_content.format(
rootpath=parent_path,
Expand Down
9 changes: 2 additions & 7 deletions common/test/test_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,15 @@
import os
import sys
import unittest
import pwd
import grp
import stat
from tempfile import TemporaryDirectory

from test import generic
from test.constants import CURRENTUSER, CURRENTGROUP

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import mount

CURRENTUID = os.geteuid()
CURRENTUSER = pwd.getpwuid(CURRENTUID).pw_name

CURRENTGID = os.getegid()
CURRENTGROUP = grp.getgrgid(CURRENTGID).gr_name

class RestoreTestCase(generic.SnapshotsWithSidTestCase):
def setUp(self):
Expand Down
6 changes: 1 addition & 5 deletions common/test/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from datetime import date, datetime
from tempfile import TemporaryDirectory
from test import generic
from test.constants import CURRENTUSER, CURRENTGROUP, CURRENTGID, CURRENTUID

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import logger
Expand All @@ -38,11 +39,6 @@
import tools
import mount

CURRENTUID = os.geteuid()
CURRENTUSER = pwd.getpwuid(CURRENTUID).pw_name

CURRENTGID = os.getegid()
CURRENTGROUP = grp.getgrgid(CURRENTGID).gr_name

# all groups the current user is member in
GROUPS = [i.gr_name for i in grp.getgrall() if CURRENTUSER in i.gr_mem]
Expand Down
7 changes: 3 additions & 4 deletions common/test/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
import signal
from unittest.mock import patch
from copy import deepcopy
from unittest.mock import patch
from tempfile import NamedTemporaryFile, TemporaryDirectory
from datetime import datetime
from test import generic
from time import sleep
import pyfakefs.fake_filesystem_unittest as pyfakefs_ut
from test import generic

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import tools
Expand Down Expand Up @@ -98,7 +97,7 @@ def _kill_process(self):
if self.subproc:
self.subproc.kill()
self.subproc.wait()
self.subproc = None
self.subproc = None

def test_sharePath(self):
share = tools.sharePath()
Expand Down
7 changes: 2 additions & 5 deletions qt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import languagedialog
import messagebox
from aboutdlg import AboutDlg
import qttools


class MainWindow(QMainWindow):
Expand Down Expand Up @@ -878,13 +879,9 @@ def updateProfiles(self):

self.comboProfiles.clear()

qttools.update_combo_profiles(self.config, self.comboProfiles, self.config.currentProfile())
profiles = self.config.profilesSortedByName()

for profile_id in profiles:
self.comboProfiles.addProfileID(profile_id)
if profile_id == self.config.currentProfile():
self.comboProfiles.setCurrentProfileID(profile_id)

self.comboProfilesAction.setVisible(len(profiles) > 1)

self.updateProfile()
Expand Down
Loading