diff --git a/tests/xlfunctions/test_logical.py b/tests/xlfunctions/test_logical.py index fb64327..4c779d4 100644 --- a/tests/xlfunctions/test_logical.py +++ b/tests/xlfunctions/test_logical.py @@ -54,8 +54,14 @@ def test_TRUE(self): self.assertTrue(logical.TRUE()) def test_IFERROR(self): - self.assertEqual(logical.IFERROR(10/2,0),5) # Check if value is OK - self.assertEqual(logical.IFERROR(10/0,0),0) # Check if value cause error - self.assertEqual(logical.IFERROR(10/0,"ERROR"),"ERROR") # Check returning string - self.assertEqual(logical.IFERROR(logical.IFERROR(10/0,0) + 1,0),1) # Check nested IFERROR - + num_error = xlerrors.NumExcelError() + div_ziro_error = xlerrors.DivZeroExcelError() + # Check if value is valid + self.assertEqual(logical.IFERROR(10 / 2, 0), 5) + # Check if value cause error + self.assertEqual(logical.IFERROR(div_ziro_error, 0), 0) + # Check returning string + self.assertEqual(logical.IFERROR(num_error, "ERROR"), "ERROR") + # Check nested IFERROR + self.assertEqual(logical.IFERROR(logical.IFERROR(div_ziro_error, + 0) + 1, 0), 1) diff --git a/tests/xlfunctions_vs_excel/iferror_test.py b/tests/xlfunctions_vs_excel/iferror_test.py index 9713a8b..47fbbb4 100644 --- a/tests/xlfunctions_vs_excel/iferror_test.py +++ b/tests/xlfunctions_vs_excel/iferror_test.py @@ -1,7 +1,5 @@ from .. import testing -from xlcalculator.xlfunctions import xlerrors - class SqrtTest(testing.FunctionalTestCase): filename = "IFERROR.xlsx" @@ -17,19 +15,19 @@ def test_evaluation_C2(self): self.evaluator.get_cell_value('Sheet1!C2!'), self.evaluator.evaluate('Sheet1!C2') ) - + def test_evaluation_C3(self): self.assertEqual( self.evaluator.get_cell_value('Sheet1!C3!'), self.evaluator.evaluate('Sheet1!C3') ) - + def test_evaluation_C4(self): self.assertEqual( self.evaluator.get_cell_value('Sheet1!C4!'), self.evaluator.evaluate('Sheet1!C4') ) - + def test_evaluation_C5(self): self.assertEqual( self.evaluator.get_cell_value('Sheet1!C5!'), diff --git a/xlcalculator/parser.py b/xlcalculator/parser.py index 48bd064..ef230ac 100644 --- a/xlcalculator/parser.py +++ b/xlcalculator/parser.py @@ -120,7 +120,7 @@ def shunting_yard(self, raw_tokens, named_ranges, tokenize_range=False): for index, token in enumerate(tokens): new_tokens.append(token) - if type(token.tvalue) == str: + if type(token.tvalue) is str: # example -> :OFFSET( or simply :A10 if token.tvalue.startswith(':'): diff --git a/xlcalculator/xlfunctions/logical.py b/xlcalculator/xlfunctions/logical.py index 609ed5a..85b1103 100644 --- a/xlcalculator/xlfunctions/logical.py +++ b/xlcalculator/xlfunctions/logical.py @@ -102,12 +102,13 @@ def TRUE() -> func_xltypes.XlBoolean: """ return True + @xl.register() @xl.validate_args -def IFERROR(value: func_xltypes.XlExpr, - value_if_error: func_xltypes.XlAnything) -> func_xltypes.XlAnything: - """Evaluate value, return value if has no error, otherwise return value_if_error. - +def IFERROR(value: func_xltypes.XlExpr, value_if_error: func_xltypes.XlAnything + ) -> func_xltypes.XlAnything: + """Evaluate value, return value if has no error, + otherwise return value_if_error. https://support.microsoft.com/en-au/office/iferror-function-c526fd07-caeb-47b8-8bb6-63f3e417f611 """ if isinstance(value(), xlerrors.ExcelError):