/usr/lib/python2.7/dist-packages/linaro_image_tools/hwpack/tests/test_hwpack_converter.py is in python-linaro-image-tools 2016.05-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | # Copyright (C) 2010, 2011, 2012 Linaro
#
# Author: Milo Casagrande <milo.casagrande@linaro.org>
#
# This file is part of Linaro Image Tools.
#
# Linaro Image Tools is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# Linaro Image Tools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Linaro Image Tools; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
import tempfile
from linaro_image_tools.testing import TestCaseWithFixtures
from linaro_image_tools.tests.fixtures import (
CreateTempDirFixture,
CreateTempFileFixture,
)
from linaro_image_tools.hwpack.hwpack_convert import (
HwpackConverter,
HwpackConverterException,
check_and_validate_args,
)
class Args():
"""Defines the args for the command line options."""
def __init__(self, input_file, output_file=None):
self.CONFIG_FILE = input_file
self.out = output_file
class HwpackConverterTests(TestCaseWithFixtures):
"""Test class for the hwpack converter."""
def setUp(self):
super(HwpackConverterTests, self).setUp()
def test_wrong_input_file(self):
"""Pass a non-existing file."""
input_file = '/tmp/foobaz'
self.assertRaises(
HwpackConverterException, check_and_validate_args,
Args(input_file=input_file))
def test_wrong_input_dir(self):
"""Pass a directory instead of file."""
temp_file = tempfile.NamedTemporaryFile()
temp_dir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
self.assertRaises(
HwpackConverterException, check_and_validate_args,
Args(input_file=temp_file.name, output_file=temp_dir))
def test_same_input_output_file(self):
"""Pass the same existing file path to the two arguments."""
temp_file = self.useFixture(CreateTempFileFixture()).get_file_name()
self.assertRaises(
HwpackConverterException, check_and_validate_args,
Args(input_file=temp_file, output_file=temp_file))
def test_basic_parse(self):
ini_format = '[hwpack]\nformat=2.0\nsupport=supported'
output_format = "format: '3.0'\nsupport: supported\n"
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(output_format, str(converter))
def test_architectures_section_creation(self):
"""Tests that we create the correct architectures list in the
converted file.
"""
ini_format = '[hwpack]\nformat=2.0\narchitectures=armhf armel'
output_format = "format: '3.0'\narchitectures:\n- armhf\n- armel\n"
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(output_format, str(converter))
def test_bootloaders(self):
"""Tests the correct creation of the bootloaders part."""
ini_format = ("[hwpack]\nformat=2.0\nu_boot_package=a_package\n"
"u_boot_file=a_file\nu_boot_in_boot_part=Yes\n"
"u_boot_dd=33")
out_format = ("format: '3.0'\nbootloaders:\n u_boot:\n dd: '33'"
"\n file: a_file\n in_boot_part: true\n"
" package: a_package\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_extra_boot_options(self):
"""Tests the correct creation of the extra_boot_options part."""
ini_format = ("[hwpack]\nformat=2.0\nu_boot_package=a_package\n"
"extra_boot_options=opt1 opt2")
out_format = ("format: '3.0'\nbootloaders:\n u_boot:\n "
" extra_boot_options:\n - opt1\n "
"- opt2\n package: a_package\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_extra_serial_options(self):
"""Tests the correct creation of the extra_serial_options part."""
ini_format = ("[hwpack]\nformat=2.0\nextra_serial_options=opt1 opt2")
out_format = ("format: '3.0'\nextra_serial_options:\n- opt1\n- opt2\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_assume_installed(self):
"""Tests the correct creation of the extra_serial_options part."""
ini_format = ("[hwpack]\nformat=2.0\nassume-installed=install1 "
"install2")
out_format = ("format: '3.0'\nassume_installed:\n- install1\n- "
"install2\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_include_debs(self):
"""Tests the correct creation of the extra_serial_options part."""
ini_format = ("[hwpack]\nformat=2.0\ninclude-debs=yes")
out_format = ("format: '3.0'\ninclude_debs: true\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_dtb_file(self):
"""Test the dtb_file conversion."""
ini_format = ("[hwpack]\nformat=2.0\ndtb_file=boot/a-*-path/file.dtb")
out_format = ("format: '3.0'\ndtb_files:\n- board.dtb: "
"boot/a-*-path/file.dtb\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
def test_mmc_id(self):
"""Test correct handling of mmc_id field.
The mmc_id field has to be quoted coming out from the converter
otherwise when reading the yaml file the value is read as a number,
not a string."""
ini_format = ("[hwpack]\nformat=2.0\nmmc_id=1:1")
out_format = ("format: '3.0'\nmmc_id: '1:1'\n")
input_file = self.useFixture(
CreateTempFileFixture(ini_format)).get_file_name()
output_file = self.useFixture(CreateTempFileFixture()).get_file_name()
converter = HwpackConverter(input_file, output_file)
converter._parse()
self.assertEqual(out_format, str(converter))
|