importosimportsysimporttypesBIN = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, "bin"))
def_load_crossfetch():
if"crossfetch"in sys.modules:
return sys.modules["crossfetch"]
# Load the crossfetch script as a module mod = types.ModuleType("crossfetch")
sys.modules["crossfetch"] = mod
withopen(os.path.join(BIN, "crossfetch")) as f:
code = f.read()
# Skip the shebang lineif code.startswith("#!"):
code ="\n"+ code.split("\n", 1)[1]
exec(code, mod.__dict__)
return mod
deftest_new_emblems_registered():
cf = _load_crossfetch()
for name in ("star", "dove", "thorns"):
assert name in cf.SYMBOLS, name
deftest_new_masks_are_well_formed():
cf = _load_crossfetch()
for name in ("star", "dove", "thorns"):
mask = cf.SYMBOLS[name]
assertlen(mask) >=12, name # tall enough to readassertall(set(row) <= {"#", " "} for row in mask), name
assertsum(row.count("#") for row in mask) >=30, name
deftest_set_symbol_accepts_new_names():
cf = _load_crossfetch()
for name in ("star", "dove", "thorns", "bethlehem", "spirit"):
cf.set_symbol(name)
assert cf.MASK isnot cf.CHI_RHO or name in ("chi",), name
cf.set_symbol("chi") # restore default for other tests