-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements getters ram manager with tests and mocks
- Loading branch information
javierfh03
committed
Feb 29, 2024
1 parent
1eae16e
commit 5b91ea8
Showing
8 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
"""Exposed ram_lib classes and methods.""" | ||
from ram_lib.entities.ram_module import RamModule | ||
from ram_lib.entities import RamModule | ||
from ram_lib.managers import RamManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
"""Exposed managers classes and methods.""" | ||
from ram_lib.managers.ram_manager import RamManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Manage RAM of unix system.""" | ||
from shell_executor_lib import CommandManager | ||
|
||
from ram_lib import RamModule | ||
from ram_lib.managers.getters import RamGetter, UseGetter | ||
|
||
|
||
class RamManager: | ||
"""Manage RAM of unix system.""" | ||
|
||
def __init__(self, command_manager: CommandManager): | ||
"""Initialize the RAM manager. | ||
Args: | ||
command_manager: The command manager to execute commands. | ||
""" | ||
self.__ram_getter = RamGetter(command_manager) | ||
self.__use_getter = UseGetter(command_manager) | ||
|
||
async def get_ram(self) -> list[RamModule]: | ||
"""Get RAM modules of the system. | ||
Returns: | ||
The list of RAM modules of the system. | ||
Raises: | ||
CommandError: If the exit code is not 0. | ||
""" | ||
return await self.__ram_getter.get_ram() | ||
|
||
async def get_use(self) -> tuple[int, int]: | ||
"""Get use of RAM in the system. | ||
Returns: | ||
The capacity and the use of the RAM in bytes. | ||
Raises: | ||
CommandError: If the exit code is not 0. | ||
""" | ||
return await self.__use_getter.get_use() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Test the RamManager class.""" | ||
import unittest | ||
from unittest import mock | ||
|
||
from shell_executor_lib import CommandManager | ||
|
||
from mock_ram_lib import mock_command_executor_method, use_ram_formatted, use_ram, mock_ram_memories, \ | ||
mock_ram_memories_entities | ||
from ram_lib import RamManager | ||
|
||
|
||
class TestRamManager(unittest.IsolatedAsyncioTestCase): | ||
"""Test the RamManager class.""" | ||
|
||
def setUp(self) -> None: | ||
"""Set up the test.""" | ||
self.ram_manager = RamManager(CommandManager("augusto", "augusto")) | ||
|
||
async def test_get_ram(self) -> None: | ||
"""Test get ram modules correctly.""" | ||
with mock.patch(mock_command_executor_method, return_value=mock_ram_memories): | ||
self.assertEqual(await self.ram_manager.get_ram(), mock_ram_memories_entities) | ||
|
||
async def test_get_uses(self) -> None: | ||
"""Test get uses correctly.""" | ||
with mock.patch(mock_command_executor_method, return_value=use_ram): | ||
self.assertEqual(await self.ram_manager.get_use(), use_ram_formatted) |