How to use _check_results method in autotest

Best Python code snippet using autotest_python

test_stockvaluation.py

Source:test_stockvaluation.py Github

copy

Full Screen

...71 all_amls = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids72 if self.sale_order1.picking_ids.move_lines.account_move_ids:73 all_amls |= self.sale_order1.picking_ids.move_lines.account_move_ids.line_ids74 return all_amls75 def _check_results(self, expected_aml, expected_aml_count, all_amls):76 # Construct a dict similar to `expected_aml` with `all_amls` in order to77 # compare them.78 result_aml = {}79 for aml in all_amls:80 account_id = aml.account_id.id81 if result_aml.get(account_id):82 debit = result_aml[account_id][0]83 credit = result_aml[account_id][1]84 result_aml[account_id] = (debit + aml.debit, credit + aml.credit)85 else:86 result_aml[account_id] = (aml.debit, aml.credit)87 self.assertEqual(len(all_amls), expected_aml_count)88 for k, v in expected_aml.items():89 self.assertEqual(result_aml[k], v)90 # -------------------------------------------------------------------------91 # Continental92 # -------------------------------------------------------------------------93 def test_dropship_standard_perpetual_continental_ordered(self):94 self.env.company.anglo_saxon_accounting = False95 self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'96 self.product1.product_tmpl_id.standard_price = 1097 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'98 self.product1.product_tmpl_id.invoice_policy = 'order'99 all_amls = self._dropship_product1()100 expected_aml = {101 self.company_data['default_account_payable'].id: (0.0, 8.0),102 self.company_data['default_account_expense'].id: (8.0, 0.0),103 self.company_data['default_account_receivable'].id: (12.0, 0.0),104 self.company_data['default_account_revenue'].id: (0.0, 12.0),105 }106 self._check_results(expected_aml, 4, all_amls)107 def test_dropship_standard_perpetual_continental_delivered(self):108 self.env.company.anglo_saxon_accounting = False109 self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'110 self.product1.product_tmpl_id.standard_price = 10111 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'112 self.product1.product_tmpl_id.invoice_policy = 'delivery'113 all_amls = self._dropship_product1()114 expected_aml = {115 self.company_data['default_account_payable'].id: (0.0, 8.0),116 self.company_data['default_account_expense'].id: (8.0, 0.0),117 self.company_data['default_account_receivable'].id: (12.0, 0.0),118 self.company_data['default_account_revenue'].id: (0.0, 12.0),119 }120 self._check_results(expected_aml, 4, all_amls)121 def test_dropship_fifo_perpetual_continental_ordered(self):122 self.env.company.anglo_saxon_accounting = False123 self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'124 self.product1.product_tmpl_id.standard_price = 10125 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'126 self.product1.product_tmpl_id.invoice_policy = 'order'127 all_amls = self._dropship_product1()128 expected_aml = {129 self.company_data['default_account_payable'].id: (0.0, 8.0),130 self.company_data['default_account_expense'].id: (8.0, 0.0),131 self.company_data['default_account_receivable'].id: (12.0, 0.0),132 self.company_data['default_account_revenue'].id: (0.0, 12.0),133 }134 self._check_results(expected_aml, 4, all_amls)135 def test_dropship_fifo_perpetual_continental_delivered(self):136 self.env.company.anglo_saxon_accounting = False137 self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'138 self.product1.product_tmpl_id.standard_price = 10139 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'140 self.product1.product_tmpl_id.invoice_policy = 'delivery'141 all_amls = self._dropship_product1()142 expected_aml = {143 self.company_data['default_account_payable'].id: (0.0, 8.0),144 self.company_data['default_account_expense'].id: (8.0, 0.0),145 self.company_data['default_account_receivable'].id: (12.0, 0.0),146 self.company_data['default_account_revenue'].id: (0.0, 12.0),147 }148 self._check_results(expected_aml, 4, all_amls)149 # -------------------------------------------------------------------------150 # Anglosaxon151 # -------------------------------------------------------------------------152 def test_dropship_standard_perpetual_anglosaxon_ordered(self):153 self.env.company.anglo_saxon_accounting = True154 self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'155 self.product1.product_tmpl_id.standard_price = 10156 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'157 self.product1.product_tmpl_id.invoice_policy = 'order'158 all_amls = self._dropship_product1()159 expected_aml = {160 self.company_data['default_account_payable'].id: (0.0, 8.0),161 self.company_data['default_account_expense'].id: (10.0, 0.0),162 self.company_data['default_account_receivable'].id: (12.0, 0.0),163 self.company_data['default_account_revenue'].id: (0.0, 12.0),164 self.company_data['default_account_stock_in'].id: (8.0, 10.0),165 self.company_data['default_account_stock_out'].id: (10.0, 10.0),166 }167 # Interim IN is not balanced because because there's a difference between the po line168 # price unit and the standard price. We could set a price difference account on the169 # category to compensate.170 self._check_results(expected_aml, 10, all_amls)171 def test_dropship_standard_perpetual_anglosaxon_delivered(self):172 self.env.company.anglo_saxon_accounting = True173 self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'174 self.product1.product_tmpl_id.standard_price = 10175 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'176 self.product1.product_tmpl_id.invoice_policy = 'delivery'177 all_amls = self._dropship_product1()178 expected_aml = {179 self.company_data['default_account_payable'].id: (0.0, 8.0),180 self.company_data['default_account_expense'].id: (10.0, 0.0),181 self.company_data['default_account_receivable'].id: (12.0, 0.0),182 self.company_data['default_account_revenue'].id: (0.0, 12.0),183 self.company_data['default_account_stock_in'].id: (8.0, 10.0),184 self.company_data['default_account_stock_out'].id: (10.0, 10.0),185 }186 # Interim IN is not balanced because because there's a difference between the po line187 # price unit and the standard price. We could set a price difference account on the188 # category to compensate.189 self._check_results(expected_aml, 10, all_amls)190 def test_dropship_fifo_perpetual_anglosaxon_ordered(self):191 self.env.company.anglo_saxon_accounting = True192 self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'193 self.product1.product_tmpl_id.standard_price = 10194 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'195 self.product1.product_tmpl_id.invoice_policy = 'order'196 all_amls = self._dropship_product1()197 expected_aml = {198 self.company_data['default_account_payable'].id: (0.0, 8.0),199 self.company_data['default_account_expense'].id: (8.0, 0.0),200 self.company_data['default_account_receivable'].id: (12.0, 0.0),201 self.company_data['default_account_revenue'].id: (0.0, 12.0),202 self.company_data['default_account_stock_in'].id: (8.0, 8.0),203 self.company_data['default_account_stock_out'].id: (8.0, 8.0),204 }205 self._check_results(expected_aml, 10, all_amls)206 def test_dropship_fifo_perpetual_anglosaxon_delivered(self):207 self.env.company.anglo_saxon_accounting = True208 self.product1.product_tmpl_id.categ_id.property_cost_method = 'fifo'209 self.product1.product_tmpl_id.standard_price = 10210 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'211 self.product1.product_tmpl_id.invoice_policy = 'delivery'212 all_amls = self._dropship_product1()213 expected_aml = {214 self.company_data['default_account_payable'].id: (0.0, 8.0),215 self.company_data['default_account_expense'].id: (8.0, 0.0),216 self.company_data['default_account_receivable'].id: (12.0, 0.0),217 self.company_data['default_account_revenue'].id: (0.0, 12.0),218 self.company_data['default_account_stock_in'].id: (8.0, 8.0),219 self.company_data['default_account_stock_out'].id: (8.0, 8.0),220 }221 self._check_results(expected_aml, 10, all_amls)222 def test_dropship_standard_perpetual_anglosaxon_ordered_return(self):223 self.env.company.anglo_saxon_accounting = True224 self.product1.product_tmpl_id.categ_id.property_cost_method = 'standard'225 self.product1.product_tmpl_id.standard_price = 10226 self.product1.product_tmpl_id.categ_id.property_valuation = 'real_time'227 self.product1.product_tmpl_id.invoice_policy = 'order'228 all_amls = self._dropship_product1()229 # return what we've done230 stock_return_picking_form = Form(self.env['stock.return.picking']231 .with_context(active_ids=self.sale_order1.picking_ids.ids, active_id=self.sale_order1.picking_ids.ids[0],232 active_model='stock.picking'))233 stock_return_picking = stock_return_picking_form.save()234 stock_return_picking_action = stock_return_picking.create_returns()235 return_pick = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])236 return_pick.move_lines[0].move_line_ids[0].qty_done = 1.0237 return_pick._action_done()238 self.assertEqual(return_pick.move_lines._is_dropshipped_returned(), True)239 all_amls_return = self.vendor_bill1.line_ids + self.customer_invoice1.line_ids240 if self.sale_order1.picking_ids.mapped('move_lines.account_move_ids'):241 all_amls_return |= self.sale_order1.picking_ids.mapped('move_lines.account_move_ids.line_ids')242 # Two extra AML should have been created for the return243 expected_aml = {244 self.company_data['default_account_stock_in'].id: (10.0, 0.0),245 self.company_data['default_account_stock_out'].id: (0.0, 10.0),246 }...

Full Screen

Full Screen

beam_search_test.py

Source:beam_search_test.py Github

copy

Full Screen

...42 [3, 4, 5, 5, 5]]43 )44 # This is what the log probs should look like for each item in the batch.45 self.expected_log_probs = np.log(np.array([0.4, 0.3, 0.2])) # pylint: disable=assignment-from-no-return46 def _check_results(self,47 batch_size: int = 5,48 expected_top_k: np.array = None,49 expected_log_probs: np.array = None,50 beam_search: BeamSearch = None,51 state: Dict[str, torch.Tensor] = None) -> None:52 expected_top_k = expected_top_k if expected_top_k is not None else self.expected_top_k53 expected_log_probs = expected_log_probs if expected_log_probs is not None else self.expected_log_probs54 state = state or {}55 beam_search = beam_search or self.beam_search56 beam_size = beam_search.beam_size57 initial_predictions = torch.tensor([0] * batch_size) # pylint: disable=not-callable58 top_k, log_probs = beam_search.search(initial_predictions, state, take_step) # type: ignore59 # top_k should be shape `(batch_size, beam_size, max_predicted_length)`.60 assert list(top_k.size())[:-1] == [batch_size, beam_size]61 np.testing.assert_array_equal(top_k[0].numpy(), expected_top_k)62 # log_probs should be shape `(batch_size, beam_size, max_predicted_length)`.63 assert list(log_probs.size()) == [batch_size, beam_size]64 np.testing.assert_allclose(log_probs[0].numpy(), expected_log_probs)65 def test_search(self):66 self._check_results()67 def test_finished_state(self):68 state = {}69 state["foo"] = torch.tensor( # pylint: disable=not-callable70 [[1, 0, 1],71 [2, 0, 1],72 [0, 0, 1],73 [1, 1, 1],74 [0, 0, 0]]75 )76 # shape: (batch_size, 3)77 expected_finished_state = {}78 expected_finished_state["foo"] = np.array(79 [[1, 0, 1],80 [1, 0, 1],81 [1, 0, 1],82 [2, 0, 1],83 [2, 0, 1],84 [2, 0, 1],85 [0, 0, 1],86 [0, 0, 1],87 [0, 0, 1],88 [1, 1, 1],89 [1, 1, 1],90 [1, 1, 1],91 [0, 0, 0],92 [0, 0, 0],93 [0, 0, 0]]94 )95 # shape: (batch_size x beam_size, 3)96 self._check_results(state=state)97 # check finished state.98 for key, array in expected_finished_state.items():99 np.testing.assert_allclose(state[key].numpy(), array)100 def test_batch_size_of_one(self):101 self._check_results(batch_size=1)102 def test_greedy_search(self):103 beam_search = BeamSearch(self.end_index, beam_size=1)104 expected_top_k = np.array([[1, 2, 3, 4, 5]])105 expected_log_probs = np.log(np.array([0.4])) # pylint: disable=assignment-from-no-return106 self._check_results(expected_top_k=expected_top_k,107 expected_log_probs=expected_log_probs,108 beam_search=beam_search)109 def test_early_stopping(self):110 """111 Checks case where beam search will reach `max_steps` before finding end tokens.112 """113 beam_search = BeamSearch(self.end_index, beam_size=3, max_steps=3)114 expected_top_k = np.array(115 [[1, 2, 3],116 [2, 3, 4],117 [3, 4, 5]]118 )119 expected_log_probs = np.log(np.array([0.4, 0.3, 0.2])) # pylint: disable=assignment-from-no-return120 self._check_results(expected_top_k=expected_top_k,121 expected_log_probs=expected_log_probs,122 beam_search=beam_search)123 def test_different_per_node_beam_size(self):124 # per_node_beam_size = 1125 beam_search = BeamSearch(self.end_index, beam_size=3, per_node_beam_size=1)126 self._check_results(beam_search=beam_search)127 # per_node_beam_size = 2128 beam_search = BeamSearch(self.end_index, beam_size=3, per_node_beam_size=2)129 self._check_results(beam_search=beam_search)130 def test_catch_bad_config(self):131 """132 If `per_node_beam_size` (which defaults to `beam_size`) is larger than133 the size of the target vocabulary, `BeamSearch.search` should raise134 a ConfigurationError.135 """136 beam_search = BeamSearch(self.end_index, beam_size=20)137 with pytest.raises(ConfigurationError):138 self._check_results(beam_search=beam_search)139 def test_warn_for_bad_log_probs(self):140 # The only valid next step from the initial predictions is the end index.141 # But with a beam size of 3, the call to `topk` to find the 3 most likely142 # next beams will result in 2 new beams that are invalid, in that have probability of 0.143 # The beam search should warn us of this.144 initial_predictions = torch.LongTensor([self.end_index-1, self.end_index-1])145 with pytest.warns(RuntimeWarning, match="Infinite log probabilities"):146 self.beam_search.search(initial_predictions, {}, take_step)147 def test_empty_sequences(self):148 initial_predictions = torch.LongTensor([self.end_index-1, self.end_index-1])149 beam_search = BeamSearch(self.end_index, beam_size=1)150 with pytest.warns(RuntimeWarning, match="Empty sequences predicted"):151 predictions, log_probs = beam_search.search(initial_predictions, {}, take_step)152 # predictions hould have shape `(batch_size, beam_size, max_predicted_length)`....

Full Screen

Full Screen

test_shared_resolve_dice.py

Source:test_shared_resolve_dice.py Github

copy

Full Screen

...5 def test_no_danger(self):6 action_dice = [1, 2, 3]7 danger_dice = []8 expected_result = [1, 2, 3]9 self._check_results(action_dice, danger_dice, expected_result)10 def test_no_matching_danger(self):11 action_dice = [1, 2, 3]12 danger_dice = [4]13 expected_result = [1, 2, 3]14 self._check_results(action_dice, danger_dice, expected_result)15 def test_single_matching(self):16 action_dice = [1, 2, 3]17 danger_dice = [1]18 expected_result = [2, 3]19 self._check_results(action_dice, danger_dice, expected_result)20 def test_multiple_matching(self):21 action_dice = [1, 2, 3]22 danger_dice = [1, 2]23 expected_result = [3]24 self._check_results(action_dice, danger_dice, expected_result)25 def test_multiple_matching_duplicate(self):26 action_dice = [1, 1, 1, 2, 3]27 danger_dice = [1, 1]28 expected_result = [1, 2, 3]29 self._check_results(action_dice, danger_dice, expected_result)30 def test_remove_all_action(self):31 action_dice = [1, 1]32 danger_dice = [1, 1]33 expected_result = []34 self._check_results(action_dice, danger_dice, expected_result)35 def _check_results(self, action_dice, danger_dice, expected_result):36 result_dice = resolve_dice(action_dice, danger_dice)37 self.assertEqual(expected_result, result_dice)38if __name__ == '__main__':...

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 autotest 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