Changes for new pylint compliance

This commit is contained in:
Tim Byrne 2023-07-09 11:13:13 -05:00
parent f9e0368385
commit 8a87f4a30f
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
6 changed files with 33 additions and 32 deletions

View File

@ -3,10 +3,10 @@
import collections import collections
import contextlib import contextlib
import copy import copy
import distutils.dir_util # pylint: disable=no-name-in-module,import-error
import os import os
import platform import platform
import pwd import pwd
import shutil
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
import py import py
import pytest import pytest
@ -31,7 +31,7 @@ def shellcheck_version():
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def pylint_version(): def pylint_version():
"""Version of pylint supported""" """Version of pylint supported"""
return '2.6.0' return '2.17.0'
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
@ -204,7 +204,7 @@ class Runner():
merged_env.update(env) merged_env.update(env)
self.inp = inp self.inp = inp
self.wrap(expect) self.wrap(expect)
process = Popen( with Popen(
self.command, self.command,
stdin=PIPE, stdin=PIPE,
stdout=PIPE, stdout=PIPE,
@ -212,14 +212,14 @@ class Runner():
shell=shell, shell=shell,
cwd=cwd, cwd=cwd,
env=merged_env, env=merged_env,
) ) as process:
input_bytes = self.inp input_bytes = self.inp
if self.inp: if self.inp:
input_bytes = self.inp.encode() input_bytes = self.inp.encode()
(out_bstream, err_bstream) = process.communicate(input=input_bytes) (out_bstream, err_bstream) = process.communicate(input=input_bytes)
self.out = out_bstream.decode() self.out = out_bstream.decode()
self.err = err_bstream.decode() self.err = err_bstream.decode()
self.code = process.wait() self.code = process.wait()
self.success = self.code == 0 self.success = self.code == 0
self.failure = self.code != 0 self.failure = self.code != 0
if report: if report:
@ -365,6 +365,10 @@ def yadm_cmd(paths):
return command_list return command_list
class NoRelativePath(Exception):
"""Exception when finding relative paths"""
class DataFile(): class DataFile():
"""Datafile object""" """Datafile object"""
@ -384,7 +388,7 @@ class DataFile():
"""Relative path property""" """Relative path property"""
if self.__parent: if self.__parent:
return self.__parent.join(self.path) return self.__parent.join(self.path)
raise BaseException('Unable to provide relative path, no parent') raise NoRelativePath('Unable to provide relative path, no parent')
@property @property
def tracked(self): def tracked(self):
@ -405,10 +409,10 @@ class DataSet():
"""Dataset object""" """Dataset object"""
def __init__(self): def __init__(self):
self.__files = list() self.__files = []
self.__dirs = list() self.__dirs = []
self.__tracked_dirs = list() self.__tracked_dirs = []
self.__private_dirs = list() self.__private_dirs = []
self.__relpath = None self.__relpath = None
def __repr__(self): def __repr__(self):
@ -562,15 +566,13 @@ def ds1_data(tmpdir_factory, config_git, ds1_dset, runner):
@pytest.fixture() @pytest.fixture()
def ds1_work_copy(ds1_data, paths): def ds1_work_copy(ds1_data, paths):
"""Function scoped copy of ds1_data.work""" """Function scoped copy of ds1_data.work"""
distutils.dir_util.copy_tree( # pylint: disable=no-member shutil.copytree(str(ds1_data.work), str(paths.work), dirs_exist_ok=True)
str(ds1_data.work), str(paths.work))
@pytest.fixture() @pytest.fixture()
def ds1_repo_copy(runner, ds1_data, paths): def ds1_repo_copy(runner, ds1_data, paths):
"""Function scoped copy of ds1_data.repo""" """Function scoped copy of ds1_data.repo"""
distutils.dir_util.copy_tree( # pylint: disable=no-member shutil.copytree(str(ds1_data.repo), str(paths.repo), dirs_exist_ok=True)
str(ds1_data.repo), str(paths.repo))
env = os.environ.copy() env = os.environ.copy()
env['GIT_DIR'] = str(paths.repo) env['GIT_DIR'] = str(paths.repo)
runner( runner(

View File

@ -26,7 +26,7 @@ def test_pylint(pytestconfig, runner, pylint_version):
run = runner(command=['pylint', '--version'], report=False) run = runner(command=['pylint', '--version'], report=False)
if f'pylint {pylint_version}' not in run.out: if f'pylint {pylint_version}' not in run.out:
pytest.skip('Unsupported pylint version') pytest.skip('Unsupported pylint version')
pyfiles = list() pyfiles = []
for tfile in os.listdir('test'): for tfile in os.listdir('test'):
if tfile.endswith('.py'): if tfile.endswith('.py'):
pyfiles.append(f'test/{tfile}') pyfiles.append(f'test/{tfile}')

View File

@ -213,14 +213,14 @@ def test_score_values(
local_user={local_user} local_user={local_user}
""" """
expected = '' expected = ''
for filename in filenames: for filename, score in filenames.items():
script += f""" script += f"""
score_file "{filename}" score_file "{filename}"
echo "{filename}" echo "{filename}"
echo "$score" echo "$score"
""" """
expected += filename + '\n' expected += filename + '\n'
expected += str(filenames[filename]) + '\n' expected += str(score) + '\n'
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.success assert run.success
assert run.err == '' assert run.err == ''
@ -278,14 +278,14 @@ def test_score_values_templates(runner, yadm):
local_user={local_user} local_user={local_user}
""" """
expected = '' expected = ''
for filename in filenames: for filename, score in filenames.items():
script += f""" script += f"""
score_file "{filename}" score_file "{filename}"
echo "{filename}" echo "{filename}"
echo "$score" echo "$score"
""" """
expected += filename + '\n' expected += filename + '\n'
expected += str(filenames[filename]) + '\n' expected += str(score) + '\n'
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.success assert run.success
assert run.err == '' assert run.err == ''
@ -337,14 +337,14 @@ def test_underscores_in_distro_and_family(runner, yadm):
local_distro_family="{local_distro_family}" local_distro_family="{local_distro_family}"
""" """
expected = '' expected = ''
for filename in filenames: for filename, score in filenames.items():
script += f""" script += f"""
score_file "{filename}" score_file "{filename}"
echo "{filename}" echo "{filename}"
echo "$score" echo "$score"
""" """
expected += filename + '\n' expected += filename + '\n'
expected += str(filenames[filename]) + '\n' expected += str(score) + '\n'
run = runner(command=['bash'], inp=script) run = runner(command=['bash'], inp=script)
assert run.success assert run.success
assert run.err == '' assert run.err == ''

View File

@ -39,7 +39,7 @@ def test_upgrade(tmpdir, runner, versions, submodule):
os.environ.pop('XDG_DATA_HOME', None) os.environ.pop('XDG_DATA_HOME', None)
def run_version(version, *args, check_stderr=True): def run_version(version, *args, check_stderr=True):
yadm = 'yadm-%s' % version if version else '/yadm/yadm' yadm = f'yadm-{version}' if version else '/yadm/yadm'
run = runner([yadm, *args], shell=True, cwd=str(home), env=env) run = runner([yadm, *args], shell=True, cwd=str(home), env=env)
assert run.success assert run.success
if check_stderr: if check_stderr:

View File

@ -10,9 +10,8 @@ def expected_version(yadm):
Expected semantic version number. This is taken directly out of yadm, Expected semantic version number. This is taken directly out of yadm,
searching for the VERSION= string. searching for the VERSION= string.
""" """
yadm_version = re.findall( with open(yadm, encoding='utf-8') as source_file:
r'VERSION=([^\n]+)', yadm_version = re.findall(r'VERSION=([^\n]+)', source_file.read())
open(yadm).read())
if yadm_version: if yadm_version:
return yadm_version[0] return yadm_version[0]
pytest.fail(f'version not found in {yadm}') pytest.fail(f'version not found in {yadm}')

View File

@ -81,7 +81,7 @@ def parse_alt_output(output, linked=True):
regex = r'Creating (.+) from template (.+)$' regex = r'Creating (.+) from template (.+)$'
if linked: if linked:
regex = r'Linking (.+) to (.+)$' regex = r'Linking (.+) to (.+)$'
parsed_list = dict() parsed_list = {}
for line in output.splitlines(): for line in output.splitlines():
match = re.match(regex, line) match = re.match(regex, line)
if match: if match: