Debian Codegraph @

test/units/cli/galaxy/test_get_collection_widths.py

raw
1 # -*- coding: utf-8 -*-
2 # Copyright (c) 2020 Ansible Project
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import annotations
6
7 import pytest
8
9 from ansible.cli.galaxy import _get_collection_widths
10 from ansible.galaxy.dependency_resolution.dataclasses import Requirement
11
12
13 @pytest.fixture
14 def collection_objects():
15 collection_ham = Requirement('sandwiches.ham', '1.5.0', None, 'galaxy', None)
16
17 collection_pbj = Requirement('sandwiches.pbj', '2.5', None, 'galaxy', None)
18
19 collection_reuben = Requirement('sandwiches.reuben', '4', None, 'galaxy', None)
20
21 return [collection_ham, collection_pbj, collection_reuben]
22
23
24 def test_get_collection_widths(collection_objects):
25 assert _get_collection_widths(collection_objects) == (17, 5)
26
27
28 def test_get_collection_widths_single_collection(mocker):
29 mocked_collection = Requirement('sandwiches.club', '3.0.0', None, 'galaxy', None)
30 # Make this look like it is not iterable
31 mocker.patch('ansible.cli.galaxy.is_iterable', return_value=False)
32
33 assert _get_collection_widths(mocked_collection) == (15, 5)