def test_constant_values(self): """Test enumeration member instantiation from value""" self.assertEqual(Distributions('debian'), Distributions.DEBIAN) self.assertRaises(ValueError, Distributions, 'unknown') # Check `get_distribution_identifiers` consistency. distribution_identifiers = Distributions.get_distribution_identifiers() self.assertTrue(isinstance(distribution_identifiers, list)) self.assertTrue(all(isinstance(i, str) for i in distribution_identifiers))
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_distribution_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( '-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()
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_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. self.assertTrue( getattr(logo_module, 'LOGO', []), msg='[{0}] logo module missing `LOGO` attribute'.format( logo_module_name)) self.assertTrue( getattr(logo_module, 'COLORS', []), msg='[{0}] logo module missing `COLORS` attribute'.format( logo_module_name)) # Make Archey compute the logo width. logo_width = get_logo_width(logo_module.LOGO) # 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]) # Width check. self.assertEqual( line_width, logo_width, msg= '[{0}] line index {1}, got an unexpected width {2} (expected {3})' .format(logo_module_name, j, line_width, logo_width)) # Non-empty line check. self.assertTrue( Colors.remove_colors(line).strip(), msg='[{0}] line index {1}, got an useless empty line'. format(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))