-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35acbc7
commit cc7aa0e
Showing
3 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from unittest import TestSuite, TextTestRunner | ||
|
||
from unittest_extensions import TestCase, args | ||
|
||
from property_utils.units.converter_types import ( | ||
get_converter, | ||
register_converter, | ||
AbsoluteUnitConverter, | ||
RelativeUnitConverter, | ||
CompositePhysicalPropertyUnitConverter, | ||
) | ||
from property_utils.exceptions.base import ( | ||
PropertyUtilsTypeError, | ||
PropertyUtilsValueError, | ||
) | ||
from property_utils.exceptions.units.converter_types import UndefinedConverter | ||
from property_utils.tests.utils import add_to | ||
from property_utils.tests.units.data import ( | ||
Unit1, | ||
Unit2, | ||
Unit3, | ||
Unit1Converter, | ||
UnregisteredConverter, | ||
Unit1_314Converter, | ||
Unit2Converter, | ||
Unit1Unit2Converter, | ||
) | ||
|
||
converter_types_test_suite = TestSuite() | ||
|
||
converter_types_test_suite.addTests( | ||
[ | ||
(TestGetConverter_test_suite := TestSuite()), | ||
(TestRegisterConverter_test_suite := TestSuite()), | ||
] | ||
) | ||
|
||
|
||
@add_to(TestGetConverter_test_suite) | ||
class TestGetConverter(TestCase): | ||
def subject(self, generic): | ||
return get_converter(generic) | ||
|
||
@args({"generic": Unit1.A}) | ||
def test_with_measurement_unit(self): | ||
self.assertResultRaises(PropertyUtilsTypeError) | ||
|
||
@args({"generic": Unit3}) | ||
def test_with_unregistered_generic(self): | ||
self.assertResultRaises(UndefinedConverter) | ||
|
||
@args({"generic": Unit2}) | ||
def test_with_measurement_unit_type(self): | ||
self.assertResult(Unit2Converter) | ||
|
||
@args({"generic": Unit1**3.14}) | ||
def test_with_generic_dimension(self): | ||
self.assertResult(Unit1_314Converter) | ||
|
||
@args({"generic": Unit1 * Unit2}) | ||
def test_with_generic_composite_dimension(self): | ||
self.assertResult(Unit1Unit2Converter) | ||
|
||
|
||
@add_to(TestRegisterConverter_test_suite) | ||
class TestRegisterConverter(TestCase): | ||
def subject(self, generic): | ||
return register_converter(generic)(UnregisteredConverter) | ||
|
||
@args({"generic": Unit1.A}) | ||
def test_with_measurement_unit(self): | ||
self.assertResultRaises(PropertyUtilsTypeError) | ||
|
||
@args({"generic": Unit1}) | ||
def test_with_registered_converter(self): | ||
self.assertResultRaises(PropertyUtilsValueError) | ||
|
||
@args({"generic": Unit3}) | ||
def test_with_unregistered_converter(self): | ||
self.assertResult(UnregisteredConverter) | ||
self.assertEqual(self.cachedResult().generic_unit_descriptor, Unit3) | ||
|
||
|
||
if __name__ == "__main__": | ||
runner = TextTestRunner() | ||
runner.run(converter_types_test_suite) |
Oops, something went wrong.