Skip to content

Commit

Permalink
Remove: Drop obsolete gather_project function
Browse files Browse the repository at this point in the history
This function got replaced by Project.gather_project.
  • Loading branch information
bjoernricks committed Mar 2, 2023
1 parent b8982d6 commit 7e41232
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 74 deletions.
22 changes: 2 additions & 20 deletions pontos/version/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,19 @@

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,
PythonVersionCommand,
)


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
55 changes: 1 addition & 54 deletions tests/version/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 7e41232

Please sign in to comment.