From afb8da894224ee66e926c3e9f1f602c3856e4331 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 6 Feb 2026 17:09:05 +0100 Subject: [PATCH] MT#62763 Fix pycodestyle issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add pyproject.toml and tox.ini with consistent black and pycodestyle settings. - Run black for consistent coding style. - Manually fix remaining issues: + Split overlong strings. + Reflow comments. + Use «is» instead of «==» for None. + Disable checks for explicit empty blank lines in test data. Change-Id: I6d10b78061974d8f96bdb07eadee939e0e481aa4 --- pyproject.toml | 7 + t/conftest.py | 8 +- t/fixtures/commandline.py | 34 ++-- t/fixtures/fs.py | 2 +- t/fixtures/gitrepo.py | 216 ++++++++++++++------- t/fixtures/programs.py | 14 +- t/test_fixture_ngcpcfg.py | 32 +-- t/test_ngcp_instances_validator.py | 3 + t/test_ngcpcfg.py | 16 +- t/test_ngcpcfg_apply.py | 4 +- t/test_ngcpcfg_apply_instances.py | 15 +- t/test_ngcpcfg_build_network_interfaces.py | 4 +- t/test_ngcpcfg_build_syntax.py | 3 +- t/test_ngcpcfg_get.py | 4 +- t/test_ngcpcfg_patch.py | 203 ++++++++++++++----- t/test_ngcpcfg_set_and_del.py | 16 +- t/test_ngcpcfg_status.py | 3 +- tox.ini | 2 + 18 files changed, 417 insertions(+), 169 deletions(-) create mode 100644 pyproject.toml create mode 100644 tox.ini diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..eb3b35ac --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[tool.black] +# Match line-length expected by pycodestyle. +line-length = 79 +# Current version in Debian trixie. +target-version = ['py313'] +# Enable preview features, expected by pycodestyle. +preview = true diff --git a/t/conftest.py b/t/conftest.py index e48a8916..ce91aa0f 100644 --- a/t/conftest.py +++ b/t/conftest.py @@ -1,2 +1,8 @@ import pytest -pytest_plugins = ['fixtures.commandline', 'fixtures.fs', 'fixtures.gitrepo', 'fixtures.programs'] + +pytest_plugins = [ + "fixtures.commandline", + "fixtures.fs", + "fixtures.gitrepo", + "fixtures.programs", +] diff --git a/t/fixtures/commandline.py b/t/fixtures/commandline.py index da47d5e0..aa63ad94 100644 --- a/t/fixtures/commandline.py +++ b/t/fixtures/commandline.py @@ -5,13 +5,21 @@ import functools import subprocess import collections +ProcessResult = collections.namedtuple( + "ProcessResult", ["exitcode", "stdout", "stderr"] +) -ProcessResult = collections.namedtuple('ProcessResult', - ['exitcode', 'stdout', 'stderr']) - -def run(*args, env=None, timeout=None, stdin=None, expect_stdout=True, - expect_stderr=True, outencoding='utf-8', errencoding='utf-8'): +def run( + *args, + env=None, + timeout=None, + stdin=None, + expect_stdout=True, + expect_stderr=True, + outencoding="utf-8", + errencoding="utf-8", +): """Execute command in `args` in a subprocess""" # drop stdout & stderr and spare some memory, if not needed @@ -24,11 +32,13 @@ def run(*args, env=None, timeout=None, stdin=None, expect_stdout=True, stderr = None # run command - p = subprocess.Popen(args, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - env=env) + p = subprocess.Popen( + args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + ) if stdin: p.stdin.write(stdin) stdout, stderr = p.communicate(timeout=timeout) @@ -37,11 +47,11 @@ def run(*args, env=None, timeout=None, stdin=None, expect_stdout=True, if expect_stdout and stdout: stdoutput = stdout.decode(outencoding) else: - stdoutput = '' + stdoutput = "" if expect_stderr and stderr: stderror = stderr.decode(errencoding) else: - stderror = '' + stderror = "" return ProcessResult(p.returncode, stdoutput, stderror) diff --git a/t/fixtures/fs.py b/t/fixtures/fs.py index e4d7971c..331cd7f5 100644 --- a/t/fixtures/fs.py +++ b/t/fixtures/fs.py @@ -38,4 +38,4 @@ def check_stdoutput(stdout, test_file, tmpdir): output_file = os.path.join(tmpdir, "check.txt") with open(output_file, "w") as out_file: out_file.writelines(stdout) - check_output(output_file, test_file) \ No newline at end of file + check_output(output_file, test_file) diff --git a/t/fixtures/gitrepo.py b/t/fixtures/gitrepo.py index aa2e9979..ab501e31 100644 --- a/t/fixtures/gitrepo.py +++ b/t/fixtures/gitrepo.py @@ -9,52 +9,129 @@ import zipfile from .commandline import run from .fs import keep_directory -BUILTIN_GIT_COMMANDS = {"add", "am", "annotate", "apply", "archive", - "bisect--helper", "blame", "branch", - "bundle", "cat-file", "check-attr", - "check-ignore", "check-mailmap", - "check-ref-format", "checkout", - "checkout-index", "cherry", - "cherry-pick", "clean", "clone", - "column", "commit", "commit-tree", - "config", "count-objects", "credential", - "describe", "diff", "diff-files", - "diff-index", "diff-tree", - "fast-export", "fetch", "fetch-pack", - "fmt-merge-msg", "for-each-ref", - "format-patch", "fsck", "fsck-objects", - "gc", "get-tar-commit-id", "grep", - "hash-object", "help", "index-pack", - "init", "init-db", "interpret-trailers", - "log", "ls-files", "ls-remote", - "ls-tree", "mailinfo", "mailsplit", - "merge", "merge-base", "merge-file", - "merge-index", "merge-ours", - "merge-recursive", "merge-subtree", - "merge-tree", "mktag", "mktree", "mv", - "name-rev", "notes", "pack-objects", - "pack-redundant", "pack-refs", - "patch-id", "prune", "prune-packed", - "pull", "push", "read-tree", - "receive-pack", "reflog", "remote", - "remote-ext", "remote-fd", "remote-ftp", - "remote-ftps", "remote-https", "repack", - "replace", "rerere", "reset", - "rev-list", "rev-parse", "revert", "rm", - "send-pack", "shortlog", "show", - "show-branch", "show-ref", "stage", - "status", "stripspace", - "submodule--helper", "symbolic-ref", - "tag", "unpack-file", "unpack-objects", - "update-index", "update-ref", - "update-server-info", "upload-archive", - "var", "verify-commit", "verify-pack", - "verify-tag", "whatchanged", "worktree", - "write-tree"} +BUILTIN_GIT_COMMANDS = { + "add", + "am", + "annotate", + "apply", + "archive", + "bisect--helper", + "blame", + "branch", + "bundle", + "cat-file", + "check-attr", + "check-ignore", + "check-mailmap", + "check-ref-format", + "checkout", + "checkout-index", + "cherry", + "cherry-pick", + "clean", + "clone", + "column", + "commit", + "commit-tree", + "config", + "count-objects", + "credential", + "describe", + "diff", + "diff-files", + "diff-index", + "diff-tree", + "fast-export", + "fetch", + "fetch-pack", + "fmt-merge-msg", + "for-each-ref", + "format-patch", + "fsck", + "fsck-objects", + "gc", + "get-tar-commit-id", + "grep", + "hash-object", + "help", + "index-pack", + "init", + "init-db", + "interpret-trailers", + "log", + "ls-files", + "ls-remote", + "ls-tree", + "mailinfo", + "mailsplit", + "merge", + "merge-base", + "merge-file", + "merge-index", + "merge-ours", + "merge-recursive", + "merge-subtree", + "merge-tree", + "mktag", + "mktree", + "mv", + "name-rev", + "notes", + "pack-objects", + "pack-redundant", + "pack-refs", + "patch-id", + "prune", + "prune-packed", + "pull", + "push", + "read-tree", + "receive-pack", + "reflog", + "remote", + "remote-ext", + "remote-fd", + "remote-ftp", + "remote-ftps", + "remote-https", + "repack", + "replace", + "rerere", + "reset", + "rev-list", + "rev-parse", + "revert", + "rm", + "send-pack", + "shortlog", + "show", + "show-branch", + "show-ref", + "stage", + "status", + "stripspace", + "submodule--helper", + "symbolic-ref", + "tag", + "unpack-file", + "unpack-objects", + "update-index", + "update-ref", + "update-server-info", + "upload-archive", + "var", + "verify-commit", + "verify-pack", + "verify-tag", + "whatchanged", + "worktree", + "write-tree", +} # helpers + def delete_tmp_folder(folder): """Recursively delete a folder""" shutil.rmtree(folder) @@ -72,6 +149,7 @@ def find_git_root(folder): # implementation + class GitCommand: def __init__(self, repo, command): self.repo = repo @@ -80,7 +158,7 @@ class GitCommand: def __call__(self, *args): with keep_directory(): os.chdir(self.repo.root) - return run('git', self.command, *args) + return run("git", self.command, *args) def __repr__(self): return "command 'git {}'".format(self.command) @@ -108,18 +186,18 @@ class GitRepository: @property def branch(self): """Return current git branch""" - ex, out, err = GitCommand(self, 'branch')() + ex, out, err = GitCommand(self, "branch")() assert ex == 0 for line in out.splitlines(): - if line.startswith('*'): + if line.startswith("*"): return line[1:].strip() @property def version(self): """Return git version in use""" - ex, out, err = GitCommand(self, '--version')() + ex, out, err = GitCommand(self, "--version")() assert ex == 0 - return ' '.join(out.strip().split()[2:]) + return " ".join(out.strip().split()[2:]) def __repr__(self): return "GitRepository at '{}'".format(self.root) @@ -127,7 +205,8 @@ class GitRepository: class GitLoader: """Provides methods to download a git repository""" - default = 'default-git-repository.tar.gz' + + default = "default-git-repository.tar.gz" def __init__(self, tmpdir): self.localpath = tmpdir.mkdir("git-pytest") @@ -136,43 +215,46 @@ class GitLoader: def extract_archive(src, dest): """Extract files and folder in archive `src` to path `dest`""" suffix = None - if src.endswith('.tgz') or src.endswith('.tar.gz'): - suffix = ':gz' - elif src.endswith('.tbz2') or src.endswith('.tar.bz2'): - suffix = ':bz2' - elif src.endswith('.tar.lzma'): - suffix = ':xz' - elif src.endswith('.tar'): - suffix = '' + if src.endswith(".tgz") or src.endswith(".tar.gz"): + suffix = ":gz" + elif src.endswith(".tbz2") or src.endswith(".tar.bz2"): + suffix = ":bz2" + elif src.endswith(".tar.lzma"): + suffix = ":xz" + elif src.endswith(".tar"): + suffix = "" if suffix is not None: - ar = tarfile.open(src, 'r' + suffix) + ar = tarfile.open(src, "r" + suffix) ar.extractall(path=dest) return dest - elif src.endswith('.zip'): - with zipfile.ZipFile(src, 'r') as fd: + elif src.endswith(".zip"): + with zipfile.ZipFile(src, "r") as fd: fd.extractall(path=dest) return dest else: - raise ValueError('Archive of unknown file type: {}'.format(src)) + raise ValueError("Archive of unknown file type: {}".format(src)) def from_url(self, url): """Clone git repository from URL""" - ex, out, err = run('git', 'clone', url, self.localpath) + ex, out, err = run("git", "clone", url, self.localpath) assert ex == 0 - return GitRepository(find_git_root(self.localpath), - delete_fn=self.cleanup) + return GitRepository( + find_git_root(self.localpath), delete_fn=self.cleanup + ) def from_archive(self, archive_path): """Extract git repository from given archive""" self.localpath = self.extract_archive(archive_path, self.localpath) - return GitRepository(find_git_root(self.localpath), - delete_fn=self.cleanup) + return GitRepository( + find_git_root(self.localpath), delete_fn=self.cleanup + ) def in_folder(self, path): """Assume `path` already contains a git repository""" - assert os.path.exists(os.path.join(path, '.git')), \ - '.git folder must exist in git repository' + assert os.path.exists( + os.path.join(path, ".git") + ), ".git folder must exist in git repository" return GitRepository(path) def cleanup(self): diff --git a/t/fixtures/programs.py b/t/fixtures/programs.py index bcbe7df8..988f394f 100644 --- a/t/fixtures/programs.py +++ b/t/fixtures/programs.py @@ -135,8 +135,9 @@ def ngcpcfg(gitrepo, tmpdir, *args): ): testenv["SERVICES_POOL_BASE"] = testenv["TEMPLATE_POOL_BASE"] print( - "forced SERVICES_POOL_BASE={}" - .format(testenv["SERVICES_POOL_BASE"]) + "forced SERVICES_POOL_BASE={}".format( + testenv["SERVICES_POOL_BASE"] + ) ) # this has to be absolute testenv["NGCPCFG"] = Path(testenv["NGCPCFG"]).resolve() @@ -167,7 +168,7 @@ def ngcpcfg(gitrepo, tmpdir, *args): env["SERVICES_POOL_BASE"] = env[key_base] cfg.set("ngcpcfg", "SERVICES_POOL_BASE", str(dst_pool)) # each CONFIG_TOOL dir has to be a git repository - for dir in cfg.get("ngcpcfg", "CONFIG_POOL").split(' '): + for dir in cfg.get("ngcpcfg", "CONFIG_POOL").split(" "): dir_path = Path(outdir).joinpath(dir[1:]) print("create empty git repository at {}".format(dir_path)) gitrepo.extract_archive(str(EMPTY_GIT), dir_path) @@ -318,10 +319,9 @@ def helpercli(tmpdir, *args): print("stderr:") print(stderr) - result = namedtuple("ProcessResult", - ["returncode", "stdout", "stderr"])( - p.returncode, stdout, stderr - ) + result = namedtuple( + "ProcessResult", ["returncode", "stdout", "stderr"] + )(p.returncode, stdout, stderr) return result return run diff --git a/t/test_fixture_ngcpcfg.py b/t/test_fixture_ngcpcfg.py index d27ffea1..86b4765c 100644 --- a/t/test_fixture_ngcpcfg.py +++ b/t/test_fixture_ngcpcfg.py @@ -19,11 +19,11 @@ def test_file_out(tmpdir): filename = "config.yml" src = Path("fixtures/repos").joinpath(filename) dst_dir = Path(tmpdir.mkdir("copy_tree")) - assert copy_tree(dst_dir, src, dst_dir) == None + assert copy_tree(dst_dir, src, dst_dir) is None def test_file_in(tmpdir): - """src is a file from NGCPCTL_MAIN """ + """src is a file from NGCPCTL_MAIN""" filename = "config.yml" base = Path("fixtures/repos") src = base.joinpath(filename) @@ -37,7 +37,7 @@ def test_file_in(tmpdir): def test_dir_out(tmpdir): dirname = tmpdir.mkdir("config") dst_dir = Path(tmpdir.mkdir("copy_tree")) - assert copy_tree(dst_dir, dirname, dst_dir) == None + assert copy_tree(dst_dir, dirname, dst_dir) is None def test_dir_in(tmpdir): @@ -54,17 +54,22 @@ def test_empty(ngcpcfg): ngcpctl_config = Path(env["NGCPCTL_MAIN"]).joinpath("config.yml") assert ngcpctl_config.exists() assert str(ngcpctl_config) != str(cfg["NGCPCTL_CONFIG"]) - assert Path(cfg["TEMPLATE_POOL_BASE"]) == Path(env["NGCPCTL_MAIN"]).joinpath( - "templates" - ) + assert Path(cfg["TEMPLATE_POOL_BASE"]) == Path( + env["NGCPCTL_MAIN"] + ).joinpath("templates") def test_config(ngcpcfg): """test that templates are properly copied and configs defined in env""" env, cfg = ngcpcfg({"NGCPCFG": "fixtures/ngcpcfg.cfg"}) - tt2_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc/bad-syntax.txt.tt2") + tt2_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath( + "etc/bad-syntax.txt.tt2" + ) assert tt2_path.exists() - assert Path(env["NETWORK_CONFIG"]) == Path("fixtures/repos/network.yml").resolve() + assert ( + Path(env["NETWORK_CONFIG"]) + == Path("fixtures/repos/network.yml").resolve() + ) def test_template_pool(ngcpcfg): @@ -78,7 +83,9 @@ def test_template_pool(ngcpcfg): tt2_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc/fake.txt.tt2") assert tt2_path.exists() # no files from fixtures/repos/templates is left - tt2_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc/bad-syntax.txt.tt2") + tt2_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath( + "etc/bad-syntax.txt.tt2" + ) assert not tt2_path.exists() @@ -109,12 +116,15 @@ def test_config_cli(ngcpcfgcli): out = ngcpcfgcli( "status", env={"NGCPCFG": "fixtures/ngcpcfg_carrier_instances.cfg"} ) - # NGCPCFG is always generated with env values and add as ${NGCPCTL_MAIN}/ngcpcfg.cfg + # NGCPCFG is always generated with env values and add as + # "${NGCPCTL_MAIN}/ngcpcfg.cfg". assert ( out.env["NGCPCFG"] == Path(out.env["NGCPCTL_MAIN"]).joinpath("ngcpcfg.cfg").resolve() ) - tt2_path = Path(out.cfg["TEMPLATE_POOL_BASE"]).joinpath("etc/bad-syntax.txt.tt2") + tt2_path = Path(out.cfg["TEMPLATE_POOL_BASE"]).joinpath( + "etc/bad-syntax.txt.tt2" + ) assert tt2_path.exists() assert ( Path(out.env["NETWORK_CONFIG"]) diff --git a/t/test_ngcp_instances_validator.py b/t/test_ngcp_instances_validator.py index e7540fdd..453cb531 100644 --- a/t/test_ngcp_instances_validator.py +++ b/t/test_ngcp_instances_validator.py @@ -68,6 +68,7 @@ def test_wrong_link_interfaces(cli): out.stderr, ) + def test_repeated_instance_name(cli): file = "repeated_instance_name" cmd = [ @@ -82,6 +83,7 @@ def test_repeated_instance_name(cli): out.stderr, ) + def test_repeated_instance_name_in_connections(cli): file = "repeated_instance_name_in_connections" cmd = [ @@ -96,6 +98,7 @@ def test_repeated_instance_name_in_connections(cli): out.stderr, ) + def test_host_to_run_on_is_absent(cli): file = "host_to_run_on_is_absent" cmd = [ diff --git a/t/test_ngcpcfg.py b/t/test_ngcpcfg.py index c6b35154..684e5f02 100644 --- a/t/test_ngcpcfg.py +++ b/t/test_ngcpcfg.py @@ -43,10 +43,14 @@ def test_simple_build_template_no_ha_no_carrier(ngcpcfgcli): out = ngcpcfgcli("build", "/etc/config_variants") assert out.returncode == 0 regex = re.compile( - r"Generating " + str(out.env["OUTPUT_DIRECTORY"]) + r"/etc/config_variants: OK" + r"Generating " + + str(out.env["OUTPUT_DIRECTORY"]) + + r"/etc/config_variants: OK" ) assert re.search(regex, out.stdout) - output_file = os.path.join(out.env["OUTPUT_DIRECTORY"], "etc/config_variants") + output_file = os.path.join( + out.env["OUTPUT_DIRECTORY"], "etc/config_variants" + ) test_file = "fixtures/output/config_variants" check_output(output_file, test_file) @@ -62,10 +66,14 @@ def test_simple_build_template_pro(ngcpcfgcli): ) assert out.returncode == 0 regex = re.compile( - r"Generating " + str(out.env["OUTPUT_DIRECTORY"]) + r"/etc/config_variants: OK" + r"Generating " + + str(out.env["OUTPUT_DIRECTORY"]) + + r"/etc/config_variants: OK" ) assert re.search(regex, out.stdout) - output_file = os.path.join(out.env["OUTPUT_DIRECTORY"], "etc/config_variants") + output_file = os.path.join( + out.env["OUTPUT_DIRECTORY"], "etc/config_variants" + ) test_file = "fixtures/output/config_variants_pro" check_output(output_file, test_file) diff --git a/t/test_ngcpcfg_apply.py b/t/test_ngcpcfg_apply.py index b86ec480..4b8fb7c2 100644 --- a/t/test_ngcpcfg_apply.py +++ b/t/test_ngcpcfg_apply.py @@ -28,7 +28,9 @@ def test_apply_no_commit_msg(ngcpcfg, ngcpcfgcli): ) assert re.search(r"Please provide commit message", out.stdout) - assert re.search(r"Error: Uncommitted configuration files found", out.stderr) + assert re.search( + r"Error: Uncommitted configuration files found", out.stderr + ) assert out.returncode != 0 diff --git a/t/test_ngcpcfg_apply_instances.py b/t/test_ngcpcfg_apply_instances.py index 1df12add..162404c4 100644 --- a/t/test_ngcpcfg_apply_instances.py +++ b/t/test_ngcpcfg_apply_instances.py @@ -35,13 +35,15 @@ def test_apply_instances(ngcpcfgcli, tmpdir): output_file = base_dir.joinpath("ngcpcfg.serviceA") check_stdoutput("INSTANCE_NAME:A\n", str(output_file), tmpdir) assert re.search( - r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[A\]", out.stdout + r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[A\]", + out.stdout, ) output_file = base_dir.joinpath("ngcpcfg.serviceB") check_stdoutput("INSTANCE_NAME:B\n", str(output_file), tmpdir) assert re.search( - r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[B\]", out.stdout + r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[B\]", + out.stdout, ) @@ -96,17 +98,20 @@ def test_apply_instances_changes(ngcpcfg, ngcpcfgcli, tmpdir, gitrepo): output_file = base_dir.joinpath("ngcpcfg.service") assert not output_file.exists() assert not re.search( - r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services$", out.stdout + r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services$", + out.stdout, ) output_file = base_dir.joinpath("ngcpcfg.serviceA") assert not output_file.exists() assert not re.search( - r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[A\]$", out.stdout + r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[A\]$", + out.stdout, ) output_file = base_dir.joinpath("ngcpcfg.serviceB") check_stdoutput("INSTANCE_NAME:B\n", str(output_file), tmpdir) assert re.search( - r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[B\]", out.stdout + r"Executing action for .*/etc/kamailio/lb/ngcpcfg.services\[B\]", + out.stdout, ) diff --git a/t/test_ngcpcfg_build_network_interfaces.py b/t/test_ngcpcfg_build_network_interfaces.py index 066276d4..dc35e61d 100644 --- a/t/test_ngcpcfg_build_network_interfaces.py +++ b/t/test_ngcpcfg_build_network_interfaces.py @@ -19,7 +19,9 @@ def test_network_interfaces(ngcpcfgcli): assert re.search(r"Generating .*/etc/network/interfaces: OK", out.stdout) assert not re.search(r"Error", out.stdout) - output_file = out.env["OUTPUT_DIRECTORY"].joinpath("etc/network/interfaces") + output_file = out.env["OUTPUT_DIRECTORY"].joinpath( + "etc/network/interfaces" + ) test_file = "fixtures/output/network_interfaces" check_output(str(output_file), test_file) diff --git a/t/test_ngcpcfg_build_syntax.py b/t/test_ngcpcfg_build_syntax.py index c16e8354..68eb9c21 100644 --- a/t/test_ngcpcfg_build_syntax.py +++ b/t/test_ngcpcfg_build_syntax.py @@ -15,7 +15,8 @@ def test_bad_syntax(ngcpcfgcli): }, ) assert re.search( - r"Error: Cannot process template " "'.*etc/bad-syntax.txt.tt2':.*", out.stderr + r"Error: Cannot process template " "'.*etc/bad-syntax.txt.tt2':.*", + out.stderr, ) assert re.search( r"file error - parse error - input file handle line 1: " diff --git a/t/test_ngcpcfg_get.py b/t/test_ngcpcfg_get.py index b99bdb4d..3cb8e3a2 100644 --- a/t/test_ngcpcfg_get.py +++ b/t/test_ngcpcfg_get.py @@ -17,7 +17,9 @@ def test_get_action_missing_key_parameter(ngcpcfgcli): @pytest.mark.get def test_get_action_missing_file(ngcpcfgcli): - out = ngcpcfgcli("get", "test", env={"NGCPCTL_CONFIG": "/run/nonexistent-file"}) + out = ngcpcfgcli( + "get", "test", env={"NGCPCTL_CONFIG": "/run/nonexistent-file"} + ) assert "" in out.stdout assert ( "Error: Configuration file /run/nonexistent-file does not " diff --git a/t/test_ngcpcfg_patch.py b/t/test_ngcpcfg_patch.py index c9ad4bb6..fc469de3 100644 --- a/t/test_ngcpcfg_patch.py +++ b/t/test_ngcpcfg_patch.py @@ -52,7 +52,10 @@ APT::Install-Recommends "0"; assert "'ngcpcfg patch' walks through all templates" in out.stdout assert "Validating patch" not in out.stdout - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) assert out.returncode == 0 @@ -90,14 +93,20 @@ APT::Install-Recommends "0"; ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) - assert "Requested patchtt operation has finished successfully." in out.stdout + assert ( + "Requested patchtt operation has finished successfully." in out.stdout + ) assert out.returncode == 0 generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") - assert generated_customtt.read_text() == """APT::Install-Recommends "1";\n""" + assert ( + generated_customtt.read_text() == """APT::Install-Recommends "1";\n""" + ) @pytest.mark.tt_24920 @@ -134,7 +143,9 @@ APT::Install-Recommends "0"; ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( @@ -147,7 +158,10 @@ APT::Install-Recommends "0"; "Error: Some operations above finished with an error for the file(s)" in out.stderr ) - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") assert not generated_customtt.exists() @@ -156,7 +170,8 @@ APT::Install-Recommends "0"; @pytest.mark.tt_24920 def test_patch_action_template_missing_for_patchtt(ngcpcfg, ngcpcfgcli): - # ensure "ngcpcfg build" will be aborted if patchtt for missing template found + # Ensure "ngcpcfg build" will be aborted if patchtt for missing template + # found. env, cfg = ngcpcfg() template_pool = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") @@ -182,7 +197,9 @@ def test_patch_action_template_missing_for_patchtt(ngcpcfg, ngcpcfgcli): ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( @@ -193,13 +210,17 @@ def test_patch_action_template_missing_for_patchtt(ngcpcfg, ngcpcfgcli): "Error: Some operations above finished with an error for the file(s)" in out.stderr ) - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) assert out.returncode != 0 @pytest.mark.tt_24920 def test_patch_action_generate_requested_customtt_only(ngcpcfg, ngcpcfgcli): - # ensure 'ngcpcfg patch .../some.patchtt.tt2' will build one requested patchtt only + # Ensure 'ngcpcfg patch .../some.patchtt.tt2' will build one requested + # patchtt only. env, cfg = ngcpcfg() template_pool = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") @@ -247,7 +268,9 @@ APT::Install-Recommends "0"; ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( @@ -255,11 +278,15 @@ APT::Install-Recommends "0"; in out.stdout ) assert ( - "Successfully created '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Successfully created '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert "72_another_file.customtt.tt2" not in out.stdout - assert "Requested patchtt operation has finished successfully." in out.stdout + assert ( + "Requested patchtt operation has finished successfully." in out.stdout + ) assert out.returncode == 0 generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") @@ -268,7 +295,9 @@ APT::Install-Recommends "0"; @pytest.mark.tt_24920 -def test_patch_action_generate_requested_customtt_only_shortname(ngcpcfg, ngcpcfgcli): +def test_patch_action_generate_requested_customtt_only_shortname( + ngcpcfg, ngcpcfgcli +): # ensure 'ngcpcfg patch .../some.patchtt.tt2' will build one # requested patchtt only using the short filename @@ -319,7 +348,9 @@ APT::Install-Recommends "0"; ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( @@ -327,11 +358,15 @@ APT::Install-Recommends "0"; in out.stdout ) assert ( - "Successfully created '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Successfully created '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert "72_another_file.customtt.tt2" not in out.stdout - assert "Requested patchtt operation has finished successfully." in out.stdout + assert ( + "Requested patchtt operation has finished successfully." in out.stdout + ) assert out.returncode == 0 generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") @@ -366,7 +401,9 @@ APT::Install-Recommends "0"; @pytest.mark.tt_24920 -def test_patch_action_build_generate_and_overwrite_customtt_file(ngcpcfg, ngcpcfgcli): +def test_patch_action_build_generate_and_overwrite_customtt_file( + ngcpcfg, ngcpcfgcli +): # Ensure here "ngcpcfg build" will: # * find available patchtt file # * validate available patchtt file (necessary only) @@ -465,11 +502,15 @@ dome dummy customtt message assert "No patchtt files found, nothing to patch." not in out.stdout assert "dummy" not in out.stdout assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2.sp1'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2.sp1'" in out.stdout ) assert ( @@ -477,11 +518,15 @@ dome dummy customtt message in out.stdout ) assert ( - "Successfully created '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Successfully created '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert ( - "Applying patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2.sp1'" + "Applying patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2.sp1'" in out.stdout ) assert ( @@ -490,7 +535,9 @@ dome dummy customtt message + "/71_no_recommended.customtt.tt2.sp1'" in out.stdout ) - assert "Requested patchtt operation has finished successfully." in out.stdout + assert ( + "Requested patchtt operation has finished successfully." in out.stdout + ) assert ( "Generating " + str(out.env["OUTPUT_DIRECTORY"]) @@ -502,7 +549,9 @@ dome dummy customtt message generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") generated_customtt.read_text() == expected_output - generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2.sp1") + generated_customtt = apt_path.joinpath( + "71_no_recommended.customtt.tt2.sp1" + ) generated_customtt.read_text() == expected_output_sp1 generated_config = out.env["OUTPUT_DIRECTORY"].joinpath( @@ -513,8 +562,9 @@ dome dummy customtt message @pytest.mark.tt_24920 def test_patch_action_build_generate_all_file(ngcpcfg, ngcpcfgcli): - # the same as test 'test_patch_action_build_generate_and_overwrite_customtt_file' - # while build all available files + # The same as test + # 'test_patch_action_build_generate_and_overwrite_customtt_file' + # while build all available files. env, cfg = ngcpcfg( env={ @@ -603,24 +653,35 @@ dome dummy customtt message assert "No patchtt files found, nothing to patch." not in out.stdout assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" + in out.stdout + ) + assert ( + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2.sp1'" in out.stdout ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2.sp1'" + "Validating patch '" + str(dummy_path) + "/dummy.patchtt.tt2'" in out.stdout ) - assert "Validating patch '" + str(dummy_path) + "/dummy.patchtt.tt2'" in out.stdout assert ( "Applying patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( - "Successfully created '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Successfully created '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert ( - "Applying patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2.sp1'" + "Applying patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2.sp1'" in out.stdout ) assert ( @@ -629,12 +690,17 @@ dome dummy customtt message + "/71_no_recommended.customtt.tt2.sp1'" in out.stdout ) - assert "Applying patch '" + str(dummy_path) + "/dummy.patchtt.tt2'" in out.stdout + assert ( + "Applying patch '" + str(dummy_path) + "/dummy.patchtt.tt2'" + in out.stdout + ) assert ( "Successfully created '" + str(dummy_path) + "/dummy.customtt.tt2'" in out.stdout ) - assert "Requested patchtt operation has finished successfully." in out.stdout + assert ( + "Requested patchtt operation has finished successfully." in out.stdout + ) assert ( "Generating " + str(out.env["OUTPUT_DIRECTORY"]) @@ -646,7 +712,9 @@ dome dummy customtt message generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2") generated_customtt.read_text() == expected_output - generated_customtt = apt_path.joinpath("71_no_recommended.customtt.tt2.sp1") + generated_customtt = apt_path.joinpath( + "71_no_recommended.customtt.tt2.sp1" + ) generated_customtt.read_text() == expected_output_sp1 generated_config = out.env["OUTPUT_DIRECTORY"].joinpath( @@ -656,7 +724,9 @@ dome dummy customtt message @pytest.mark.tt_24920 -def test_patch_action_customtt_does_not_trigger_patch_file(ngcpcfg, ngcpcfgcli): +def test_patch_action_customtt_does_not_trigger_patch_file( + ngcpcfg, ngcpcfgcli +): # ensure here new patch functionality on "ngcpcfg build" # will NOT affect current customtt logic if no patchtt file available @@ -689,7 +759,10 @@ APT::Install-Recommends "1"; ) assert "No patchtt files found, nothing to patch." in out.stdout - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) assert "Generating " in out.stdout assert "/etc/apt/apt.conf.d/71_no_recommended: OK" in out.stdout assert "Validating patch" not in out.stdout @@ -737,7 +810,9 @@ APT::Install-Recommends "0"; ) assert ( - "Validating patch '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Validating patch '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) assert ( @@ -750,7 +825,10 @@ APT::Install-Recommends "0"; "Error: Some operations above finished with an error for the file(s)" in out.stderr ) - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) assert "Generating " not in out.stdout assert "/etc/apt/apt.conf.d/71_no_recommended: OK" not in out.stdout assert out.returncode != 0 @@ -794,7 +872,7 @@ APT::Install-Recommends "2"; -APT::Install-Recommends "0"; +APT::Install-Recommends "2"; """ - ) + ) # noqa: W293 out = ngcpcfgcli( "patch", @@ -804,14 +882,20 @@ APT::Install-Recommends "2"; assert "No patchtt files found, nothing to patch." not in out.stdout assert ( - "Validating customtt '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Validating customtt '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert ( - "Creating patchtt file '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Creating patchtt file '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) - assert "Requested customtt operation has finished successfully." in out.stdout + assert ( + "Requested customtt operation has finished successfully." in out.stdout + ) assert out.returncode == 0 generated_patchtt = apt_path.joinpath("71_no_recommended.patchtt.tt2") @@ -821,8 +905,8 @@ APT::Install-Recommends "2"; @pytest.mark.tt_24920 def test_patch_action_from_customtt_missing_file_argument(ngcpcfg, ngcpcfgcli): - # ensure "ngcpcfg patch --from-customtt missing.customtt.tt2" will be handled properly if - # no some.customtt.tt2 file are available + # Ensure "ngcpcfg patch --from-customtt missing.customtt.tt2" will be + # handled properly if no some.customtt.tt2 file are available. env, cfg = ngcpcfg() template_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") @@ -842,8 +926,9 @@ def test_patch_action_from_customtt_missing_file_argument(ngcpcfg, ngcpcfgcli): @pytest.mark.tt_24920 def test_patch_action_from_customtt_filename_only(ngcpcfg, ngcpcfgcli): - # ensure "ngcpcfg patch --from-customtt valid.customtt.tt2" will be handled properly if - # no filename only valid.customtt.tt2 has been passed instead of full path + # Ensure "ngcpcfg patch --from-customtt valid.customtt.tt2" will be + # handled properly if no filename only valid.customtt.tt2 has been + # passed instead of full path. env, cfg = ngcpcfg() template_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") @@ -872,7 +957,7 @@ APT::Install-Recommends "2"; -APT::Install-Recommends "0"; +APT::Install-Recommends "2"; """ - ) + ) # noqa: W293 out = ngcpcfgcli( "patch", @@ -883,14 +968,20 @@ APT::Install-Recommends "2"; assert "No patchtt files found, nothing to patch." not in out.stdout assert ( - "Validating customtt '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Validating customtt '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert ( - "Creating patchtt file '" + str(apt_path) + "/71_no_recommended.patchtt.tt2'" + "Creating patchtt file '" + + str(apt_path) + + "/71_no_recommended.patchtt.tt2'" in out.stdout ) - assert "Requested customtt operation has finished successfully." in out.stdout + assert ( + "Requested customtt operation has finished successfully." in out.stdout + ) assert out.returncode == 0 generated_patchtt = apt_path.joinpath("71_no_recommended.patchtt.tt2") @@ -900,7 +991,8 @@ APT::Install-Recommends "2"; @pytest.mark.tt_24920 def test_patch_action_from_customtt_missing_templates(ngcpcfg, ngcpcfgcli): - # ensure "ngcpcfg patch --from-customtt" will be aborted if template is missing for customtt + # Ensure "ngcpcfg patch --from-customtt" will be aborted if template is + # missing for customtt. env, cfg = ngcpcfg() template_path = Path(cfg["TEMPLATE_POOL_BASE"]).joinpath("etc") @@ -921,7 +1013,9 @@ the content here doesn't matter as no tt2 file available ) assert ( - "Validating customtt '" + str(apt_path) + "/71_no_recommended.customtt.tt2'" + "Validating customtt '" + + str(apt_path) + + "/71_no_recommended.customtt.tt2'" in out.stdout ) assert ( @@ -934,5 +1028,8 @@ the content here doesn't matter as no tt2 file available "Error: Some operations above finished with an error for the file(s)" in out.stderr ) - assert "Requested patchtt operation has finished successfully." not in out.stdout + assert ( + "Requested patchtt operation has finished successfully." + not in out.stdout + ) assert out.returncode != 0 diff --git a/t/test_ngcpcfg_set_and_del.py b/t/test_ngcpcfg_set_and_del.py index a8bd9d40..f3511a88 100644 --- a/t/test_ngcpcfg_set_and_del.py +++ b/t/test_ngcpcfg_set_and_del.py @@ -420,6 +420,7 @@ foo: assert "Error: Elements in array '[bla]' should be quoted" in out.stderr assert out.returncode == 1 + @pytest.mark.tt_33030 def test_set_action_append_array_element(ngcpcfgcli, tmpdir): tmpfile = tmpdir.join("tmpfile.txt") @@ -558,7 +559,10 @@ foo: """ ) assert "" in out.stdout - assert "Key resolved to a ARRAY reference; refusing to overwrite." in out.stderr + assert ( + "Key resolved to a ARRAY reference; refusing to overwrite." + in out.stderr + ) assert out.returncode == 1 @@ -590,7 +594,10 @@ foo: """ ) assert "" in out.stdout - assert "Key resolved to a ARRAY reference; refusing to overwrite." in out.stderr + assert ( + "Key resolved to a ARRAY reference; refusing to overwrite." + in out.stderr + ) assert out.returncode == 1 @@ -622,7 +629,10 @@ foo: """ ) assert "" in out.stdout - assert "Key resolved to a HASH reference; refusing to overwrite." in out.stderr + assert ( + "Key resolved to a HASH reference; refusing to overwrite." + in out.stderr + ) assert out.returncode == 1 diff --git a/t/test_ngcpcfg_status.py b/t/test_ngcpcfg_status.py index e1d0f42c..28f88a6d 100644 --- a/t/test_ngcpcfg_status.py +++ b/t/test_ngcpcfg_status.py @@ -21,5 +21,6 @@ def test_status_build(ngcpcfg, ngcpcfgcli): out = ngcpcfgcli("status", env=env) assert out.returncode == 0 assert re.search( - r"ACTION_NEEDED: commits without according build identified", out.stdout + r"ACTION_NEEDED: commits without according build identified", + out.stdout, ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..fa95328d --- /dev/null +++ b/tox.ini @@ -0,0 +1,2 @@ +[pycodestyle] +max-line-length = 79