Skip to content

Commit

Permalink
Implements getters ram manager with tests and mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
javierfh03 committed Feb 29, 2024
1 parent 1eae16e commit 5b91ea8
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.1.0]
## Added
- @javierfh03 - Add ram getter with tests and mocks.
- @javierfh03 - Add use getter with tests and mocks.
- @javierfh03 - Implements getters ram manager with tests and mocks.

[Unreleased]: https://github.com/Lagatrix/ram_lib.git
[0.1.0]: https://github.com/Lagatrix/ram_lib.git
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ nose2 = "^0.12"
nose2-html-report = "^0.6"
pep8-naming = "^0.13"
python-kacl = "^0.3"
shell_executor_lib = { git = "https://github.com/Lagatrix/shell_executor_lib.git", rev = "0.1.2" }
shell_executor_lib = { git = "https://github.com/Lagatrix/shell_executor_lib.git", rev = "0.2.0" }

[tool.poetry.group.dev]
optional = true
Expand Down
3 changes: 2 additions & 1 deletion src/ram_lib/__init__.py
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
1 change: 1 addition & 0 deletions src/ram_lib/managers/__init__.py
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
4 changes: 2 additions & 2 deletions src/ram_lib/managers/getters/use_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def __init__(self, command_manager: CommandManager):
"""
self.__command_manager = command_manager

async def get_uses(self) -> tuple[int, int]:
async def get_use(self) -> tuple[int, int]:
"""Get use of RAM in the system.
Returns:
The capacity of all modules of the ram and the use of the ram.
The capacity and the use of the RAM in bytes.
Raises:
CommandError: If the exit code is not 0.
Expand Down
40 changes: 40 additions & 0 deletions src/ram_lib/managers/ram_manager.py
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()
2 changes: 1 addition & 1 deletion tests/test_ram_lib/managers/getters/test_use_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def setUp(self) -> None:
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.use_getter.get_uses(), use_ram_formatted)
self.assertEqual(await self.use_getter.get_use(), use_ram_formatted)
27 changes: 27 additions & 0 deletions tests/test_ram_lib/managers/test_ram_manager.py
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)

0 comments on commit 5b91ea8

Please sign in to comment.