| import subprocess |
| import sh |
| import unittest |
| from unittest.mock import MagicMock |
| from steps import machine_setup |
| |
| class TestMachineSetup(unittest.TestCase): |
| def setUp(self): |
| self.init_step_mock() |
| self.step.export_machine = MagicMock(return_value="") |
| self.step.source_setup = MagicMock(return_value="") |
| self.step.umask = MagicMock(return_value="") |
| |
| self.step.run_script() |
| |
| def init_step_mock(self): |
| self.step = machine_setup.MachineSetup() |
| self.step.firmware_machine = "machine0" |
| self.step.main_repo_name = "repo0" |
| sh.cd = MagicMock() |
| subprocess.run = MagicMock() |
| |
| 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 is called""" |
| self.step.umask.assert_called_with() |
| |
| def test_cd(self): |
| """Tests that run_script changes into the main_repo_name dir""" |
| sh.cd.assert_called_with(self.step.main_repo_name) |
| |
| def test_subprocess(self): |
| """Tests the arguments of subprocess, and the order in which each |
| sub-commands are called (separated by &&) |
| """ |
| self.init_step_mock() |
| |
| self.step.run_script() |
| |
| command = "export MACHINE=machine0 " \ |
| "&& source setup machine0 " \ |
| "&& umask 002" |
| |
| subprocess.run.assert_called_with(["bash", "-c", command]) |