def test_calculator_soma(self): with patch('src.calculator.calculator.soma', MagicMock()) as mocked_operation: # it will fail since self.calculator was instantiated outside scope # self.calculator.execute_operation(0, self.num1, self.num2) calculator = Calculator() calculator.execute_operation(0, self.num1, self.num2) assert mocked_operation.mock_calls == [call(1, 2)]
def main(operation_code, num1, num2): calculator = Calculator() try: result = calculator.execute_operation(operation_code, num1, num2) print(f'Result is: {result}') except Exception as e: print(e)
def test_calculator_divide(self): with patch('src.calculator.calculator.divide', MagicMock()) as mocked_operation: calculator = Calculator() calculator.execute_operation(3, self.num1, self.num2) assert mocked_operation.mock_calls == [call(1, 2)]
def test_calculator_multiply(self): with patch('src.calculator.calculator.multiply', MagicMock()) as mocked_operation: calculator = Calculator() calculator.execute_operation(2, self.num1, self.num2) assert mocked_operation.mock_calls == [call(1, 2)]