Address more pylint warnings on tests files

All of the changes are made manual.
The target files are only those who test the new code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
This commit is contained in:
Martin Vrachev 2021-12-03 18:39:02 +02:00
parent a728717eda
commit 8d73330f86
6 changed files with 11 additions and 5 deletions

View file

@ -27,6 +27,7 @@ class TestConsistentSnapshot(unittest.TestCase):
are formed for each combination"""
def setUp(self) -> None:
# pylint: disable=consider-using-with
self.temp_dir = tempfile.TemporaryDirectory()
self.metadata_dir = os.path.join(self.temp_dir.name, "metadata")
self.targets_dir = os.path.join(self.temp_dir.name, "targets")

View file

@ -57,12 +57,14 @@ def tearDownClass(cls) -> None:
def setup_subtest(self) -> None:
# Setup repository for subtest: make sure no roots have been published
# pylint: disable=attribute-defined-outside-init
self.sim = RepositorySimulator()
self.sim.signed_roots.clear()
self.sim.root.version = 0
if self.dump_dir is not None:
# create subtest dumpdir
# pylint: disable=no-member
name = f"{self.id().split('.')[-1]}-{self.case_name}"
self.sim.dump_dir = os.path.join(self.dump_dir, name)
os.mkdir(self.sim.dump_dir)
@ -73,6 +75,7 @@ def _run_refresh(self) -> None:
self.sim.write()
# bootstrap with initial root
# pylint: disable=attribute-defined-outside-init
self.metadata_dir = tempfile.mkdtemp(dir=self.temp_dir.name)
with open(os.path.join(self.metadata_dir, "root.json"), "bw") as f:
f.write(self.sim.signed_roots[0])

View file

@ -48,14 +48,14 @@ def setUpClass(cls) -> None:
# Needed because in some tests simple_server.py cannot be found.
# The reason is that the current working directory
# has been changed when executing a subprocess.
SIMPLE_SERVER_PATH = os.path.join(os.getcwd(), "simple_server.py")
simple_server_path = os.path.join(os.getcwd(), "simple_server.py")
# Launch a SimpleHTTPServer (serves files in the current directory).
# Test cases will request metadata and target files that have been
# pre-generated in 'tuf/tests/repository_data', which will be served
# by the SimpleHTTPServer launched here.
cls.server_process_handler = utils.TestServerProcess(
log=logger, server=SIMPLE_SERVER_PATH
log=logger, server=simple_server_path
)
@classmethod
@ -259,7 +259,7 @@ def test_implicit_refresh_with_only_local_root(self) -> None:
self._assert_files(["root"])
# Get targetinfo for 'file3.txt' listed in the delegated role1
targetinfo3 = self.updater.get_targetinfo("file3.txt")
self.updater.get_targetinfo("file3.txt")
expected_files = ["role1", "root", "snapshot", "targets", "timestamp"]
self._assert_files(expected_files)

View file

@ -40,6 +40,7 @@ class TestRefresh(unittest.TestCase):
past_datetime = datetime.utcnow().replace(microsecond=0) - timedelta(days=5)
def setUp(self) -> None:
# pylint: disable=consider-using-with
self.temp_dir = tempfile.TemporaryDirectory()
self.metadata_dir = os.path.join(self.temp_dir.name, "metadata")
self.targets_dir = os.path.join(self.temp_dir.name, "targets")

View file

@ -12,11 +12,11 @@
import tempfile
import unittest
from typing import Optional, Tuple
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import MagicMock, patch
from tests import utils
from tests.repository_simulator import RepositorySimulator
from tuf.api.metadata import SPECIFICATION_VERSION, TargetFile, Targets
from tuf.api.metadata import SPECIFICATION_VERSION, Targets
from tuf.exceptions import BadVersionNumberError, UnsignedMetadataError
from tuf.ngclient import Updater

View file

@ -222,6 +222,7 @@ def _start_process(self, extra_cmd_args: List[str], popen_cwd: str) -> None:
# Reusing one subprocess in multiple tests, but split up the logs
# for each.
# pylint: disable=consider-using-with
self.__server_process = subprocess.Popen(
command,
stdout=subprocess.PIPE,