Skip to content

Commit 25cde12

Browse files
committed
Returns class instance from property multiplcation
1 parent 0ea7bb9 commit 25cde12

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/property_utils/properties/property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def __mul__(self, other) -> "Property":
213213
<Property: 3000 (m^2) * K>
214214
"""
215215
if isinstance(other, (float, int)):
216-
return Property(self.value * other, self.unit)
216+
return self.__class__(self.value * other, self.unit)
217217
if isinstance(other, Property):
218218
_other = self._unit_preconversion(other)
219219
return Property(

src/property_utils/tests/properties/test_property.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import TestSuite, TextTestRunner
2+
from operator import mul
23

34
from unittest_extensions import args, TestCase
45

@@ -358,6 +359,19 @@ def test_with_zero_value_property(self):
358359
self.assert_result("0.0 (A^3) / (B^3)")
359360

360361

362+
class TestPropertyMultiplicationResultClass(TestProperty):
363+
def subject(self, left, right):
364+
return mul(left, right)
365+
366+
@args({"left": 2, "right": PropUnit1(10, Unit1.A)})
367+
def test_left_multiplication_result_class(self):
368+
self.assertResultIsInstance(PropUnit1)
369+
370+
@args({"left": PropUnit1(20, Unit1.A), "right": 2})
371+
def test_right_multiplication_result_class(self):
372+
self.assertResultIsInstance(PropUnit1)
373+
374+
361375
@add_to(property_test_suite, "__mul__")
362376
class TestCompositeDimensionPropertyUnitPreconversionMultiplication(TestProperty):
363377

0 commit comments

Comments
 (0)