diff --git a/pontos/version/commands.py b/pontos/version/commands.py index bf321f7e3..f2c2155b2 100644 --- a/pontos/version/commands.py +++ b/pontos/version/commands.py @@ -17,15 +17,13 @@ from typing import Iterable, Tuple, Type -from pontos.version.errors import ProjectError - from .cmake import CMakeVersionCommand from .go import GoVersionCommand from .javascript import JavaScriptVersionCommand from .python import PythonVersionCommand from .version import VersionCommand -_COMMANDS: Tuple[Type[VersionCommand]] = ( +__COMMANDS: Tuple[Type[VersionCommand]] = ( CMakeVersionCommand, GoVersionCommand, JavaScriptVersionCommand, @@ -33,21 +31,5 @@ ) -def gather_project() -> VersionCommand: - """ - Get the fitting VersionCommand for a project in the current working - directory - - Raises: - ProjectError if no fitting VersionCommand could be found - """ - for cmd in _COMMANDS: - command = cmd() - if command.project_found(): - return command - - raise ProjectError("No project settings file found") - - def get_commands() -> Iterable[Type[VersionCommand]]: - return _COMMANDS + return __COMMANDS diff --git a/tests/version/test_commands.py b/tests/version/test_commands.py index f286132da..4152c2237 100644 --- a/tests/version/test_commands.py +++ b/tests/version/test_commands.py @@ -17,60 +17,7 @@ import unittest -from pontos.testing import temp_directory, temp_python_module -from pontos.version.cmake import CMakeVersionCommand -from pontos.version.commands import gather_project, get_commands -from pontos.version.errors import ProjectError -from pontos.version.go import GoVersionCommand -from pontos.version.javascript import JavaScriptVersionCommand -from pontos.version.python import PythonVersionCommand - - -class GatherProjectTestCase(unittest.TestCase): - def test_no_project_found(self): - with temp_directory(change_into=True), self.assertRaisesRegex( - ProjectError, "No project settings file found" - ): - gather_project() - - def test_python_project(self): - content = "__version__ = '1.2.3'" - with temp_python_module( - content, name="foo", change_into=True - ) as temp_module: - temp_dir = temp_module.parent / "pyproject.toml" - temp_dir.write_text( - '[tool.poetry]\nversion = "1.2.3"\n' - '[tool.pontos.version]\nversion-module-file = "foo.py"', - encoding="utf8", - ) - - self.assertIsInstance(gather_project(), PythonVersionCommand) - - def test_go_project(self): - with temp_directory(change_into=True) as temp_dir: - project_file = temp_dir / "go.mod" - project_file.touch() - version_file = temp_dir / "version.go" - version_file.write_text('var version = "1.2.3"') - - self.assertIsInstance(gather_project(), GoVersionCommand) - - def test_javascript_project(self): - with temp_directory(change_into=True) as temp_dir: - version_file = temp_dir / "package.json" - version_file.write_text( - '{"name": "foo", "version": "1.2.3"}', encoding="utf8" - ) - - self.assertIsInstance(gather_project(), JavaScriptVersionCommand) - - def test_cmake_project_version(self): - with temp_directory(change_into=True) as temp_dir: - version_file = temp_dir / "CMakeLists.txt" - version_file.write_text("project(VERSION 1.2.3)", encoding="utf8") - - self.assertIsInstance(gather_project(), CMakeVersionCommand) +from pontos.version.commands import get_commands class GetCommandsTestCase(unittest.TestCase):