def test_when_os_is_NILinuxRT_and_creation_is_OK_and_no_files_exist_then_files_should_be_updated(): patch_grains = patch.dict(opkg.__grains__, {"os_family": "NILinuxRT"}) patch_makedirs = patch("os.makedirs", autospec=True, return_value=None) patch_update_state = patch( "salt.modules.opkg._update_nilrt_restart_state", autospec=True ) patch_listdir = patch("os.listdir", return_value=[], autospec=True) with patch_grains, patch_makedirs, patch_listdir, patch_update_state as fake_update: opkg.__virtual__() fake_update.assert_called_once()
def test_virtual_update_restart_state_not_called(self): """ Test - Update restart state is not called when dir contains files """ mock_cmd = MagicMock() with patch.dict(opkg.__grains__, {"os_family": "NILinuxRT"}): with patch.object(os, "makedirs", MagicMock(return_value=True)): with patch.object(os, "listdir", MagicMock(return_value=["test"])): with patch.object(opkg, "_update_nilrt_restart_state", mock_cmd): opkg.__virtual__() mock_cmd.assert_not_called()
def test_virtual_not_supported_system(self): """ Test - Module not supported """ with patch.object(os.path, "isdir", MagicMock(return_value=False)): expected = (False, "Module opkg only works on OpenEmbedded based systems") self.assertEqual(expected, opkg.__virtual__())
def test_virtual_ni_linux_rt_system(self): """ Test - Module virtual name on NI Linux RT """ with patch.dict(opkg.__grains__, {"os_family": "NILinuxRT"}): with patch.object(os, "makedirs", MagicMock(return_value=True)): with patch.object(os, "listdir", MagicMock(return_value=[])): with patch.object(opkg, "_update_nilrt_restart_state", MagicMock()): self.assertEqual("pkg", opkg.__virtual__())
def test_when_os_is_NILinuxRT_and_creation_of_RESTART_CHECK_STATE_PATH_fails_virtual_should_be_False(): expected_result = ( False, "Error creating /var/lib/salt/restartcheck_state (-whatever): 42", ) with patch.dict(opkg.__grains__, {"os_family": "NILinuxRT"}), patch( "os.makedirs", autospec=True, side_effect=OSError("whatever", 42, "boop") ): result = opkg.__virtual__() assert result == expected_result
def test_virtual_open_embedded_system(self): """ Test - Module virtual name on Open Embedded """ with patch.object(os.path, "isdir", MagicMock(return_value=True)): self.assertEqual("pkg", opkg.__virtual__())