Skip to content

Commit

Permalink
Returns class instance from property multiplcation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxcode123 committed May 20, 2024
1 parent 0ea7bb9 commit e65f658
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/property_utils/properties/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __mul__(self, other) -> "Property":
<Property: 3000 (m^2) * K>
"""
if isinstance(other, (float, int)):
return Property(self.value * other, self.unit)
return self.__class__(self.value * other, self.unit)
if isinstance(other, Property):
_other = self._unit_preconversion(other)
return Property(
Expand Down
14 changes: 14 additions & 0 deletions src/property_utils/tests/properties/test_property.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import TestSuite, TextTestRunner
from operator import mul

from unittest_extensions import args, TestCase

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


class TestPropertyMultiplicationResultClass(TestProperty):
def subject(self, left, right):
return mul(left, right)

@args({"left": 2, "right": PropUnit1(10, Unit1.A)})
def test_left_multiplication_result_class(self):
self.assertResultIsInstance(PropUnit1)

@args({"left": PropUnit1(20, Unit1.A), "right": 2})
def test_right_multiplication_result_class(self):
self.assertResultIsInstance(PropUnit1)


@add_to(property_test_suite, "__mul__")
class TestCompositeDimensionPropertyUnitPreconversionMultiplication(TestProperty):

Expand Down

0 comments on commit e65f658

Please sign in to comment.