Source code for tests.test_pyproject

# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

"""Tests for pyproject.toml utilities."""

from __future__ import annotations

from repomatic.pyproject import get_project_name


[docs] def test_get_project_name_from_cwd(tmp_path, monkeypatch): """Test that get_project_name reads from pyproject.toml in CWD.""" pyproject_content = """\ [project] name = "my-package" version = "1.0.0" """ (tmp_path / "pyproject.toml").write_text(pyproject_content) monkeypatch.chdir(tmp_path) assert get_project_name() == "my-package"
[docs] def test_get_project_name_missing_pyproject(tmp_path, monkeypatch): """Test that get_project_name returns None when no pyproject.toml.""" monkeypatch.chdir(tmp_path) assert get_project_name() is None
[docs] def test_get_project_name_no_project_section(tmp_path, monkeypatch): """Test that get_project_name returns None when no [project] section.""" (tmp_path / "pyproject.toml").write_text("[tool.ruff]\n") monkeypatch.chdir(tmp_path) assert get_project_name() is None
[docs] def test_get_project_name_with_preloaded_data(): """Test that get_project_name accepts pre-parsed pyproject data.""" data = {"project": {"name": "preloaded-pkg"}} assert get_project_name(data) == "preloaded-pkg"