summaryrefslogtreecommitdiff
path: root/tests/test_subcmds_list.py
blob: 29a7032f31f99788f26dd72da3b21b28473cbc9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright (C) 2026 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Unittests for the list subcmd."""

from typing import List, Optional
from unittest import mock

import pytest

import subcmds


@pytest.mark.parametrize(
    ("extra_args", "expected_groups", "expected_missing_ok"),
    [
        (["--groups", "special"], "special", None),
        (["--all"], None, True),
    ],
    ids=("groups", "all"),
)
def test_list_regex_passes_groups_and_all(
    extra_args: List[str],
    expected_groups: Optional[str],
    expected_missing_ok: Optional[bool],
) -> None:
    """Pass --groups and --all through in regex mode."""
    cmd = subcmds.list.List()

    opts, args = cmd.OptionParser.parse_args(
        ["--regex", *extra_args, "project"]
    )

    with mock.patch.object(
        cmd,
        "FindProjects",
        return_value=[],
    ) as find_projects:
        cmd.Execute(opts, args)

    find_projects.assert_called_once_with(
        ["project"],
        groups=expected_groups,
        missing_ok=expected_missing_ok,
        all_manifests=True,
    )