1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
import os
import subprocess
import pytest
pycdlib_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
pycdlib_exe = os.path.join(pycdlib_root, 'tools', 'pycdlib-genisoimage')
def find_executable(executable):
paths = os.environ['PATH'].split(os.pathsep)
if os.path.isfile(executable):
return executable
else:
for p in paths:
f = os.path.join(p, executable)
if os.path.isfile(f):
return f
return None
class ProcessException(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
def run_process(cmdline):
if not 'LD_LIBRARY_PATH' in os.environ:
os.environ['LD_LIBRARY_PATH'] = ''
process = subprocess.Popen(cmdline,
env={
'LD_LIBRARY_PATH': os.environ['LD_LIBRARY_PATH'],
'PATH': os.environ['PATH'],
'PYTHONPATH': pycdlib_root,
},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = process.communicate()
ret = process.wait()
if ret != 0:
raise ProcessException('Process failed: %s\n%s' % (out, err))
return out, err
@pytest.mark.skipif(find_executable('isosize') is None or
find_executable('isovfy') is None,
reason='isosize not installed')
def test_pycdlib_genisoimage_nofiles(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'nofiles'
indir.mkdir()
outfile = str(indir) + '.iso'
def _do_test(binary):
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-o',
str(outfile), str(indir)])
run_process(['isovfy', str(outfile)])
out, err = run_process(['isosize', str(outfile)])
size = int(out.strip())
assert(size == 49152)
_do_test('genisoimage')
_do_test(pycdlib_exe)
@pytest.mark.skipif(find_executable('isosize') is None or
find_executable('isovfy') is None or
find_executable('iso-read') is None,
reason='isosize not installed')
def test_pycdlib_genisoimage_onedir(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'onedir'
indir.mkdir()
outfile = str(indir) + '.iso'
dir1 = newdir = indir / 'dir1'
newdir.mkdir()
with open(os.path.join(str(dir1), 'foo'), 'wb') as outfp:
outfp.write(b'foo\n')
def _do_test(binary):
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-o',
str(outfile), str(indir)])
run_process(['isovfy', str(outfile)])
out, err = run_process(['isosize', str(outfile)])
genisoimage_size = int(out.strip())
assert(genisoimage_size == 53248)
foocheck = os.path.join(str(tmp_path), 'foocheck')
out, err = run_process(['iso-read', '-i', str(outfile), '-e', 'dir1/foo', '-o', foocheck])
with open(foocheck, 'rb') as infp:
assert(infp.read() == b'foo\n')
_do_test('genisoimage')
_do_test(pycdlib_exe)
@pytest.mark.skipif(find_executable('isosize') is None or
find_executable('isovfy') is None or
find_executable('iso-read') is None,
reason='isosize not installed')
def test_pycdlib_genisoimage_onefile(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'onedir'
indir.mkdir()
outfile = str(indir) + '.iso'
with open(os.path.join(str(indir), 'foo'), 'wb') as outfp:
outfp.write(b'foo\n')
def _do_test(binary):
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-o',
str(outfile), str(indir)])
run_process(['isovfy', str(outfile)])
out, err = run_process(['isosize', str(outfile)])
genisoimage_size = int(out.strip())
assert(genisoimage_size == 51200)
foocheck = os.path.join(str(tmp_path), 'foocheck')
out, err = run_process(['iso-read', '-i', str(outfile), '-e', 'foo', '-o', foocheck])
with open(foocheck, 'rb') as infp:
assert(infp.read() == b'foo\n')
_do_test('genisoimage')
_do_test(pycdlib_exe)
@pytest.mark.skipif(find_executable('isosize') is None or
find_executable('isovfy') is None or
find_executable('iso-read') is None,
reason='isosize not installed')
def test_pycdlib_genisoimage_file_cmdline(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'onedir'
indir.mkdir()
outfile = str(indir) + '.iso'
foofile = os.path.join(str(indir), 'foo')
with open(foofile, 'wb') as outfp:
outfp.write(b'foo\n')
def _do_test(binary):
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-o',
str(outfile), foofile])
run_process(['isovfy', str(outfile)])
out, err = run_process(['isosize', str(outfile)])
genisoimage_size = int(out.strip())
assert(genisoimage_size == 51200)
foocheck = os.path.join(str(tmp_path), 'foocheck')
out, err = run_process(['iso-read', '-i', str(outfile), '-e', 'foo', '-o', foocheck])
with open(foocheck, 'rb') as infp:
assert(infp.read() == b'foo\n')
_do_test('genisoimage')
_do_test(pycdlib_exe)
@pytest.mark.skipif(find_executable('isosize') is None or
find_executable('isovfy') is None or
find_executable('iso-read') is None,
reason='isosize not installed')
def test_pycdlib_genisoimage_boot_file_cmdline(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'onedir'
indir.mkdir()
outfile = str(indir) + '.iso'
bootfile = os.path.join(str(indir), 'boot')
with open(bootfile, 'wb') as outfp:
outfp.write(b'boot\n')
def _do_test(binary):
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-b', 'boot',
'-c', 'boot.cat', '-no-emul-boot', '-o', str(outfile),
bootfile])
run_process(['isovfy', str(outfile)])
out, err = run_process(['isosize', str(outfile)])
genisoimage_size = int(out.strip())
assert(genisoimage_size == 55296)
bootcheck = os.path.join(str(tmp_path), 'bootcheck')
out, err = run_process(['iso-read', '-i', str(outfile), '-e', 'boot', '-o', bootcheck])
with open(bootcheck, 'rb') as infp:
assert(infp.read() == b'boot\n')
_do_test('genisoimage')
_do_test(pycdlib_exe)
def test_pycdlib_genisoimage_bootfile_bad(tmp_path):
# First set things up, and generate the ISO with genisoimage.
indir = tmp_path / 'onedir'
indir.mkdir()
outfile = str(indir) + '.iso'
def _do_test(binary):
try:
run_process([binary, '-v', '-iso-level', '1', '-no-pad', '-b', 'boot',
'-c', 'boot.cat', '-no-emul-boot', '-o', str(outfile),
str(indir)])
except ProcessException as e:
err1 = "Uh oh, I cant find the boot image 'boot'" in str(e)
assert(err1)
_do_test('genisoimage')
_do_test(pycdlib_exe)
|