mirror of
https://github.com/HorlogeSkynet/archey4
synced 2025-04-13 16:00:15 +02:00
[LOGOS][TEST] Implements consistency checks between distro IDs and logos
This commit is contained in:
parent
ba3a8dafb4
commit
5bda300051
@ -3,8 +3,9 @@
|
||||
import pkgutil
|
||||
import unittest
|
||||
|
||||
from archey.colors import Colors
|
||||
from archey import logos
|
||||
from archey.colors import Colors
|
||||
from archey.distributions import Distributions
|
||||
from archey.logos import get_logo_width, lazy_load_logo_module
|
||||
|
||||
|
||||
@ -12,17 +13,27 @@ class TestLogos(unittest.TestCase):
|
||||
"""Simple tests checking logos consistency and utility function logic"""
|
||||
def test_distribution_logos_consistency(self):
|
||||
"""
|
||||
Verify each distribution identifier got a logo module.
|
||||
Verify each distribution logo module contain `LOGO` & `COLORS` ("truthy") attributes.
|
||||
Also check they got _consistent_ widths across their respective lines.
|
||||
Additionally verify they don't contain any (useless) empty line.
|
||||
|
||||
This test also indirectly checks `lazy_load_logo_module` behavior!
|
||||
"""
|
||||
for logo_module_info in pkgutil.iter_modules(logos.__path__):
|
||||
distributions_identifiers = Distributions.get_distribution_identifiers()
|
||||
|
||||
for i, logo_module_info in enumerate(pkgutil.iter_modules(logos.__path__), start=1):
|
||||
# `iter_modules` yields `pkgutil.ModuleInfo` named tuple starting with Python 3.6.
|
||||
# So we manually extract the module name from `(module_finder, name, ispkg)` tuple.
|
||||
logo_module_name = logo_module_info[1]
|
||||
|
||||
# Check each logo module name corresponds to a distribution identifier.
|
||||
self.assertIn(
|
||||
logo_module_name,
|
||||
distributions_identifiers,
|
||||
msg='No distribution identifier for [{0}]'.format(logo_module_name)
|
||||
)
|
||||
|
||||
logo_module = lazy_load_logo_module(logo_module_name)
|
||||
|
||||
# Attributes checks.
|
||||
@ -39,7 +50,7 @@ class TestLogos(unittest.TestCase):
|
||||
logo_width = get_logo_width(logo_module.LOGO)
|
||||
|
||||
# Then, check that each logo line got the same effective width.
|
||||
for i, line in enumerate(logo_module.LOGO[1:], start=1):
|
||||
for j, line in enumerate(logo_module.LOGO[1:], start=1):
|
||||
# Here we gotta trick the `get_logo_width` call.
|
||||
# We actually pass each logo line as if it was a "complete" logo.
|
||||
line_width = get_logo_width([line])
|
||||
@ -49,7 +60,7 @@ class TestLogos(unittest.TestCase):
|
||||
line_width,
|
||||
logo_width,
|
||||
msg='[{0}] line index {1}, got an unexpected width {2} (expected {3})'.format(
|
||||
logo_module_name, i, line_width, logo_width
|
||||
logo_module_name, j, line_width, logo_width
|
||||
)
|
||||
)
|
||||
|
||||
@ -57,10 +68,20 @@ class TestLogos(unittest.TestCase):
|
||||
self.assertTrue(
|
||||
Colors.remove_colors(line).strip(),
|
||||
msg='[{0}] line index {1}, got an useless empty line'.format(
|
||||
logo_module_name, i
|
||||
logo_module_name, j
|
||||
)
|
||||
)
|
||||
|
||||
# Finally, check each distributions identifier got a logo!
|
||||
# pylint: disable=undefined-loop-variable
|
||||
self.assertEqual(
|
||||
i,
|
||||
len(distributions_identifiers),
|
||||
msg='[{0}] Expected {1} logo modules, got {2}'.format(
|
||||
logo_module_name, len(distributions_identifiers), i
|
||||
)
|
||||
)
|
||||
|
||||
def test_get_logo_width(self):
|
||||
"""Test `logos.get_logo_width` behavior"""
|
||||
self.assertEqual(
|
||||
|
Loading…
x
Reference in New Issue
Block a user