test: fix minor pylint warnings
This fixes a bunch of minor pylint warnings: * Drop unused imports. * Fix "inline-JSON" formatting. * Fix space before/after brackets. * Use `_` for unused variables. * Break overlong lines. * Mark unittest as `no-self-use` if applicable. * Drop spurious newline at end of file.
This commit is contained in:
parent
617ed6ed29
commit
72be939521
8 changed files with 50 additions and 45 deletions
|
|
@ -70,6 +70,7 @@ class TestCase(unittest.TestCase):
|
|||
result = json.loads(output)
|
||||
return result.get("tree_id"), result.get("output_id")
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def run_tree_diff(self, tree1, tree2):
|
||||
tree_diff_cmd = ["./tree-diff", tree1, tree2]
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import contextlib
|
|||
import glob
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
|
|
@ -20,7 +19,7 @@ class TestAssemblers(osbuildtest.TestCase):
|
|||
def run_assembler(self, name, options):
|
||||
with open("test/pipelines/f30-base.json") as f:
|
||||
base = json.load(f)
|
||||
base["pipeline"] = dict(base["pipeline"], assembler={ "name": name, "options": options })
|
||||
base["pipeline"] = dict(base["pipeline"], assembler={"name": name, "options": options})
|
||||
return self.run_osbuild("-", input=json.dumps(base))
|
||||
|
||||
def assertImageFile(self, filename, fmt, expected_size=None):
|
||||
|
|
@ -32,7 +31,7 @@ class TestAssemblers(osbuildtest.TestCase):
|
|||
output = subprocess.check_output(["blkid", "--output", "export", device], encoding="utf-8")
|
||||
blkid = dict(line.split("=") for line in output.strip().split("\n"))
|
||||
self.assertEqual(blkid["UUID"], uuid)
|
||||
self.assertEqual(blkid["TYPE"],fstype)
|
||||
self.assertEqual(blkid["TYPE"], fstype)
|
||||
|
||||
with mount(device) as target_tree:
|
||||
tree = f"{self.store}/refs/{tree_id}"
|
||||
|
|
@ -109,10 +108,10 @@ class TestAssemblers(osbuildtest.TestCase):
|
|||
]
|
||||
for filename, compression, expected_mimetypes in cases:
|
||||
options = {
|
||||
"filename": filename,
|
||||
"compression": compression
|
||||
"filename": filename,
|
||||
"compression": compression
|
||||
}
|
||||
tree_id, output_id = self.run_assembler("org.osbuild.tar", options)
|
||||
_, output_id = self.run_assembler("org.osbuild.tar", options)
|
||||
image = f"{self.store}/refs/{output_id}/{filename}"
|
||||
output = subprocess.check_output(["file", "--mime-type", image], encoding="utf-8")
|
||||
_, mimetype = output.strip().split(": ") # "filename: mimetype"
|
||||
|
|
@ -137,7 +136,9 @@ def nbd_connect(image):
|
|||
try:
|
||||
# qemu-nbd doesn't wait for the device to be ready
|
||||
for _ in range(100):
|
||||
if subprocess.run(["nbd-client", "--check", device], check=False, stdout=subprocess.DEVNULL).returncode == 0:
|
||||
if subprocess.run(["nbd-client", "--check", device],
|
||||
check=False,
|
||||
stdout=subprocess.DEVNULL).returncode == 0:
|
||||
break
|
||||
time.sleep(0.2)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
import subprocess
|
||||
import unittest
|
||||
from . import osbuildtest
|
||||
|
||||
|
||||
|
|
@ -9,21 +8,23 @@ class TestBoot(osbuildtest.TestCase):
|
|||
_, output_id = self.run_osbuild("test/pipelines/f30-boot.json")
|
||||
|
||||
r = subprocess.run(["qemu-system-x86_64",
|
||||
"-snapshot",
|
||||
"-m", "1024",
|
||||
"-M", "accel=kvm:hvf:tcg",
|
||||
"-snapshot",
|
||||
"-m", "1024",
|
||||
"-M", "accel=kvm:hvf:tcg",
|
||||
|
||||
# be silent
|
||||
"-nographic",
|
||||
"-monitor", "none",
|
||||
"-serial", "none",
|
||||
# be silent
|
||||
"-nographic",
|
||||
"-monitor", "none",
|
||||
"-serial", "none",
|
||||
|
||||
# create /dev/vport0p1
|
||||
"-chardev", "stdio,id=stdio",
|
||||
"-device", "virtio-serial",
|
||||
"-device", "virtserialport,chardev=stdio",
|
||||
# create /dev/vport0p1
|
||||
"-chardev", "stdio,id=stdio",
|
||||
"-device", "virtio-serial",
|
||||
"-device", "virtserialport,chardev=stdio",
|
||||
|
||||
f"{self.get_path_to_store(output_id)}/f30-boot.qcow2"
|
||||
], encoding="utf-8", stdout=subprocess.PIPE, check=True)
|
||||
f"{self.get_path_to_store(output_id)}/f30-boot.qcow2"],
|
||||
encoding="utf-8",
|
||||
stdout=subprocess.PIPE,
|
||||
check=True)
|
||||
|
||||
self.assertEqual(r.stdout.strip(), "running")
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ class TestObjectStore(unittest.TestCase):
|
|||
# there should be no temporary Objects dirs anymore
|
||||
self.assertEqual(len(os.listdir(object_store.tmp)), 0)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@unittest.skipUnless(can_set_immutable(), "Need root permissions")
|
||||
def test_cleanup_immutable(self):
|
||||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
|
|
@ -98,6 +99,7 @@ class TestObjectStore(unittest.TestCase):
|
|||
subprocess.run(["chattr", "+i", f"{path}/A"],
|
||||
check=True)
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def test_duplicate(self):
|
||||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
object_store = objectstore.ObjectStore(tmp)
|
||||
|
|
@ -122,6 +124,7 @@ class TestObjectStore(unittest.TestCase):
|
|||
assert len(os.listdir(f"{object_store.refs}/a/")) == 1
|
||||
assert len(os.listdir(f"{object_store.refs}/b/")) == 1
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
def test_object_base(self):
|
||||
# operate with a clean object store
|
||||
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ class TestDescriptions(unittest.TestCase):
|
|||
|
||||
cases = [
|
||||
{},
|
||||
{ "assembler": None },
|
||||
{ "stages": [] },
|
||||
{ "build": {} },
|
||||
{ "build": None }
|
||||
{"assembler": None},
|
||||
{"stages": []},
|
||||
{"build": {}},
|
||||
{"build": None}
|
||||
]
|
||||
for pipeline in cases:
|
||||
with self.subTest(pipeline):
|
||||
|
|
@ -23,7 +23,7 @@ class TestDescriptions(unittest.TestCase):
|
|||
|
||||
def test_stage(self):
|
||||
name = "org.osbuild.test"
|
||||
options = { "one": 1 }
|
||||
options = {"one": 1}
|
||||
cases = [
|
||||
(osbuild.Stage(name, {}, None, None, {}), {"name": name}),
|
||||
(osbuild.Stage(name, {}, None, None, None), {"name": name}),
|
||||
|
|
@ -35,7 +35,7 @@ class TestDescriptions(unittest.TestCase):
|
|||
|
||||
def test_assembler(self):
|
||||
name = "org.osbuild.test"
|
||||
options = { "one": 1 }
|
||||
options = {"one": 1}
|
||||
cases = [
|
||||
(osbuild.Assembler(name, None, None, {}), {"name": name}),
|
||||
(osbuild.Assembler(name, None, None, None), {"name": name}),
|
||||
|
|
@ -47,33 +47,33 @@ class TestDescriptions(unittest.TestCase):
|
|||
|
||||
def test_pipeline(self):
|
||||
build = osbuild.Pipeline("org.osbuild.test")
|
||||
build.add_stage("org.osbuild.test", {}, { "one": 1 })
|
||||
build.add_stage("org.osbuild.test", {}, {"one": 1})
|
||||
|
||||
pipeline = osbuild.Pipeline("org.osbuild.test", build)
|
||||
pipeline.add_stage("org.osbuild.test", {}, { "one": 2 })
|
||||
pipeline.add_stage("org.osbuild.test", {}, {"one": 2})
|
||||
pipeline.set_assembler("org.osbuild.test")
|
||||
|
||||
self.assertEqual(pipeline.description(), {
|
||||
"build": {
|
||||
"build": {
|
||||
"pipeline": {
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.test",
|
||||
"options": { "one": 1 }
|
||||
}
|
||||
]
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.test",
|
||||
"options": {"one": 1}
|
||||
}
|
||||
]
|
||||
},
|
||||
"runner": "org.osbuild.test"
|
||||
},
|
||||
"stages": [
|
||||
},
|
||||
"stages": [
|
||||
{
|
||||
"name": "org.osbuild.test",
|
||||
"options": { "one": 2 }
|
||||
"name": "org.osbuild.test",
|
||||
"options": {"one": 2}
|
||||
}
|
||||
],
|
||||
"assembler": {
|
||||
],
|
||||
"assembler": {
|
||||
"name": "org.osbuild.test"
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
def test_stageinfo(self):
|
||||
|
|
|
|||
|
|
@ -15,4 +15,3 @@ class TestOSRelease(unittest.TestCase):
|
|||
for entry in os.scandir("test/os-release"):
|
||||
with self.subTest(entry.name):
|
||||
self.assertEqual(osbuild.pipeline.describe_os(entry.path), entry.name)
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ def have_rpm_ostree():
|
|||
|
||||
class TestObjectStore(unittest.TestCase):
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
@unittest.skipIf(not have_rpm_ostree(), "rpm-ostree missing")
|
||||
def test_treefile_empty(self):
|
||||
# check we produce a valid treefile from an empty object
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import io
|
||||
import unittest
|
||||
import subprocess
|
||||
|
||||
from osbuild.util import selinux
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue