tests: unittest and pytest expect functions to start with test_

This commit is contained in:
Brian C. Lane 2020-01-14 17:43:46 -08:00
parent 9bb1a0916e
commit d265824564
9 changed files with 96 additions and 96 deletions

View File

@ -41,12 +41,12 @@ def mkFakeBoot(root_dir):
class CreatorTest(unittest.TestCase):
def fakednf_test(self):
def test_fakednf(self):
"""Test FakeDNF class"""
fake_dbo = FakeDNF(conf=DataHolder(installroot="/a/fake/install/root/"))
self.assertEqual(fake_dbo.conf.installroot, "/a/fake/install/root/")
def squashfs_args_test(self):
def test_squashfs_args(self):
"""Test squashfs_args results"""
test_arches = {"x86_64": ("xz", ["-Xbcj", "x86"]),
"ppc64le": ("xz", ["-Xbcj", "powerpc"]),
@ -68,7 +68,7 @@ class CreatorTest(unittest.TestCase):
opts = DataHolder(compression="xz", compress_args=["-X32767", "-Xbcj x86"], arch="x86_64")
self.assertEqual(squashfs_args(opts), ("xz", ["-X32767", "-Xbcj", "x86"]), (opts, squashfs_args(opts)))
def make_appliance_test(self):
def test_make_appliance(self):
"""Test creating the appliance description XML file"""
lorax_templates = find_templates("./share/")
appliance_template = joinpaths(lorax_templates, "appliance/libvirt.tmpl")
@ -102,7 +102,7 @@ class CreatorTest(unittest.TestCase):
self.assertEqual(storage.find("./disk/checksum").get("type"), "sha256")
self.assertEqual(storage.find("./disk/checksum").text, "90611458b33009998f73e25ccc3766b31a8b548cc6c2d84f78ae0e84d64e10a5")
def pxe_config_test(self):
def test_pxe_config(self):
"""Test creation of a PXE config file"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
live_image_name = "live-rootfs.squashfs.img"
@ -122,7 +122,7 @@ class CreatorTest(unittest.TestCase):
self.assertTrue("initramfs-4.18.13-200.fc28.x86_64.img" in pxe_config)
self.assertTrue("/live-rootfs.squashfs.img ostree=/mnt/sysimage/" in pxe_config)
def make_runtime_squashfs_test(self):
def test_make_runtime_squashfs(self):
"""Test making a runtime squashfs only image"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.TemporaryDirectory(prefix="lorax.test.root.") as mount_dir:
@ -146,7 +146,7 @@ class CreatorTest(unittest.TestCase):
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def make_runtime_squashfs_ext4_test(self):
def test_make_runtime_squashfs_ext4(self):
"""Test making a runtime squashfs+ext4 only image"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.TemporaryDirectory(prefix="lorax.test.root.") as mount_dir:
@ -168,7 +168,7 @@ class CreatorTest(unittest.TestCase):
results = runcmd_output(cmd)
self.assertTrue("rootfs.img" in results)
def get_arch_test(self):
def test_get_arch(self):
"""Test getting the arch of the installed kernel"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
# Make a fake kernel and initrd
@ -176,13 +176,13 @@ class CreatorTest(unittest.TestCase):
arch = get_arch(work_dir)
self.assertTrue(arch == "x86_64")
def find_ostree_root_test(self):
def test_find_ostree_root(self):
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
ostree_path = "ostree/boot.1/apu/c8f294c479fc948375a001f06bc524d02900d32c6a1a72061a1dc281e9e93e41/0"
os.makedirs(joinpaths(work_dir, ostree_path))
self.assertEqual(find_ostree_root(work_dir), ostree_path)
def good_ks_novirt_test(self):
def test_good_ks_novirt(self):
"""Test a good kickstart with novirt"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_pxe_live=False)
ks_version = makeVersion()
@ -194,7 +194,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(check_kickstart(ks, opts), [])
def good_ks_virt_test(self):
def test_good_ks_virt(self):
"""Test a good kickstart with virt"""
opts = DataHolder(no_virt=False, make_fsimage=False, make_pxe_live=False)
ks_version = makeVersion()
@ -206,7 +206,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(check_kickstart(ks, opts), [])
def nomethod_novirt_test(self):
def test_nomethod_novirt(self):
"""Test a kickstart with repo and no url"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_pxe_live=False)
ks_version = makeVersion()
@ -219,7 +219,7 @@ class CreatorTest(unittest.TestCase):
self.assertTrue("Only url, nfs and ostreesetup" in errors[0])
self.assertTrue("repo can only be used with the url" in errors[1])
def no_network_test(self):
def test_no_network(self):
"""Test a kickstart with missing network command"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_pxe_live=False)
ks_version = makeVersion()
@ -230,7 +230,7 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("The kickstart must activate networking" in errors[0])
def displaymode_test(self):
def test_displaymode(self):
"""Test a kickstart with displaymode set"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_pxe_live=False)
ks_version = makeVersion()
@ -244,7 +244,7 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("must not set a display mode" in errors[0])
def autopart_test(self):
def test_autopart(self):
"""Test a kickstart with autopart"""
opts = DataHolder(no_virt=True, make_fsimage=True, make_pxe_live=False)
ks_version = makeVersion()
@ -257,7 +257,7 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("Filesystem images must use a single" in errors[0])
def boot_part_test(self):
def test_boot_part(self):
"""Test a kickstart with a boot partition"""
opts = DataHolder(no_virt=True, make_fsimage=True, make_pxe_live=False)
ks_version = makeVersion()
@ -271,7 +271,7 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("Filesystem images must use a single" in errors[0])
def shutdown_virt_test(self):
def test_shutdown_virt(self):
"""Test a kickstart with reboot instead of shutdown"""
opts = DataHolder(no_virt=False, make_fsimage=True, make_pxe_live=False)
ks_version = makeVersion()
@ -284,7 +284,7 @@ class CreatorTest(unittest.TestCase):
errors = check_kickstart(ks, opts)
self.assertTrue("must include shutdown when using virt" in errors[0])
def disk_size_simple_test(self):
def test_disk_size_simple(self):
"""Test calculating the disk size with a simple / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False, image_size_align=0)
ks_version = makeVersion()
@ -296,7 +296,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4098)
def disk_size_boot_test(self):
def test_disk_size_boot(self):
"""Test calculating the disk size with / and /boot partitions"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False, image_size_align=0)
ks_version = makeVersion()
@ -309,7 +309,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4610)
def disk_size_boot_fsimage_test(self):
def test_disk_size_boot_fsimage(self):
"""Test calculating the disk size with / and /boot partitions on a fsimage"""
opts = DataHolder(no_virt=True, make_fsimage=True, make_iso=False, make_pxe_live=False, image_size_align=0)
ks_version = makeVersion()
@ -322,7 +322,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4098)
def disk_size_reqpart_test(self):
def test_disk_size_reqpart(self):
"""Test calculating the disk size with reqpart and a / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False, image_size_align=0)
ks_version = makeVersion()
@ -335,7 +335,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 4598)
def disk_size_reqpart_boot_test(self):
def test_disk_size_reqpart_boot(self):
"""Test calculating the disk size with reqpart --add-boot and a / partition"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False, image_size_align=0)
ks_version = makeVersion()
@ -348,7 +348,7 @@ class CreatorTest(unittest.TestCase):
"shutdown\n")
self.assertEqual(calculate_disk_size(opts, ks), 5622)
def disk_size_align_test(self):
def test_disk_size_align(self):
"""Test aligning the disk size"""
opts = DataHolder(no_virt=True, make_fsimage=False, make_iso=False, make_pxe_live=False, image_size_align=1024)
ks_version = makeVersion()
@ -361,7 +361,7 @@ class CreatorTest(unittest.TestCase):
self.assertEqual(calculate_disk_size(opts, ks), 5120)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def boot_over_root_test(self):
def test_boot_over_root(self):
"""Test the mount_boot_part_over_root ostree function"""
# Make a fake disk image with a / and a /boot/loader.0
# Mount the / partition

View File

@ -20,7 +20,7 @@ import tempfile
from pylorax.discinfo import DiscInfo
class DiscInfoTest(unittest.TestCase):
def discinfo_test(self):
def test_discinfo(self):
with tempfile.NamedTemporaryFile(mode="w+t") as f:
di = DiscInfo("1.0", "x86_64")
di.write(f.name)

View File

@ -24,7 +24,7 @@ from pylorax.executils import execWithRedirect, execWithCapture, execReadlines
from pylorax.executils import runcmd, runcmd_output, setenv
class ExecUtilsTest(unittest.TestCase):
def startProgram_test(self):
def test_startProgram(self):
cmd = ["python3", "-c", "import os; print(os.environ['LC_ALL'])"]
proc = startProgram(cmd, reset_lang=True)
(stdout, _stderr) = proc.communicate()
@ -40,7 +40,7 @@ class ExecUtilsTest(unittest.TestCase):
(stdout, _stderr) = proc.communicate()
self.assertEqual(stdout.strip(), b"False")
def childenv_test(self):
def test_childenv(self):
"""Test setting a child environmental variable"""
setenv("LORAX_CHILD_TEST", "mustard IS progress")
cmd = ["python3", "-c", "import os; print(os.environ['LORAX_CHILD_TEST'])"]
@ -49,7 +49,7 @@ class ExecUtilsTest(unittest.TestCase):
(stdout, _stderr) = proc.communicate()
self.assertEqual(stdout.strip(), b"mustard IS progress")
def execWithRedirect_test(self):
def test_execWithRedirect(self):
import logging
logger = logging.getLogger("pylorax")
logger.addHandler(logging.NullHandler())
@ -72,46 +72,46 @@ class ExecUtilsTest(unittest.TestCase):
os.unlink(tmp_f.name)
program_log.removeHandler(fh)
def execWithCapture_test(self):
def test_execWithCapture(self):
cmd = ["python3", "-c", "import sys; print('Truffula trees.', end=''); sys.exit(0)"]
stdout = execWithCapture(cmd[0], cmd[1:], callback=lambda p: True)
self.assertEqual(stdout.strip(), "Truffula trees.")
def returncode_test(self):
def test_returncode(self):
cmd = ["python3", "-c", "import sys; print('Truffula trees.'); sys.exit(1)"]
with self.assertRaises(CalledProcessError):
execWithCapture(cmd[0], cmd[1:], raise_err=True)
def exec_filter_stderr_test(self):
def test_exec_filter_stderr(self):
cmd = ["python3", "-c", "import sys; print('Truffula trees.', file=sys.stderr); sys.exit(0)"]
stdout = execWithCapture(cmd[0], cmd[1:], filter_stderr=True)
self.assertEqual(stdout.strip(), "")
def execReadlines_test(self):
def test_execReadlines(self):
cmd = ["python3", "-c", "import sys; print('Truffula trees.'); sys.exit(0)"]
iterator = execReadlines(cmd[0], cmd[1:], callback=lambda p: True, filter_stderr=True)
self.assertEqual(list(iterator), ["Truffula trees."])
def execReadlines_error_test(self):
def test_execReadlines_error(self):
with self.assertRaises(OSError):
execReadlines("foo-prog", [])
def del_execReadlines_test(self):
def test_del_execReadlines(self):
cmd = ["python3", "-c", "import sys; print('Truffula trees.'); sys.exit(0)"]
iterator = execReadlines(cmd[0], cmd[1:], callback=lambda p: True)
del iterator
def runcmd_test(self):
def test_runcmd(self):
cmd = ["python3", "-c", "import sys; print('Theodor Seuss Geisel'); sys.exit(0)"]
rc = runcmd(cmd)
self.assertEqual(rc, 0)
def runcmd_output_test(self):
def test_runcmd_output(self):
cmd = ["python3", "-c", "import sys; print('Everyone needs Thneeds'); sys.exit(0)"]
stdout = runcmd_output(cmd)
self.assertEqual(stdout.strip(), "Everyone needs Thneeds")
def chroot_test(self):
def test_chroot(self):
"""Test the preexec function"""
cmd = ["python3", "-c", "import sys; print('Failure is always an option'); sys.exit(0)"]
@ -119,7 +119,7 @@ class ExecUtilsTest(unittest.TestCase):
with self.assertRaises(FileNotFoundError):
startProgram(cmd, root="/tmp/")
def preexec_test(self):
def test_preexec(self):
"""Test the preexec function"""
cmd = ["python3", "-c", "import sys; print('Failure is always an option'); sys.exit(0)"]

View File

@ -54,7 +54,7 @@ class GitArchiveTest(unittest.TestCase):
finally:
shutil.rmtree(tardir)
def git_branch_test(self):
def test_git_branch(self):
"""Test creating an archive from a git branch"""
git_repo = toml.loads("""
[[repos.git]]
@ -69,7 +69,7 @@ class GitArchiveTest(unittest.TestCase):
archive = GitArchiveTarball(git_repo["repos"]["git"][0])
self._check_tar(archive, "git-rpm-test/", "branch")
def git_commit_test(self):
def test_git_commit(self):
"""Test creating an archive from a git commit hash"""
git_repo = toml.loads("""
[[repos.git]]
@ -84,7 +84,7 @@ class GitArchiveTest(unittest.TestCase):
archive = GitArchiveTarball(git_repo["repos"]["git"][0])
self._check_tar(archive, "git-rpm-test/", "first")
def git_tag_test(self):
def test_git_tag(self):
"""Test creating an archive from a git tag"""
git_repo = toml.loads("""
[[repos.git]]
@ -99,7 +99,7 @@ class GitArchiveTest(unittest.TestCase):
archive = GitArchiveTarball(git_repo["repos"]["git"][0])
self._check_tar(archive, "git-rpm-test/", "second")
def git_fail_repo_test(self):
def test_git_fail_repo(self):
"""Test creating an archive from a bad url"""
git_repo = toml.loads("""
[[repos.git]]
@ -116,7 +116,7 @@ class GitArchiveTest(unittest.TestCase):
self._check_tar(archive, "git-rpm-test/", None)
self.assertIn("Failed to clone", str(e.exception))
def git_fail_ref_test(self):
def test_git_fail_ref(self):
"""Test creating an archive from a bad ref"""
git_repo = toml.loads("""
[[repos.git]]
@ -162,7 +162,7 @@ class GitRpmTest(unittest.TestCase):
# / should never be included in the rpm, doing so conflicts with the filesystem package
self.assertFalse(any(True for f in files if f == "/"))
def git_branch_test(self):
def test_git_branch(self):
"""Test creating an rpm from a git branch"""
git_repo = toml.loads("""
[[repos.git]]
@ -181,7 +181,7 @@ class GitRpmTest(unittest.TestCase):
finally:
shutil.rmtree(rpm_dir)
def git_commit_test(self):
def test_git_commit(self):
"""Test creating an rpm from a git commit hash"""
git_repo = toml.loads("""
[[repos.git]]
@ -200,7 +200,7 @@ class GitRpmTest(unittest.TestCase):
finally:
shutil.rmtree(rpm_dir)
def git_tag_test(self):
def test_git_tag(self):
"""Test creating an rpm from a git tag"""
git_repo = toml.loads("""
[[repos.git]]
@ -219,7 +219,7 @@ class GitRpmTest(unittest.TestCase):
finally:
shutil.rmtree(rpm_dir)
def gitrpm_repo_test(self):
def test_gitrpm_repo(self):
"""Test creating a dnf repo of the git rpms"""
recipe = toml.loads("""
[[repos.git]]
@ -251,7 +251,7 @@ class GitRpmTest(unittest.TestCase):
finally:
shutil.rmtree(temp_dir)
def git_root_test(self):
def test_git_root(self):
"""Test creating an rpm with / as the destination """
git_repo = toml.loads("""
[[repos.git]]
@ -272,14 +272,14 @@ class GitRpmTest(unittest.TestCase):
class GitRpmBuildTest(unittest.TestCase):
def get_base_dir_test(self):
def test_get_base_dir(self):
"""Make sure base_dir is created"""
gitRpm = GitRpmBuild("rpmtest", "1.0.0", "1", ["noarch"])
base_dir = gitRpm.get_base_dir()
self.assertTrue("lorax-git-rpm" in base_dir)
gitRpm.cleanup_tmpdir()
def short_base_dir_test(self):
def test_short_base_dir(self):
"""Make sure cleanup of an unusually short base_dir fails"""
gitRpm = GitRpmBuild("rpmtest", "1.0.0", "1", ["noarch"])
gitRpm._base_dir = "/aa/"

View File

@ -117,7 +117,7 @@ def mkfakediskimg(disk_img):
return True
class ImgUtilsTest(unittest.TestCase):
def mkcpio_test(self):
def test_mkcpio(self):
"""Test mkcpio function"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -128,7 +128,7 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue("cpio" in file_details, file_details)
def mktar_test(self):
def test_mktar(self):
"""Test mktar function"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -139,7 +139,7 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue("POSIX tar" in file_details, file_details)
def compressed_mktar_test(self):
def test_compressed_mktar(self):
"""Test compressed mktar function"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -155,7 +155,7 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue(magic in file_details, (compression, magic, file_details))
def mktar_single_file_test(self):
def test_mktar_single_file(self):
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img,\
tempfile.NamedTemporaryFile(prefix="lorax.test.input.") as input_file:
mktar(input_file.name, disk_img.name, compression=None)
@ -166,7 +166,7 @@ class ImgUtilsTest(unittest.TestCase):
with tarfile.TarFile(disk_img.name) as t:
self.assertEqual(t.getnames(), [os.path.basename(input_file.name)])
def mksquashfs_test(self):
def test_mksquashfs(self):
"""Test mksquashfs function"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -178,13 +178,13 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue("Squashfs" in file_details, file_details)
def mksparse_test(self):
def test_mksparse(self):
"""Test mksparse function"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
self.assertEqual(os.stat(disk_img.name).st_size, 42 * 1024**2)
def mkqcow2_test(self):
def test_mkqcow2(self):
"""Test mkqcow2 function"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mkqcow2(disk_img.name, 42 * 1024**2)
@ -193,7 +193,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue(str(42 * 1024**2) in file_details, file_details)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def loop_test(self):
def test_loop(self):
"""Test the loop_* functions (requires loop support)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
@ -205,7 +205,7 @@ class ImgUtilsTest(unittest.TestCase):
loop_detach(loop_dev)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def loop_context_test(self):
def test_loop_context(self):
"""Test the LoopDev context manager (requires loop)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
@ -214,7 +214,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertEqual(loop_dev[5:], get_loop_name(disk_img.name))
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def dm_test(self):
def test_dm(self):
"""Test the dm_* functions (requires device-mapper support)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
@ -227,7 +227,7 @@ class ImgUtilsTest(unittest.TestCase):
dm_detach(dm_name)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def dmdev_test(self):
def test_dmdev(self):
"""Test the DMDev context manager (requires device-mapper support)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
@ -237,7 +237,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue(dm_name is not None)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mount_test(self):
def test_mount(self):
"""Test the Mount context manager (requires loop)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
mksparse(disk_img.name, 42 * 1024**2)
@ -248,7 +248,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue(mnt is not None)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mkdosimg_test(self):
def test_mkdosimg(self):
"""Test mkdosimg function (requires loop)"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -259,7 +259,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue("FAT " in file_details, file_details)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mkext4img_test(self):
def test_mkext4img(self):
"""Test mkext4img function (requires loop)"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -271,7 +271,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue("ext2 filesystem" in file_details, file_details)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mkbtrfsimg_test(self):
def test_mkbtrfsimg(self):
"""Test mkbtrfsimg function (requires loop)"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -282,7 +282,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue("BTRFS Filesystem" in file_details, file_details)
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mkhfsimg_test(self):
def test_mkhfsimg(self):
"""Test mkhfsimg function (requires loop)"""
with tempfile.TemporaryDirectory(prefix="lorax.test.") as work_dir:
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
@ -292,14 +292,14 @@ class ImgUtilsTest(unittest.TestCase):
file_details = get_file_magic(disk_img.name)
self.assertTrue("Macintosh HFS" in file_details, file_details)
def default_image_name_test(self):
def test_default_image_name(self):
"""Test default_image_name function"""
for compression, suffix in [("xz", ".xz"), ("gzip", ".gz"), ("bzip2", ".bz2"), ("lzma", ".lzma")]:
filename = default_image_name(compression, "foobar")
self.assertTrue(filename.endswith(suffix))
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def partition_mount_test(self):
def test_partition_mount(self):
"""Test PartitionMount context manager (requires loop)"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
self.assertTrue(mkfakediskimg(disk_img.name))
@ -328,7 +328,7 @@ class ImgUtilsTest(unittest.TestCase):
self.assertTrue(os.path.exists(joinpaths(img_mount.mount_dir, "initramfs-4.18.13-200.fc28.x86_64.img")))
@unittest.skipUnless(os.geteuid() == 0 and not os.path.exists("/.in-container"), "requires root privileges, and no containers")
def mkfsimage_from_disk_test(self):
def test_mkfsimage_from_disk(self):
"""Test creating a fsimage from the / partition of a disk image"""
with tempfile.NamedTemporaryFile(prefix="lorax.test.disk.") as disk_img:
self.assertTrue(mkfakediskimg(disk_img.name))

View File

@ -163,13 +163,13 @@ class BasicRecipeTest(unittest.TestCase):
def tearDownClass(self):
pass
def toml_to_recipe_test(self):
def test_toml_to_recipe(self):
"""Test converting the TOML string to a Recipe object"""
for (toml_str, recipe_dict) in self.input_toml.values():
result = recipes.recipe_from_toml(toml_str)
self.assertEqual(result, recipe_dict)
def toml_to_recipe_fail_test(self):
def test_toml_to_recipe_fail(self):
"""Test trying to convert a non-TOML string to a Recipe"""
with self.assertRaises(TomlError):
recipes.recipe_from_toml("This is not a TOML string\n")
@ -177,7 +177,7 @@ class BasicRecipeTest(unittest.TestCase):
with self.assertRaises(recipes.RecipeError):
recipes.recipe_from_toml('name = "a failed toml string"\n')
def recipe_to_toml_test(self):
def test_recipe_to_toml(self):
"""Test converting a Recipe object to a TOML string"""
# In order to avoid problems from matching strings we convert to TOML and
# then back so compare the Recipes.
@ -189,7 +189,7 @@ class BasicRecipeTest(unittest.TestCase):
recipe_2 = recipes.recipe_from_toml(toml_2)
self.assertEqual(recipe_1, recipe_2)
def recipe_bump_version_test(self):
def test_recipe_bump_version(self):
"""Test the Recipe's version bump function"""
# Neither have a version
@ -217,7 +217,7 @@ class BasicRecipeTest(unittest.TestCase):
new_version = recipe.bump_version("0.0.1")
self.assertEqual(new_version, "0.1.1")
def find_field_test(self):
def test_find_field(self):
"""Test the find_field_value function"""
test_list = [{"name":"dog"}, {"name":"cat"}, {"name":"squirrel"}]
@ -226,7 +226,7 @@ class BasicRecipeTest(unittest.TestCase):
self.assertIsNone(recipes.find_field_value("color", "green", test_list))
self.assertIsNone(recipes.find_field_value("color", "green", []))
def find_name_test(self):
def test_find_name(self):
"""Test the find_name function"""
test_list = [{"name":"dog"}, {"name":"cat"}, {"name":"squirrel"}]
@ -234,7 +234,7 @@ class BasicRecipeTest(unittest.TestCase):
self.assertIsNone(recipes.find_name("alien", test_list))
self.assertIsNone(recipes.find_name("alien", []))
def find_obj_test(self):
def test_find_obj(self):
"""Test the find_recipe_obj function"""
test_recipe = {"customizations": {"hostname": "foo", "users": ["root"]}, "repos": {"git": ["git-repos"]}}
@ -244,7 +244,7 @@ class BasicRecipeTest(unittest.TestCase):
self.assertEqual(recipes.find_recipe_obj(["repos", "git", "oak"], test_recipe, ""), "")
self.assertIsNone(recipes.find_recipe_obj(["pine"], test_recipe))
def diff_lists_test(self):
def test_diff_lists(self):
"""Test the diff_lists function"""
self.assertEqual(recipes.diff_lists("Modules", "name", self.old_modules, self.old_modules), [])
self.assertEqual(recipes.diff_lists("Modules", "name", self.old_modules, self.new_modules), self.modules_result)
@ -253,13 +253,13 @@ class BasicRecipeTest(unittest.TestCase):
self.assertEqual(recipes.diff_lists("Repos.git", "rpmname", self.old_git, self.new_git), self.git_result)
self.assertEqual(recipes.diff_lists("Repos.git", "rpmname", self.old_git, sorted(self.new_git, reverse=True, key=lambda o: o["rpmname"].lower())), self.git_result)
def customizations_diff_test(self):
def test_customizations_diff(self):
"""Test the customizations_diff function"""
old_recipe = recipes.Recipe("test-recipe", "A recipe used for testing", "0.1.1", [], [], [], customizations=self.old_custom)
new_recipe = recipes.Recipe("test-recipe", "A recipe used for testing", "0.3.1", [], [], [], customizations=self.new_custom)
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), self.custom_result)
def customizations_diff_services_test(self):
def test_customizations_diff_services(self):
"""Test the customizations_diff function with services variations"""
# Test adding the services customization
old_custom = self.old_custom.copy()
@ -296,7 +296,7 @@ class BasicRecipeTest(unittest.TestCase):
'new': {'Customizations.services': {'disabled': ['postfix', 'telnetd']}}}]
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), result)
def customizations_diff_firewall_test(self):
def test_customizations_diff_firewall(self):
"""Test the customizations_diff function with firewall variations"""
# Test adding the firewall customization
old_custom = self.old_custom.copy()
@ -360,7 +360,7 @@ class BasicRecipeTest(unittest.TestCase):
'new': {'Customizations.firewall': {'services': {'disabled': ['telnet']}}}}]
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), result)
def customizations_diff_locale_test(self):
def test_customizations_diff_locale(self):
"""Test the customizations_diff function with locale variations"""
# Test adding the locale customization
old_custom = self.old_custom.copy()
@ -397,7 +397,7 @@ class BasicRecipeTest(unittest.TestCase):
'new': {'Customizations.locale': {'keyboard': 'us'}}}]
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), result)
def customizations_diff_timezone_test(self):
def test_customizations_diff_timezone(self):
"""Test the customizations_diff function with timezone variations"""
# Test adding the timezone customization
old_custom = self.old_custom.copy()
@ -435,7 +435,7 @@ class BasicRecipeTest(unittest.TestCase):
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), result)
def customizations_diff_sshkey_test(self):
def test_customizations_diff_sshkey(self):
"""Test the customizations_diff function with sshkey variations"""
# Test changed root ssh key
old_custom = self.old_custom.copy()
@ -471,7 +471,7 @@ class BasicRecipeTest(unittest.TestCase):
'new': None}]
self.assertEqual(recipes.customizations_diff(old_recipe, new_recipe), result)
def customizations_diff_user_test(self):
def test_customizations_diff_user(self):
"""Test the customizations_diff function with user variations"""
# Test changed admin user
old_custom = self.old_custom.copy()
@ -525,7 +525,7 @@ class BasicRecipeTest(unittest.TestCase):
def recipe_diff_test(self):
def test_recipe_diff(self):
"""Test the recipe_diff function"""
old_recipe = recipes.Recipe("test-recipe", "A recipe used for testing", "0.1.1", self.old_modules, self.old_packages, [], gitrepos=self.old_git)
new_recipe = recipes.Recipe("test-recipe", "A recipe used for testing", "0.3.1", self.new_modules, self.new_packages, [], gitrepos=self.new_git)
@ -592,7 +592,7 @@ class BasicRecipeTest(unittest.TestCase):
self.assertEqual(recipes.recipe_diff(old_recipe, new_recipe), result)
def recipe_freeze_test(self):
def test_recipe_freeze(self):
"""Test the recipe freeze() function"""
# Use the repos-git.toml test, it only has http and php in it
deps = [{"arch": "x86_64",

View File

@ -23,7 +23,7 @@ from pylorax.sysutils import joinpaths, touch, replace, chown_, chmod_, remove,
from pylorax.sysutils import _read_file_end
class SysUtilsTest(unittest.TestCase):
def joinpaths_test(self):
def test_joinpaths(self):
self.assertEqual(joinpaths("foo", "bar", "baz"), "foo/bar/baz")
with tempfile.TemporaryDirectory() as tdname:
@ -33,14 +33,14 @@ class SysUtilsTest(unittest.TestCase):
self.assertEqual(joinpaths(tdname, "link-file", follow_symlinks=True),
os.path.join(tdname, "real-file"))
def touch_test(self):
def test_touch(self):
touch_file="/var/tmp/lorax-test-touch-file"
touch(touch_file)
self.assertTrue(os.path.exists(touch_file))
os.unlink(touch_file)
def replace_test(self):
def test_replace(self):
f = tempfile.NamedTemporaryFile(mode="w+t", delete=False)
f.write("A few words to apply @AARDVARKS@ testing\n")
f.close()
@ -50,22 +50,22 @@ class SysUtilsTest(unittest.TestCase):
os.unlink(f.name)
@unittest.skipUnless(os.geteuid() == 0, "requires root privileges")
def chown_test(self):
def test_chown(self):
with tempfile.NamedTemporaryFile() as f:
chown_(f.name, "nobody", "nobody")
def chmod_test(self):
def test_chmod(self):
with tempfile.NamedTemporaryFile() as f:
chmod_(f.name, 0o777)
self.assertEqual(os.stat(f.name).st_mode, 0o100777)
def remove_test(self):
def test_remove(self):
remove_file="/var/tmp/lorax-test-remove-file"
open(remove_file, "w").write("test was here")
remove(remove_file)
self.assertFalse(os.path.exists(remove_file))
def linktree_test(self):
def test_linktree(self):
with tempfile.TemporaryDirectory() as tdname:
path = os.path.join("one", "two", "three")
os.makedirs(os.path.join(tdname, path))
@ -86,7 +86,7 @@ class SysUtilsTest(unittest.TestCase):
bio.seek(0)
return bio
def read_file_end_test(self):
def test_read_file_end(self):
"""Test reading from the end of a file"""
self.maxDiff = None

View File

@ -30,7 +30,7 @@ class TimestampTest(unittest.TestCase):
def tearDownClass(self):
shutil.rmtree(self.test_dir)
def timestamp_test(self):
def test_timestamp(self):
"""Test writing and reading compose timestamps"""
write_timestamp(self.test_dir, TS_CREATED)
ts = timestamp_dict(self.test_dir)

View File

@ -22,7 +22,7 @@ import os
from pylorax.treeinfo import TreeInfo
class TreeInfoTest(unittest.TestCase):
def treeinfo_test(self):
def test_treeinfo(self):
with tempfile.NamedTemporaryFile() as f:
ti = TreeInfo("Lorax-Test", "1.0", "Server", "x86_64", "Packages")
ti.add_section("images", {"initrd": "images/pxeboot/initrd.img",
@ -43,7 +43,7 @@ class TreeInfoTest(unittest.TestCase):
self.assertEqual(config.get("images", "initrd"), "images/pxeboot/initrd.img")
self.assertEqual(config.get("images", "kernel"), "images/pxeboot/vmlinuz")
def source_time_test(self):
def test_source_time(self):
"""Test treeinfo with SOURCE_DATE_EPOCH environmental variable set"""
os.environ["SOURCE_DATE_EPOCH"] = str(499137660)
with tempfile.NamedTemporaryFile() as f: