Skip to content

Commit

Permalink
Add tests for ReviewVerb (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay authored Oct 4, 2024
1 parent 5c7b810 commit d0c0600
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
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)

0 comments on commit d0c0600

Please sign in to comment.