def test_SUM_with_nonnumbers_in_range(self): self.assertEqual(math.SUM(xltypes.Array([[1, 'bad'], [3, 4]])), 8) self.assertEqual( math.SUM( xltypes.Array([[xltypes.Number(1), xltypes.Text('N/A')], [xltypes.Number(3), xltypes.Number(4)]])), 8)
def test__lt___with_decimal_number(self): self.assertEqual((self.value1 < xltypes.Number(2.0)).value, True)
def test__lt___with_Blank(self): self.assertEqual((xltypes.Number(-1) < xltypes.BLANK).value, True) self.assertEqual((self.value1 < xltypes.BLANK).value, False)
def test__sub__with_decimal_number(self): res = xltypes.Number(2) - xltypes.Number(1.0) self.assertIsInstance(res.value, float) self.assertEqual(res.value, 1.0)
def test__sub__with_native_float(self): res = xltypes.Number(2) - 1.0 self.assertIsInstance(res.value, float) self.assertEqual(res.value, 1.0)
def test__add__with_native_float(self): res = xltypes.Number(1) + 2.0 self.assertIsInstance(res.value, float) self.assertEqual(res.value, 3.0)
class AbstractExcelTypeTest: value_zero = xltypes.Number(0) value1 = xltypes.Number(1) native1 = 1 num1 = 1 value1_float = 1 value1_int = 1 value1_text = '1' value1_bool = True value1_dt = datetime.datetime(1900, 1, 1) value2 = xltypes.Number(2) native2 = 2 num2 = 2 text2 = xltypes.Text('2') bool2 = xltypes.Boolean(True) dt2 = xltypes.DateTime(datetime.datetime(2020, 1, 1, 12, 0, 0)) dt2_float = 6523831.0 math_result_type = int def test__add__(self): res = self.value1 + self.value2 self.assertIsNot(res, self.value1) self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 + self.num2) def test__add___with_native_addend(self): res = self.value1 + self.native2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 + self.num2) def test__add__with_Text(self): res = self.value1 + self.text2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 + self.num2) def test__add__with_unconvertible_Text(self): with self.assertRaises(xlerrors.ValueExcelError): self.value1 + xltypes.Text('data') def test__add__with_Boolean(self): res = self.value1 + self.bool2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 + 1) def test__add__with_DateTime(self): res = self.value1 + self.dt2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, float) self.assertEqual(res.value, self.num1 + self.dt2_float) def test__sub__(self): res = self.value1 - self.value2 self.assertIsNot(res, self.value1) self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 - self.num2) def test__sub___with_native_subtrahend(self): res = self.value1 - self.native2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 - self.num2) def test__mul__(self): res = self.value1 * self.value2 self.assertIsNot(res, self.value1) self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 * self.num2) def test__mul___with_native_factor(self): res = self.value1 * self.num2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1 * self.num2) def test__mul__with_DateTime(self): self.assertEqual((self.value1 * self.dt2).value, self.num1 * self.dt2_float) def test__truediv__(self): res = self.value1 / self.value2 self.assertIsNot(res, self.value1) self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, float) self.assertEqual(res.value, self.num1 / self.num2) def test__truediv___by_zero(self): with self.assertRaises(xlerrors.DivZeroExcelError): self.value1 / 0 def test__truediv___with_native_divisor(self): res = self.value1 / self.native2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, float) self.assertEqual(res.value, self.num1 / self.num2) def test__truediv__with_DateTime(self): self.assertEqual((self.value1 / self.dt2).value, self.num1 / self.dt2_float) def test__pow__(self): res = self.value1**self.value2 self.assertIsNot(res, self.value1) self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1**self.num2) def test__pow___with_native_exponent(self): res = self.value1**self.num2 self.assertIsInstance(res, xltypes.Number) self.assertIsInstance(res.value, self.math_result_type) self.assertEqual(res.value, self.num1**self.num2) def test__pow__with_DateTime(self): self.assertEqual((self.value1**self.dt2).value, self.num1**self.dt2_float) def test__lt__(self): res = self.value1 < self.value2 self.assertIsInstance(res, xltypes.Boolean) self.assertIsInstance(res.value, bool) self.assertEqual(res.value, True) def test__lt___with_Text(self): self.assertEqual((self.value1 < xltypes.Text('data')).value, True) def test__lt___with_Boolean(self): self.assertEqual((self.value_zero < self.bool2).value, True) self.assertEqual((self.value2 < self.bool2).value, True) def test__lt___with_DateTime(self): self.assertEqual((self.value1 < self.dt2).value, True) def test__le__(self): self.assertEqual((self.value1 <= self.value2).value, True) self.assertEqual((self.value1 <= self.value1).value, True) self.assertEqual((self.value2 <= self.value1).value, False) def test__eq__(self): self.assertEqual((self.value1 == self.value2).value, False) self.assertEqual((self.value1 == self.value1).value, True) def test__ne__(self): self.assertEqual((self.value1 != self.value2).value, True) self.assertEqual((self.value1 != self.value1).value, False) def test__gt__(self): self.assertEqual((self.value1 > self.value2).value, False) self.assertEqual((self.value2 > self.value1).value, True) def test__ge__(self): self.assertEqual((self.value2 >= self.value1).value, True) self.assertEqual((self.value1 >= self.value1).value, True) self.assertEqual((self.value1 >= self.value2).value, False) def test__and__(self): self.assertEqual((self.value1 & self.value2).value, True) self.assertEqual((self.value1 & self.value_zero).value, False) def test__or__(self): self.assertEqual((self.value_zero | self.value1).value, True) self.assertEqual((self.value_zero | self.value_zero).value, False) def test__int__(self): self.assertEqual(int(self.value1), self.value1_int) self.assertEqual(int(xltypes.Number(self.value1_float)), self.value1_int) def test__float__(self): self.assertEqual(float(self.value1), self.value1_float) self.assertEqual(float(xltypes.Number(self.value1_float)), self.value1_float) def test__str__(self): self.assertEqual(str(self.value1), self.value1_text) def test__bool__(self): self.assertEqual(bool(self.value1), True) self.assertEqual(bool(self.value_zero), False) def test__Number__(self): self.assertEqual(self.value1.__Number__().value, self.num1) def test__Text__(self): text = self.value1.__Text__() self.assertIsInstance(text, xltypes.Text) self.assertEqual(text.value, self.value1_text) def test__Boolean__(self): boolean = self.value1.__Boolean__() self.assertIsInstance(boolean, xltypes.Boolean) self.assertEqual(boolean.value, True) def test__DateTime__(self): dt = self.value1.__DateTime__() self.assertIsInstance(dt, xltypes.DateTime) self.assertEqual(dt.value, self.value1_dt) def test__hash__(self): self.assertEqual(hash(self.value1), hash(self.value1.value))
def test__invert__(self): res = operator.invert(xltypes.Number(2.0)) self.assertIsInstance(res.value, float) self.assertEqual(res.value, -2.0)
def test__add__with_decimal_number(self): res = xltypes.Number(1) + xltypes.Number(2.0) self.assertIsInstance(res.value, float) self.assertEqual(res.value, 3.0)
def test__pos__(self): res = +xltypes.Number(-2.0) self.assertIsInstance(res.value, float) self.assertEqual(res.value, -2.0)
def test__neg__(self): res = -xltypes.Number(2.0) self.assertIsInstance(res.value, float) self.assertEqual(res.value, -2.0)
def test_is_decimal(self): self.assertEqual(xltypes.Number(1).is_decimal, False) self.assertEqual(xltypes.Number(1.0).is_decimal, True)
def test_is_whole(self): self.assertEqual(xltypes.Number(1).is_whole, True) self.assertEqual(xltypes.Number(1.0).is_whole, False)
def test__float__(self): self.assertEqual(float(self.value1), self.value1_float) self.assertEqual(float(xltypes.Number(self.value1_float)), self.value1_float)