-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rai_ws() into pytest fixture
- Loading branch information
1 parent
de28123
commit 2dbb193
Showing
1 changed file
with
23 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
import os | ||
import uuid | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
|
||
from rai.cli.rai_cli import create_rai_ws | ||
|
||
|
||
def test_create_rai_ws(): | ||
with TemporaryDirectory() as directory: | ||
# Mock ArgumentParser and its methods | ||
mock_parser = MagicMock() | ||
mock_args = MagicMock() | ||
mock_args.name = "test_package" | ||
mock_args.destination_directory = directory | ||
mock_parser.parse_args.return_value = mock_args | ||
@pytest.fixture | ||
def rai_ws(): | ||
directory = Path("/tmp/" + str(uuid.uuid4())) | ||
os.mkdir(directory) | ||
mock_parser = MagicMock() | ||
mock_args = MagicMock() | ||
mock_args.name = "test_package" | ||
mock_args.destination_directory = directory | ||
mock_parser.parse_args.return_value = mock_args | ||
|
||
# Patch argparse.ArgumentParser to return our mock | ||
with patch("argparse.ArgumentParser", return_value=mock_parser): | ||
create_rai_ws() | ||
|
||
return directory | ||
|
||
# Patch argparse.ArgumentParser to return our mock | ||
with patch("argparse.ArgumentParser", return_value=mock_parser): | ||
create_rai_ws() | ||
|
||
whoami_directory = Path(directory) / "test_package_whoami" | ||
def test_create_rai_ws(rai_ws: Path): | ||
whoami_directory = Path(rai_ws) / "test_package_whoami" | ||
|
||
assert os.path.exists(whoami_directory), "Description folder is missing" | ||
assert os.path.exists(whoami_directory), "Description folder is missing" | ||
|
||
description_files = os.listdir(whoami_directory / "description") | ||
assert "robot_constitution.txt" in description_files | ||
description_files = os.listdir(whoami_directory / "description") | ||
assert "robot_constitution.txt" in description_files |