예제 #1
0
    def test_constant_values(self):
        """Test enumeration member instantiation from value"""
        self.assertEqual(Distributions('debian'), Distributions.DEBIAN)
        self.assertRaises(ValueError, Distributions, 'unknown')

        # Check `get_identifiers` consistency.
        distributions_identifiers = Distributions.get_identifiers()
        self.assertTrue(isinstance(distributions_identifiers, list))
        self.assertTrue(
            all(isinstance(i, str) for i in distributions_identifiers))
예제 #2
0
def args_parsing() -> argparse.Namespace:
    """Simple wrapper to `argparse`"""
    parser = argparse.ArgumentParser(prog='archey')
    parser.add_argument(
        '-c',
        '--config-path',
        metavar='PATH',
        help=
        'path to a configuration file, or a directory containing a `config.json`'
    )
    parser.add_argument(
        '-d',
        '--distribution',
        metavar='IDENTIFIER',
        choices=Distributions.get_identifiers(),
        help=
        'supported distribution identifier to show the logo of, pass `unknown` to list them'
    )
    parser.add_argument(
        '-j',
        '--json',
        action='count',
        help=
        'output entries data to JSON format, use multiple times to increase indentation'
    )
    parser.add_argument(
        '-l',
        '--logo-style',
        metavar='IDENTIFIER',
        help=
        "alternative logo style identifier to show instead of the distribution default one. "
        "For instance, you can try 'retro' to prefer old Apple's logo on Darwin platforms"
    )
    parser.add_argument(
        '-s',
        '--screenshot',
        metavar='PATH',
        nargs='?',
        const=False,
        help=
        'take a screenshot once execution is done, optionally specify a target path'
    )
    parser.add_argument('-v',
                        '--version',
                        action='version',
                        version=__version__)
    return parser.parse_args()
예제 #3
0
    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!
        """
        distributions_identifiers = Distributions.get_identifiers()

        for i, logo_module_info in enumerate(pkgutil.iter_modules(
                logos.__path__),
                                             start=1):

            # Check each logo module name corresponds to a distribution identifier.
            self.assertIn(
                logo_module_info.name,
                distributions_identifiers,
                msg=f'No distribution identifier for [{logo_module_info.name}]'
            )

            logo_module = lazy_load_logo_module(logo_module_info.name)

            # Attributes checks.
            self.assertTrue(
                getattr(logo_module, 'LOGO', []),
                msg=
                f'[{logo_module_info.name}] logo module missing `LOGO` attribute'
            )
            self.assertTrue(
                getattr(logo_module, 'COLORS', []),
                msg=
                f'[{logo_module_info.name}] logo module missing `COLORS` attribute'
            )

            # Compute once and for all the number of defined colors for this logo.
            nb_colors = len(logo_module.COLORS)

            # Make Archey compute the logo (effective) width.
            logo_width = get_logo_width(logo_module.LOGO, nb_colors)

            # Then, check that each logo line got the same effective width.
            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], nb_colors)

                # Width check.
                self.assertEqual(
                    line_width,
                    logo_width,
                    msg=
                    '[{}] line index {}, got an unexpected width {} (expected {})'
                    .format(logo_module_info.name, j, line_width, logo_width))

                # Non-empty line check.
                self.assertTrue(
                    Colors.remove_colors(line.format(c=[''] *
                                                     nb_colors)).strip(),
                    msg=
                    f'[{logo_module_info.name}] line index {j}, got an useless empty line'
                )

        # Finally, check each distributions identifier got a logo!
        # pylint: disable=undefined-loop-variable
        self.assertEqual(i,
                         len(distributions_identifiers),
                         msg='[{}] Expected {} logo modules, got {}'.format(
                             logo_module_info.name,
                             len(distributions_identifiers), i))