Source code for tests.test_platform_data

# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

from __future__ import annotations

import ast
import inspect
from operator import attrgetter
from pathlib import Path
from string import ascii_lowercase, digits

import pytest

from extra_platforms import ALL_GROUP_IDS, ALL_IDS, ALL_PLATFORMS, ALL_TRAIT_IDS
from extra_platforms import platform_data as platform_data_module

all_platforms_params = pytest.mark.parametrize(
    "platform", list(ALL_PLATFORMS), ids=attrgetter("id")
)


[docs] def test_platform_data_sorting(): """Platform instances must be sorted alphabetically.""" platform_instance_ids = [] tree = ast.parse(Path(inspect.getfile(platform_data_module)).read_bytes()) for node in tree.body: if ( isinstance(node, ast.Assign) and isinstance(node.value, ast.Call) and node.value.func.id == "Platform" ): assert len(node.targets) == 1 instance_id = node.targets[0].id assert instance_id.isupper() platform_instance_ids.append(instance_id) assert platform_instance_ids == sorted(platform_instance_ids)
[docs] @all_platforms_params def test_platform_definitions(platform): assert platform # ID. assert platform.id assert platform.id.isascii() assert platform.id[0] in ascii_lowercase assert platform.id[-1] in ascii_lowercase + digits assert set(platform.id).issubset(ascii_lowercase + digits + "_") assert platform.id.islower() # Platforms are not allowed to start with all_ or any_, which is reserved # for groups. Use unknown_ prefix instead. assert not platform.id.startswith(("all_", "any_")) assert platform.id in ALL_TRAIT_IDS assert platform.id not in ALL_GROUP_IDS assert platform.id in ALL_IDS # Name. assert platform.name assert platform.name.isascii() assert platform.name.isprintable() # Icon. assert platform.icon assert 2 >= len(platform.icon) >= 1 # URL. assert platform.url assert platform.url.startswith("https://") # Info. assert platform.info() for k, v in platform.info().items(): assert set(k).issubset(ascii_lowercase + "_") if v is not None: assert isinstance(v, (str, bool, dict)) if isinstance(v, str): assert v elif isinstance(v, dict): assert v for k1, v1 in v.items(): assert set(k1).issubset(ascii_lowercase + "_") if v1 is not None: assert v1 assert platform.info()["id"] == platform.id