def main(): parser = argparse.ArgumentParser() parser.add_argument("moduledir", help="Dir containing the Python module.") parser.add_argument("globalstorage_yaml", nargs="?", help="A yaml file to initialize GlobalStorage.") parser.add_argument( "configuration_yaml", nargs="?", help="A yaml file to initialize the configuration dict.") args = parser.parse_args() print("Testing module in: " + args.moduledir) confpath = os.path.join(args.moduledir, "module.desc") with open(confpath) as f: doc = yaml.load(f) if doc["type"] != "job" or doc["interface"] != "python": print("Only Python jobs can be tested.") return 1 libcalamares.globalstorage = libcalamares.GlobalStorage() # if a file for simulating globalStorage contents is provided, load it if args.globalstorage_yaml: with open(args.globalstorage_yaml) as f: gs_doc = yaml.load(f) for key, value in gs_doc.items(): libcalamares.globalstorage.insert(key, value) cfg_doc = dict() if args.configuration_yaml: with open(args.configuration_yaml) as f: cfg_doc = yaml.load(f) libcalamares.job = Job(args.moduledir, doc, cfg_doc) scriptpath = os.path.abspath(args.moduledir) sys.path.append(scriptpath) import main print("Output from module:") print(main.run()) return 0
def test_module(moduledir, globalconfigfilename, moduleconfigfilename, lang): print("Testing module in: " + moduledir) confpath = os.path.join(moduledir, "module.desc") with open(confpath) as f: doc = yaml.load(f) if doc["type"] != "job" or doc["interface"] != "python": print("Only Python jobs can be tested.") return 1 # Parameter None creates a new, empty GlobalStorage libcalamares.globalstorage = libcalamares.GlobalStorage(None) libcalamares.globalstorage.insert("testing", True) if lang: libcalamares.globalstorage.insert("locale", lang) libcalamares.globalstorage.insert("localeConf", {"LANG": lang}) # if a file for simulating globalStorage contents is provided, load it if globalconfigfilename: with open(globalconfigfilename) as f: gs_doc = yaml.load(f) for key, value in gs_doc.items(): libcalamares.globalstorage.insert(key, value) print("Global configuration '" + globalconfigfilename + "' loaded.") else: print("No global configuration loaded.") cfg_doc = dict() if moduleconfigfilename: with open(moduleconfigfilename) as f: cfg_doc = yaml.load(f) print("Local configuration '" + moduleconfigfilename + "' loaded.") else: print("No module configuration loaded.") libcalamares.job = Job(moduledir, doc, cfg_doc) scriptpath = os.path.abspath(moduledir) sys.path.append(scriptpath) import main # Assumed to import main from module itself print("Output from module:") print(main.run()) return 0
# Calamares Boilerplate import libcalamares libcalamares.globalstorage = libcalamares.GlobalStorage(None) libcalamares.globalstorage.insert("testing", True) # Module prep-work from src.modules.bootloader import main # Specific Bootloader test g = main.get_efi_suffix_generator("derp@@SERIAL@@") assert g is not None assert g.next() == "derp" # First time, no suffix for n in range(9): print(g.next()) # We called next() 10 times in total, starting from 0 assert g.next() == "derp10" g = main.get_efi_suffix_generator("derp@@RANDOM@@") assert g is not None for n in range(10): print(g.next()) # it's random, nothing to assert g = main.get_efi_suffix_generator("derp@@PHRASE@@") assert g is not None for n in range(10): print(g.next()) # it's random, nothing to assert # Check invalid things try: