blob: a73558344994f979c90fbb41673064a7387a42ce [file] [log] [blame]
import subprocess
import unittest
from unittest.mock import MagicMock
from steps import build_image
import inspect
class TestBuildImage(unittest.TestCase):
def setUp(self):
self.step = build_image.BuildImage()
self.step.export_machine = MagicMock(return_value="")
self.step.source_setup = MagicMock(return_value="")
self.step.umask = MagicMock(return_value="")
self.step.export_gbmc_config = MagicMock(return_value="")
self.step.export_gbmc_version = MagicMock(return_value="")
self.step.export_bb_env_extrawhite = MagicMock(return_value="")
self.step.bitbake = MagicMock(return_value="")
subprocess.run = MagicMock()
self.step.run_script()
def test_export_machine(self):
"""Tests that export_machine method is called"""
self.step.export_machine.assert_called_with()
def test_source_setup(self):
"""Tests that source_setup method is called"""
self.step.source_setup.assert_called_with()
def test_umask(self):
"""Tests that umask method i called"""
self.step.umask.assert_called_with()
def test_export_gbmc_config(self):
"""Tests that export_gbmc_config is called"""
self.step.export_gbmc_config.assert_called_with()
def test_export_gbmc_version(self):
"""Tests that export_gbmc_version is called"""
self.step.export_gbmc_version.assert_called_with()
def test_export_bb_env_extrawhite(self):
"""Tests that export_bb_env_extrawhite is called"""
self.step.export_bb_env_extrawhite.assert_called_with()
def test_bitbake(self):
"""Tests that bitbake method is called"""
self.step.bitbake.assert_called_with()
def test_subprocess_run(self):
"""Tests subprocess's arguments, tests the order in which all the previous
tests are called
"""
self.step = build_image.BuildImage()
self.step.firmware_machine = "machine0"
self.step.firmware_version = "x.y.z"
self.step.gbmc_config = "test"
subprocess.run = MagicMock()
self.step.run_script()
command = "export MACHINE=machine0 " \
"&& source setup machine0 " \
"&& umask 002 " \
"&& export GBMC_CONFIG=test " \
"&& export GBMC_VERSION=x.y.z " \
"&& export BB_ENV_EXTRAWHITE=${BB_ENV_EXTRAWHITE} GBMC_CONFIG GBMC_VERSION " \
"&& bitbake -k obmc-phosphor-image"
subprocess.run.assert_called_with(["bash", "-c", command])