How to use is_same_as method in assertpy

Best Python code snippet using assertpy_python

question.py

Source:question.py Github

copy

Full Screen

...22 def __str__(self):23 return self.as_string()24 25 def __eq__(self, other):26 return self.is_same_as(other)27 28 def __lt__(self, other):29 """30 Less difficult questions are lesser than others.31 Same difficulty is random ordered.32 """33 self_diff = self.difficulty()34 other_diff = other.difficulty()35 36 if self_diff == other_diff:37 return random.choice([True, False])38 else:39 return self.difficulty() < other.difficulty()40 41 def as_string(self):42 """43 Returns string representation of question.44 """45 return _repr_obj(self)46 47 def is_same_as(self, other_question):48 """49 Returns True if this question is equal to other_question,50 False otherwise.51 """52 raise NotImplementedError('Question must implement is_same_as()')53 54 def get_class(self):55 """56 Returns question group name.57 """58 return QuestionBase._default_group59 60 def sort_answers_randomly(self):61 """62 Returns True if answers to this question are allowed to be 63 sorted randomly, False otherwise.64 """65 return True66 67 def num_demanded_answers(self):68 """69 Returns the required number of correct answers to be for each question70 to be marked as correct. 0 means that all correct answers must be found.71 """72 return 173 74 def num_answers(self):75 """76 Returns the number of answers to choose from for each question.77 """78 return 879 80 def num_answers_nomalized(self):81 """82 Internal method - do not overwrite!83 Returns the number of answers to choose from.84 """85 num_answers = self.num_answers()86 if num_answers < 2:87 raise Exception('num_answers() must return minimum 2')88 return num_answers89 90 def difficulty(self):91 """92 Evaluates question difficulty. Is used whenever questions93 are sorted by their difficulty.94 95 The higher return value, the more difficult the question.96 """97 return 098 99 def proximate(self, answer):100 """101 Approximate how close an answer is to the question asked.102 Return value must be a float n, where 0 <= n <= 1.103 """104 return 0105 106 def max_similarity(self):107 """108 Returns the maximum allowed similarity between answers to this question.109 Return value must be a float n, where 0 <= n <= 1.110 """111 return 1112113 def maximum_correct_answers(self):114 """115 Returns the maximum number of correct answers for this question.116 """117 return self.num_answers_nomalized()118119 def correct_answer_proximate(self, answer):120 """121 Approximate how close a correct answer is to the question asked.122 Return value must be a float n, where 0 <= n <= 1.123 """124 return 0125 126 def make_answers(self):127 """128 Creates and returns answers to this question.129 Questions may generate any number of answers they like.130 Answers generated by this method does not need to be correct answers.131 132 make_answers() may return either an Answer-object (objects133 inherited from AnswerBase) or an iterator of Answer-objects.134 """135 raise NotImplementedError('Question must implement make_answers()')136 137 def draw(self, to_file):138 """139 Draw question. to_file is path of file to write image data to.140 """141 raise NotImplementedError('Question must implement draw()')142 143 def most_favorable_answer(self, answer1, answer2):144 """145 Decide whether answer1 or answer2 is most favorable146 as an answer to this question.147 148 Returns -1 if answer1 is more favorable than answer2.149 Returns 0 if answer1 and answer2 are equally favorable.150 Returns 1 if answer1 is less favorable than answer2.151 """152 raise NotImplementedError153 154 def favorized_answers(self, all_answers):155 """156 Given a large set of answers, this method returns a sorted list157 of answers, where the first elements (answers) are the most favored.158 Do not edit the original list 'all_answers' - in stead create a new!159 """160 raise NotImplementedError161 162 def pick_answers(self, all_answers):163 """164 Picks answers for this question.165 """166 raise NotImplementedError167 168 def validate_answers(self, picked_answers):169 """170 Check whether question has enough correct answers.171 Raises an exception if it doesn't.172 """173 raise NotImplementedError174 175 # -------------------------------------------------------------------------176 177 # Legacy178 179 def get_group(self, *args, **kwargs):180 return self.get_class(*args, **kwargs)181 182 def required_correct_answers(self, *args, **kwargs):183 return self.num_demanded_answers(*args, **kwargs)184185186class AnswerBase(object):187 def __str__(self):188 return self.as_string()189 190 def __eq__(self, other):191 return self.is_same_as(other)192 193 def __lt__(self, other):194 return self.is_less_than(other)195 196 def as_string(self):197 """198 Returns string representation of answer.199 """200 return _repr_obj(self)201 202 def is_same_as(self, other_answer):203 """204 Returns True if this answer is equal to other_answer,205 False otherwise.206 """207 raise NotImplementedError('Answer must implement is_same_as()')208 209 def similarity(self, other_answer):210 """211 Approximate how similar this answer is to another answer.212 Return value must be a float n, where 0 <= n <= 1.213 """214 return 0215 216 def is_less_than(self, other_answer):217 """218 Determine if this answer is lesser than other_answer.219 Used to sort out which order answers should appear in.220 """221 raise NotImplementedError('Answer must implement is_less_than()') ...

Full Screen

Full Screen

environnement.py

Source:environnement.py Github

copy

Full Screen

...65 empty_case_indice = randomXY(len(self.empty_case_states))66 randomX = self.empty_case_states[empty_case_indice].x67 randomY = self.empty_case_states[empty_case_indice].y68 self.states[randomX, randomY] = newValue69 def is_same_as(self, otherstates):70 for row in range(0,self.length):71 for col in range(0, self.length):72 if not self.states[(row, col)] == otherstates[(row, col)]:73 return False74 return True75 def evaluate_when_game_over(self):76 actionUp = UpActionImpl(current_states=copy(self.states), lenght=self.length)77 actionDown = DownActionImpl(current_states=copy(self.states), lenght=self.length)78 actionLeft = LeftActionImpl(current_states=copy(self.states), lenght=self.length)79 actionRight = RightActionImpl(current_states=copy(self.states), lenght=self.length)80 return self.is_same_as(actionUp.get_states()) and self.is_same_as(actionDown.get_states())\81 and self.is_same_as(actionLeft.get_states()) and self.is_same_as(actionRight.get_states())82 def apply(self, action):83 self.previous_states = self.states84 if action == UP or action == DOWN or action == RIGHT or action == LEFT:85 action_applied = None86 # apply_action87 # permutation action haut et bas pour faire correspondre \88 # l'axe des abscisse (en bas) de l'affichage graphique avec89 # celle du modele réel placé en haut.90 if action == DOWN:91 action_applied = UpActionImpl(current_states=copy(self.states), lenght=self.length)92 elif action == UP:93 action_applied = DownActionImpl(current_states=copy(self.states), lenght=self.length)94 elif action == LEFT:95 action_applied = LeftActionImpl(current_states=copy(self.states), lenght=self.length)96 elif action == RIGHT:97 action_applied = RightActionImpl(current_states=copy(self.states), lenght=self.length)98 if self.is_same_as(action_applied.get_states()) is False:99 self.states = action_applied.get_states()100 self.score = action_applied.get_score()101 # generate new case102 empty_cases = self.count_empty_cases()103 if empty_cases != 0:104 self._generate_random_new_case()105 self._reward = self.score106 else:107 self.score = 0108 self._reward = REWARD_NO_EFFECT109 if self.goal is True:110 self._reward = REWARD_GOAL111 if self.count_empty_cases() == 0 and self.evaluate_when_game_over():112 self._reward = REWARD_GAMEOVER...

Full Screen

Full Screen

test_board.py

Source:test_board.py Github

copy

Full Screen

...3from src.board import Outcome4from src.player import Piece5def test_getitem(after_five_plies):6 board = after_five_plies.board7 assert_that(board[1, 2]).is_same_as(Piece.O)8 assert_that(board[2, 2]).is_same_as(Piece.X)9 assert_that(board[0, 0]).is_none10def test_setitem_in_empty_square(after_five_plies):11 board = after_five_plies.board12 board[0, 0] = Piece.O13 assert_that(board[0, 0]).is_same_as(Piece.O)14def test_setitem_in_occupied_square(after_five_plies):15 board = after_five_plies.board16 with pytest.raises(ValueError):17 board[1, 1] = Piece.O18def test_do_move(after_five_plies):19 game = after_five_plies20 board = game.board21 player = game.players.peek()22 move = (0, 0)23 board.do_move(player, move)24 assert_that(board[move].piece()).is_same_as(player.piece())25def test_check_for_game_over_winner_x(win_for_x):26 assert_that(win_for_x.check_for_game_over()).is_same_as(Outcome.X)27# def test_check_for_game_over_winner_o(win_for_o):28# pass29def test_check_for_game_over_outcome_draw(drawn_game):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful