diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..1d86c390 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,65 @@ +name: Tests + +on: + push: + branches: ["main", "develop"] + pull_request: + branches: ["main", "develop"] + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + + steps: + # ---------------------------------------------------------------------- # + # checkout repo and setup Python # + # ---------------------------------------------------------------------- # + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + # ---------------------------------------------------------------------- # + # install and configure poetry # + # ---------------------------------------------------------------------- # + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + # ---------------------------------------------------------------------- # + # load cached venv if cache exists # + # ---------------------------------------------------------------------- # + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v4 + with: + path: .venv + key: + venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version + }}-${{ hashFiles('**/poetry.lock') }} + # ---------------------------------------------------------------------- # + # install dependencies if cache does not exist # + # ---------------------------------------------------------------------- # + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + + # ---------------------------------------------------------------------- # + # run Pytest # + # ---------------------------------------------------------------------- # + - name: Test with pytest + run: | + poetry run pytest --cov-report=xml + - name: Run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: ./coverage.xml diff --git a/py_maker/constants.py b/py_maker/constants.py index 2ed50640..705b2f40 100644 --- a/py_maker/constants.py +++ b/py_maker/constants.py @@ -32,6 +32,7 @@ class ExitErrors(IntEnum): USER_ABORT = 6 OS_ERROR = 7 INVALID_ACTION = 8 + TOML_ERROR = 9 MKDOCS_CONFIG = """ diff --git a/py_maker/helpers.py b/py_maker/helpers.py index 25ab01ef..f4c5d0f8 100644 --- a/py_maker/helpers.py +++ b/py_maker/helpers.py @@ -28,10 +28,17 @@ def get_author_and_email_from_git() -> tuple[str, str]: """Get the author name and email from git.""" config = GitConfigParser() - return ( - str(config.get_value("user", "name", "")), - str(config.get_value("user", "email", "")), - ) + try: + author_name = str(config.get_value("user", "name", "")) + except KeyError: + author_name = "" + + try: + author_email = str(config.get_value("user", "email", "")) + except KeyError: + author_email = "" + + return author_name, author_email def get_file_list(template_dir: Union[Traversable, Path]) -> list[Path]: @@ -112,7 +119,7 @@ def exists_on_pypi(package_name: str) -> bool: url = f"https://pypi.org/pypi/{package_name}/json" try: response = requests.get(url, timeout=5) - except requests.exceptions.Timeout: + except (requests.exceptions.Timeout, requests.exceptions.ConnectionError): return False return response.status_code == SUCCESS_RESPONSE @@ -145,6 +152,9 @@ def get_app_version() -> str: except (KeyError, OSError) as exc: print(f"Problem getting the Version : {exc}") sys.exit(ExitErrors.OS_ERROR) + except rtoml.TomlParsingError as exc: + print(f"Invalid 'pyproject.toml' file : {exc}") + sys.exit(ExitErrors.TOML_ERROR) else: return version else: diff --git a/py_maker/prompt/prompt.py b/py_maker/prompt/prompt.py index d130b998..33ccb99b 100644 --- a/py_maker/prompt/prompt.py +++ b/py_maker/prompt/prompt.py @@ -55,7 +55,7 @@ def process_response(self, value: str) -> PromptType: # type: ignore value = value.strip() try: return_value: PromptType = self.response_type(value) # type: ignore - except ValueError as exc: + except ValueError as exc: # pragma: no cover raise InvalidResponse(self.validate_error_message) from exc if self.choices is not None: diff --git a/pyproject.toml b/pyproject.toml index a3132852..73e0670e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -180,7 +180,11 @@ module = "tests.*" addopts = ["--cov", "--cov-report", "term-missing", "--cov-report", "html"] filterwarnings = [] mock_use_standalone_module = true +# pythonpath = "py_maker" [tool.coverage.run] -# source = [] omit = ["*/tests/*"] +source = ["py_maker"] + +[tool.coverage.report] +show_missing = true diff --git a/tests/test_config.py b/tests/test_config.py deleted file mode 100644 index d422f74b..00000000 --- a/tests/test_config.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Integration tests for the config command.""" -from unittest.mock import patch - -from typer.testing import CliRunner - -from py_maker.commands.config import app - - -def test_show_config() -> None: - """Test the show command.""" - runner = CliRunner() - with patch("py_maker.config.settings.Settings.get_attrs") as mock_get_attrs: - mock_get_attrs.return_value = {"key1": "value1", "key2": "value2"} - result = runner.invoke(app, ["show"]) - assert result.exit_code == 0 - assert "Key1" in result.stdout - assert "value1" in result.stdout - assert "Key2" in result.stdout - assert "value2" in result.stdout - - -def test_change_config() -> None: - """Test the change command.""" - runner = CliRunner() - with patch( - "py_maker.config.settings.Settings.change_settings" - ) as mock_change_settings: - result = runner.invoke(app, ["change"]) - assert result.exit_code == 0 - mock_change_settings.assert_called_once() diff --git a/tests/test_constants.py b/tests/test_constants.py deleted file mode 100644 index 0a97c942..00000000 --- a/tests/test_constants.py +++ /dev/null @@ -1,29 +0,0 @@ -"""Tests for the constants module.""" -from py_maker import constants - -LICENSE_DICT_SIZE = 2 - - -def test_licenses() -> None: - """Test that the licenses constant is a list of dictionaries.""" - assert isinstance(constants.LICENCES, list) - assert all( - isinstance(license_details, dict) - for license_details in constants.LICENCES - ) - assert all( - len(license_details) == LICENSE_DICT_SIZE - for license_details in constants.LICENCES - ) - - -def test_license_names() -> None: - """Test that the license_names constant is a list of strings.""" - assert isinstance(constants.license_names, list) - assert all(isinstance(name, str) for name in constants.license_names) - - -def test_exit_errors() -> None: - """Test that the ExitErrors enum is an IntEnum.""" - assert issubclass(constants.ExitErrors, int) - assert all(isinstance(error, int) for error in constants.ExitErrors) diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 9c796cca..3abb6f17 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,73 +1,301 @@ -"""Test the helpers module.""" -from __future__ import annotations - -from typing import TYPE_CHECKING +"""Test suite for the helper functions.""" +import datetime +from importlib import metadata +from pathlib import Path +import pytest import requests +from py_maker.constants import ExitErrors from py_maker.helpers import ( + check_cmd_exists, exists_on_pypi, + get_app_version, get_author_and_email_from_git, get_current_year, + get_file_list, get_title, + header, pretty_attrib, sanitize, + show_table, ) -if TYPE_CHECKING: - from pytest_mock import MockerFixture +@pytest.fixture() +def fs_setup(fs) -> str: + """A fixture to set up the fake file system before each test.""" + toml_content = """ +[tool.poetry] +name = "py_maker" +version = "1.2.3" +description = "A sample project" +authors = ["Author "] + """ + toml_path = "/fake/path/to/py_maker/pyproject.toml" + fs.create_file(toml_path, contents=toml_content) + return toml_path + + +def test_get_author_and_email_from_git(mocker) -> None: + """Test getting the username and email from Git.""" + mocker.patch( + "py_maker.helpers.GitConfigParser.get_value", + side_effect=lambda _, key, __: { + "name": "John Doe", + "email": "john@example.com", + }[key], + ) + author, email = get_author_and_email_from_git() + assert author == "John Doe" + assert email == "john@example.com" + + +def test_get_author_and_email_from_git_no_config(mocker) -> None: + """Test getting username and email from Git when no config found.""" + mocker.patch( + "py_maker.helpers.GitConfigParser.get_value", + side_effect=KeyError("Config not found"), + ) + author, email = get_author_and_email_from_git() + assert author == "" + assert email == "" + + +def test_get_author_and_email_from_git_no_name(mocker) -> None: + """Test getting username and email from Git when the username is missing.""" + + # Mock get_value to return an email but raise KeyError for the name + def get_value_mock(_, key, __) -> str: + if key == "email": + return "john@example.com" + msg = f"{key} not found" + raise KeyError(msg) + + mocker.patch( + "py_maker.helpers.GitConfigParser.get_value", side_effect=get_value_mock + ) + author, email = get_author_and_email_from_git() + assert author == "" # Expect default empty string + assert email == "john@example.com" + + +def test_get_author_and_email_from_git_no_email(mocker) -> None: + """Test getting username and email from Git when the email is missing.""" -def test_get_author_and_email_from_git() -> None: - """Test the get_author_and_email_from_git function.""" + # Mock get_value to return a name but raise KeyError for the email + def get_value_mock(_, key, __) -> str: + if key == "name": + return "John Doe" + msg = f"{key} not found" + raise KeyError(msg) + + mocker.patch( + "py_maker.helpers.GitConfigParser.get_value", side_effect=get_value_mock + ) author, email = get_author_and_email_from_git() - assert isinstance(author, str) - assert isinstance(email, str) + assert author == "John Doe" + assert email == "" # Expect default empty string + + +def test_get_file_list(fs) -> None: + """Test the 'get_file_list' helper.""" + fs.create_file("/template/__init__.py") + fs.create_file("/template/module.py") + file_list = get_file_list(Path("/template")) + assert Path("module.py") in file_list + assert Path("__init__.py") not in file_list + + +def test_exists_on_pypi_true(mocker) -> None: + """Test the 'exists_on_pypi' helper.""" + mocker.patch("requests.get", return_value=mocker.Mock(status_code=200)) + assert exists_on_pypi("existing_package") is True + + +def test_exists_on_pypi_timeout(mocker) -> None: + """Test the 'exists_on_pypi' giving a timeout.""" + mocker.patch("requests.get", side_effect=requests.exceptions.Timeout) + assert exists_on_pypi("package") is False + + +def test_exists_on_pypi_network_error(mocker) -> None: + """Test exists_on_pypi returns False on network error.""" + mocker.patch( + "requests.get", side_effect=requests.exceptions.ConnectionError + ) + assert not exists_on_pypi("some_package") + + +def test_exists_on_pypi_server_error(mocker) -> None: + """Test the 'exists_on_pypi' function handles server error responses.""" + mocker.patch("requests.get", return_value=mocker.Mock(status_code=500)) + assert exists_on_pypi("some_package") is False + + +def test_get_app_version_installed_package(mocker) -> None: + """Test getting app version from installed package metadata.""" + mocker.patch("py_maker.helpers.metadata.version", return_value="1.0.1") + mocker.patch("py_maker.helpers.Path.exists", return_value=False) + assert get_app_version() == "1.0.1" + +def test_get_app_version_local_dev(mocker, fs_setup) -> None: + """Test get_app_version returns the correct version from pyproject.toml.""" + mocker.patch("py_maker.helpers.get_toml_path", return_value=Path(fs_setup)) + version = get_app_version() + assert version == "1.2.3" -def test_sanitize() -> None: - """Test the Sanitize function.""" - assert sanitize("my-project-name") == "my_project_name" - assert sanitize("my-project-name-1.0") == "my_project_name_1_0" - assert sanitize("my_project_name") == "my_project_name" - assert sanitize("my_____project_name....end") == "my_project_name_end" +def test_get_app_version_error_handling(mocker, fs) -> None: # noqa: ARG001 + """Test get_app_version exits with error when version cant be retrieved.""" + mocker.patch("py_maker.helpers.Path.exists", return_value=False) + mocker.patch( + "py_maker.helpers.metadata.version", + side_effect=metadata.PackageNotFoundError("package not found"), + ) + with pytest.raises(SystemExit) as exc_info: + get_app_version() + assert exc_info.value.code == ExitErrors.OS_ERROR -def test_get_title() -> None: - """Test the get_title function.""" - assert get_title("my-project-name") == "My Project Name" - assert get_title("my_project_name") == "My Project Name" + +def test_get_app_version_key_error(mocker, fs) -> None: + """Test get_app_version handles KeyError when version key is missing.""" + toml_content = """ +[tool.poetry] +name = "py_maker" +description = "A sample project" +authors = ["Author "] + """ + fs.create_file( + "/fake/path/to/py_maker/pyproject.toml", contents=toml_content + ) + + mocker.patch( + "py_maker.helpers.get_toml_path", + return_value=Path("/fake/path/to/py_maker/pyproject.toml"), + ) + + with pytest.raises(SystemExit) as e: + get_app_version() + assert e.value.code == ExitErrors.OS_ERROR + + +def test_get_app_version_os_error(mocker, fs) -> None: # noqa: ARG001 + """Test get_app_version handles OSError with an issue reading the file.""" + mocker.patch( + "py_maker.helpers.get_toml_path", + return_value=Path("/fake/path/to/py_maker/pyproject.toml"), + ) + + mocker.patch("py_maker.helpers.rtoml.load", side_effect=OSError) + + with pytest.raises(SystemExit) as e: + get_app_version() + assert e.value.code == ExitErrors.OS_ERROR + + +def test_get_app_version_invalid_toml_format(mocker, fs) -> None: + """Test get_app_version handles invalid TOML format gracefully.""" + # Setup an invalid TOML file content + toml_content = "invalid TOML content" + fs.create_file( + "/fake/path/to/py_maker/pyproject.toml", contents=toml_content + ) + + # Mock get_toml_path to return the path of the created TOML file + mocker.patch( + "py_maker.helpers.get_toml_path", + return_value=Path("/fake/path/to/py_maker/pyproject.toml"), + ) + + with pytest.raises(SystemExit) as e: + get_app_version() + assert e.value.code == ExitErrors.TOML_ERROR + + +def test_get_app_version_missing_tool_poetry_section(mocker, fs) -> None: + """Test get_app_version handles missing 'tool.poetry' section.""" + # Setup a TOML file without the 'tool.poetry' section + toml_content = """ +[package] +name = "py_maker" + """ + fs.create_file( + "/fake/path/to/py_maker/pyproject.toml", contents=toml_content + ) + + # Mock get_toml_path to return the path of the created TOML file + mocker.patch( + "py_maker.helpers.get_toml_path", + return_value=Path("/fake/path/to/py_maker/pyproject.toml"), + ) + + with pytest.raises(SystemExit) as e: + get_app_version() + assert e.value.code == ExitErrors.OS_ERROR + + +def test_sanitize_with_dash() -> None: + """Test sanitize replaces dashes with underscores.""" + assert sanitize("test-name") == "test_name" + + +def test_sanitize_with_path() -> None: + """Test sanitize works with Path objects containing dashes.""" + assert sanitize("/path/to/test-name") == "/path/to/test_name" + + +def test_get_title_with_dashes() -> None: + """Test get_title replaces dashes and titlizes the string.""" + assert get_title("test-name") == "Test Name" + + +def test_get_title_with_underscore() -> None: + """Test get_title replaces underscores and titlizes the string.""" + assert get_title("test_name") == "Test Name" + + +def test_get_title_with_dot() -> None: + """Test get_title returns an empty string for a single dot.""" assert get_title(".") == "" def test_pretty_attrib() -> None: - """Test the pretty_attrib function.""" - assert pretty_attrib("my_attribute_name") == "My Attribute Name" - assert pretty_attrib("MY_ATTRIBUTE_NAME") == "My Attribute Name" + """Test pretty_attrib formats attribute names nicely.""" + assert pretty_attrib("test_name") == "Test Name" def test_get_current_year() -> None: - """Test the get_current_year function.""" - assert get_current_year().isdigit() - assert len(get_current_year()) == 4 # noqa: PLR2004 + """Test get_current_year returns the current year as a string.""" + current_year = str(datetime.datetime.now(tz=datetime.timezone.utc).year) + assert get_current_year() == current_year + + +def test_header(mocker) -> None: + """Test header prints the correct header information.""" + mock_print = mocker.patch("py_maker.helpers.print") + header() + mock_print.assert_called_once_with( + "[bold]PyMaker[/bold] - Generate a Python project skeleton.\n" + ) -def test_exists_on_pypi_returns_true(mocker: MockerFixture) -> None: - """Test the exists_on_pypi function - exists.""" - mock_get = mocker.patch.object(requests, "get") - mock_get.return_value.status_code = 200 - assert exists_on_pypi("requests") is True +def test_show_table(mocker) -> None: + """Test show_table displays user data in a table format.""" + mock_console = mocker.patch("py_maker.helpers.Console") + settings = {"name": "Test", "token": "secret"} + show_table(settings) + mock_console.return_value.print.assert_called_once() -def test_exists_on_pypi_returns_false(mocker: MockerFixture) -> None: - """Test the exists_on_pypi function - does not exist.""" - mock_get = mocker.patch.object(requests, "get") - mock_get.return_value.status_code = 404 - assert exists_on_pypi("nonexistent_package") is False +def test_check_cmd_exists_true(mocker) -> None: + """Test check_cmd_exists returns True when command exists.""" + mocker.patch("shutil.which", return_value="/path/to/git") + assert check_cmd_exists("git") is True -def test_exists_on_pypi_returns_false_on_timeout(mocker: MockerFixture) -> None: - """Test the exists_on_pypi function - timeout.""" - mock_get = mocker.patch.object(requests, "get") - mock_get.side_effect = requests.exceptions.Timeout - assert exists_on_pypi("nonexistent_package") is False +def test_check_cmd_exists_false(mocker) -> None: + """Test check_cmd_exists returns False when command does not exist.""" + mocker.patch("shutil.which", return_value=None) + assert check_cmd_exists("nonexistent_cmd") is False diff --git a/tests/test_main.py b/tests/test_main.py deleted file mode 100644 index c2ebbbc2..00000000 --- a/tests/test_main.py +++ /dev/null @@ -1,20 +0,0 @@ -"""Test the main app loop.""" -from typer.testing import CliRunner - -from py_maker.main import app - -runner = CliRunner() - - -def test_app() -> None: - """Test the main app entry point.""" - result = runner.invoke(app, []) - assert result.exit_code == 0 - assert "Usage" in result.stdout - - -def test_new() -> None: - """Test the new command with no arguments shows help.""" - result = runner.invoke(app, ["new"]) - assert result.exit_code == 0 - assert "--help" in result.stdout diff --git a/tests/test_prompt.py b/tests/test_prompt.py index 0bf7e4f6..36880fc7 100644 --- a/tests/test_prompt.py +++ b/tests/test_prompt.py @@ -1,7 +1,30 @@ -"""Test our changes to the Rich Prompt class.""" +"""Test suite for custom prompt classes in py_maker.prompt.""" +import io + import pytest +from rich.console import Console + +from py_maker.prompt import Confirm, InvalidResponse, Prompt -from py_maker.prompt import InvalidResponse, Prompt + +def test_confirm_yes() -> None: + """Test Confirm.ask for a 'yes' response.""" + user_input = "y\n" + console = Console(file=io.StringIO()) + answer = Confirm.ask( + "Continue?", console=console, stream=io.StringIO(user_input) + ) + assert answer is True + + +def test_confirm_no() -> None: + """Test Confirm.ask for a 'no' response.""" + user_input = "n\n" + console = Console(file=io.StringIO()) + answer = Confirm.ask( + "Continue?", console=console, stream=io.StringIO(user_input) + ) + assert answer is False def test_prompt_check_choice() -> None: @@ -27,3 +50,7 @@ def test_prompt_process_response() -> None: assert prompt.process_response("GREEN") == "Green" with pytest.raises(InvalidResponse): prompt.process_response("yellow") + + +def test_prompt_process_response_value_error() -> None: + """Test process_response raises ValueError for invalid data.""" diff --git a/tests/test_pymaker.py b/tests/test_pymaker.py deleted file mode 100644 index a6d875a9..00000000 --- a/tests/test_pymaker.py +++ /dev/null @@ -1,48 +0,0 @@ -"""Test the PyMaker class. - -These tests are not complete. -""" -import shutil -from collections.abc import Iterator -from pathlib import Path - -import pytest - -from py_maker.pymaker import PyMaker - - -@pytest.fixture() -def test_project_dir( - tmp_path_factory: pytest.TempPathFactory, -) -> Iterator[Path]: - """Create a temporary directory for testing.""" - project_dir: Path = tmp_path_factory.mktemp("test_project") - yield project_dir - shutil.rmtree(project_dir) - - -@pytest.fixture() -def test_pymaker(test_project_dir: pytest.TempPathFactory) -> PyMaker: - """Create a PyMaker instance for testing.""" - pymaker = PyMaker(location="test_project", options={}) - pymaker.choices.name = "test_project" - pymaker.choices.author = "Test Author" - pymaker.choices.email = "test@example.com" - pymaker.choices.license_name = "MIT" - pymaker.choices.description = "A test project" - pymaker.choices.project_dir = Path(str(test_project_dir)) / "test_project" - return pymaker - - -def test_create_folders(test_pymaker: PyMaker) -> None: - """Test that the create_folders method creates the project directory.""" - test_pymaker.create_folders() - assert test_pymaker.choices.project_dir.is_dir() - - -def test_copy_files(test_pymaker: PyMaker) -> None: - """Test that the copy_files method copies the template files.""" - test_pymaker.create_folders() - - # this test needs updating to add assertions that the files are copied - # properly. The 'pyfakefs' package will be useful here. diff --git a/tests/test_schema.py b/tests/test_schema.py new file mode 100644 index 00000000..00c59ce1 --- /dev/null +++ b/tests/test_schema.py @@ -0,0 +1,89 @@ +"""Test the pydantic schemas.""" +from pathlib import Path + +import pytest +from pydantic import ValidationError + +from py_maker.schema import ProjectSettings, ProjectValues + + +def test_project_settings_creation_success() -> None: + """Test successful creation of a ProjectSettings instance.""" + settings = ProjectSettings( + description="A test project", + package_name="test_package", + author="John Doe", + email="john.doe@example.com", + license_name="MIT", + ) + assert settings.description == "A test project" + assert settings.package_name == "test_package" + assert settings.author == "John Doe" + assert settings.email == "john.doe@example.com" + assert settings.license_name == "MIT" + + +def test_project_values_creation_success() -> None: + """Test successful creation of a ProjectValues instance with all fields.""" + values = ProjectValues( + description="A test project", + package_name="test_package", + author="John Doe", + email="john.doe@example.com", + license_name="MIT", + project_dir=Path("/path/to/project"), + name="Test Project", + standalone=True, + homepage="https://example.com", + repository="https://github.com/example/test_project", + ) + assert values.project_dir == Path("/path/to/project") + assert values.name == "Test Project" + assert values.standalone is True + assert values.homepage == "https://example.com" + assert values.repository == "https://github.com/example/test_project" + + +def test_project_values_optional_fields() -> None: + """Test ProjectValues instance creation with optional fields missing.""" + values = ProjectValues( + description="A test project", + package_name="test_package", + author="John Doe", + email="john.doe@example.com", + license_name="MIT", + project_dir=Path("/path/to/project"), + name="Test Project", + ) + assert values.homepage is None + assert values.repository is None + + +def test_project_settings_defaults() -> None: + """Test that ProjectSettings fields have correct defaults.""" + settings = ProjectSettings() + assert settings.description == "" + assert settings.package_name == "" + assert settings.author == "" + assert settings.email == "" + assert settings.license_name == "" + + +def test_project_values_defaults() -> None: + """Test that ProjectValues fields have correct defaults and types.""" + values = ProjectValues() + assert values.project_dir == Path() + assert values.name == "" + assert values.standalone is False # Noting the default is False, not None + assert values.homepage is None + assert values.repository is None + + +def test_project_values_type_validation() -> None: + """Test that ProjectValues correctly validates field types.""" + # Example of testing for correct type validation + with pytest.raises(ValidationError): + ProjectValues(standalone="not a boolean") # type: ignore + + with pytest.raises(ValidationError): + ProjectValues(project_dir=123) # type: ignore diff --git a/tests/test_settings.py b/tests/test_settings.py deleted file mode 100644 index 5e63147c..00000000 --- a/tests/test_settings.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Tests for the Settings class.""" -import tempfile -from pathlib import Path - -import pytest -import rtoml - -from py_maker.config.settings import Settings - - -@pytest.mark.skip(reason="Needs changing to new implementation") -def test_settings() -> None: - """Test that the Settings class works as expected.""" - test_author = "John Doe" - # Create a temporary directory to store the settings file - with tempfile.TemporaryDirectory() as tmpdir: - # Set the settings folder to the temporary directory - settings_folder = Path(tmpdir) / ".pymaker" - settings_folder.mkdir() - - # Set the settings path to the temporary directory - settings_path = settings_folder / "config.toml" - - # Create a new Settings object with the temporary settings path - settings = Settings(settings_file_name=settings_path) # type: ignore - - # Test that the default settings are correct - assert settings.schema_version == "none" - assert settings.author_name == "" - assert settings.author_email == "" - assert settings.default_license == "None" - - # Test that we can set and get a setting - settings.set("author_name", test_author) - assert settings.get("author_name") == test_author - - # Test that the settings are saved to the file - settings.save() - loaded_settings = rtoml.load(settings_path) - assert loaded_settings["pymaker"]["author_name"] == test_author - - # Test that we can load the settings from the file - settings2 = Settings(settings_file_name=settings_path) # type: ignore - assert settings2.get("author_name") == test_author