def test_attributes(): output = True for p_cls in PuzzleManager.getPuzzleClasses(): attrs = ["id", "auth", "name", "desc", "date"] for a in attrs: if not hasattr(p_cls, a) or getattr(p_cls, a) is None: print("%s doesn't have attr %s" % (p_cls.__name__, a)) output = False if not output: raise Exception
def init_data(): for p_cls in PuzzleManager.getPuzzleClasses(): if data["TESTING"]: variants = p_cls.test_variants else: variants = p_cls.variants for variant in variants: s_cls = PuzzleManager.getSolverClass(p_cls.id, variant) puzzle = p_cls.generateStartPosition(variant) solver = s_cls(puzzle, dir_path=data['DATABASE_DIR']) solver.solve(verbose=True)
def test_solution_are_solved(): string = "{} puzzle with variant {} has a solution {} that is not SOLVABLE." for p_cls in PuzzleManager.getPuzzleClasses(): for variantid in p_cls.variants: puzzle = p_cls.generateStartPosition(variantid) solutions = puzzle.generateSolutions() if solutions is not None: for sol in solutions: assert sol.primitive( ) == PuzzleValue.SOLVABLE, string.format( p_cls.name, variantid, sol.toString(mode="minimal")) # Add an additional test for undo moves
def server_start(): # Check which Puzzles have been solved or not solved for p_cls in PuzzleManager.getPuzzleClasses(): if p_cls.id not in puzzle_solved_variants: puzzle_solved_variants[p_cls.id] = {} variants = p_cls.variants for variant in variants: p_cls = PuzzleManager.getPuzzleClass(p_cls.id) s_cls = PuzzleManager.getSolverClass(p_cls.id, variant) puzzle = p_cls.generateStartPosition(variant) solver = s_cls(puzzle, dir_path=app.config['DATABASE_DIR']) if os.path.exists(solver.path): puzzle_solved_variants[p_cls.id][variant] = solver
def database_dir(tmpdir): global db_dir if not db_dir is None: return db_dir for p_cls in PuzzleManager.getPuzzleClasses(): variants = p_cls.test_variants if not variants: warnings.warn( UserWarning( "{} does not have any test variants. It's correctness may vary." .format(p_cls.name))) for variant in variants: s_cls = PuzzleManager.getSolverClass(p_cls.id, variant) puzzle = p_cls.generateStartPosition(variant) solver = s_cls(puzzle, dir_path=tmpdir) solver.solve() db_dir = tmpdir return db_dir
def test_serialize(): for p_cls in PuzzleManager.getPuzzleClasses(): for variantid in p_cls.variants: puzzle = p_cls.generateStartPosition(variantid) p_str = puzzle.toString(mode="minimal") puzzle = p_cls.fromString(p_str)