Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ReviewVerb #25

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/spell_check.words
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
addfinalizer
apache
archlinux
autouse
bubblify
colcon
committish
Expand Down Expand Up @@ -30,6 +31,7 @@ metafunc
mktemp
mypy
namedtuple
noop
noqa
patchset
pathlib
Expand Down
78 changes: 78 additions & 0 deletions test/test_verb_review.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2024 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
from typing import List
from typing import Optional
from typing import Tuple
from unittest.mock import Mock
from unittest.mock import patch

from colcon_core.command import CommandContext
from colcon_core.plugin_system import satisfies_version
import pytest
from rosdistro_reviewer.element_analyzer import ElementAnalyzerExtensionPoint
from rosdistro_reviewer.review import Annotation
from rosdistro_reviewer.review import Criterion
from rosdistro_reviewer.submitter import ReviewSubmitterExtensionPoint
from rosdistro_reviewer.verb.review import ReviewVerb


class NoopAnalyzer(ElementAnalyzerExtensionPoint):

def __init__(self): # noqa: D107
super().__init__()
satisfies_version(
ElementAnalyzerExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')

def analyze( # noqa: D102
self,
path: Path,
target_ref: Optional[str] = None,
head_ref: Optional[str] = None,
) -> Tuple[Optional[List[Criterion]], Optional[List[Annotation]]]:
return None, None


class NoopSubmitter(ReviewSubmitterExtensionPoint):

def __init__(self): # noqa: D107
super().__init__()
satisfies_version(
ReviewSubmitterExtensionPoint.EXTENSION_POINT_VERSION, '^1.0')

def submit(self, args, review) -> None: # noqa: D102
pass


@pytest.fixture(scope='module', autouse=True)
def patch_get_element_analyzer_extensions():
with patch(
'rosdistro_reviewer.element_analyzer.get_element_analyzer_extensions',
return_value={'noop': NoopAnalyzer()},
) as get_element_analyzer_extensions:
yield get_element_analyzer_extensions


@pytest.fixture(scope='module', autouse=True)
def patch_get_review_submitter_extensions():
with patch(
'rosdistro_reviewer.submitter.get_review_submitter_extensions',
return_value={'noop': NoopSubmitter()},
) as get_review_submitter_extensions:
yield get_review_submitter_extensions


def test_verb_review(empty_repo):
extension = ReviewVerb()
extension.add_arguments(parser=Mock())

context = CommandContext(
command_name='rosdistro-reviewer',
args=Mock())

with patch(
'rosdistro_reviewer.verb.review.Path.cwd',
return_value=Path(empty_repo.working_tree_dir),
):
assert 0 == extension.main(context=context)
Loading