def test_a_game_file_should_be_saved(self): game = Game() game.initial_sudoku = SudokuBoard() game.initial_sudoku.from_dictionary(self.puzzle, True) game_writer = SudokuGameWriter() game_writer.write(game, 'test_game.sgf') game_file = open('test_game.sgf', 'rb') read_game = pickle.load(game_file) self.assertEqual(game.initial_sudoku.to_dictionary(), read_game.initial_sudoku.to_dictionary())
def execute(self): ''' execute the command taking account the parameters of the command ''' if self.game == None: raise InvalidCmdParametersException("The command needs a game.") game_writer = SudokuGameWriter() working_directory = self.game.settings_manager.settings.getPath() if working_directory == '': working_directory = os.getcwd() file_name = self.readconfig_parameters[self.INPUT_PARAM] if os.path.dirname(file_name) == '': file_name = working_directory + os.sep + file_name game_writer.write(self.game, file_name)
def test_an_exception_should_be_raised_when_the_path_is_invalid(self): with self.assertRaises(FileNotFoundError): game = Game() game_writer = SudokuGameWriter() game_writer.write(game, 'Z:\test_game.sgf')
def test_a_new_game_file_should_be_created_when_a_file_with_the_same_name_exists(self): game = Game() game_writer = SudokuGameWriter() game_writer.write(game, 'test_game.sgf') self.file_name = game_writer.write(game, 'test_game.sgf') self.assertTrue(os.path.isfile(self.file_name))