-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracebacks in test output #171
Comments
I found that the Exception comes from get_unit_system function in scimath.unit.unit_manager. The cause is the function is given an instance from the scimath.units.smart_unit.SmartUnit which cannot be handled by the current get_unit_system method. With further traceback (using traceback.print_stack()), the problem happens in class Quantity function propagate_data_changes, line new_quantity = self.change_unit_system(predecessor.units). Here, the change_unit_system expects a system or str, but given a unit. |
It seems that the neither the scimath.units.smart_unit nor the scimath.units.unit class has a unit system associate with it. And I haven't find any function that can infer the unitsystem from a unit. Maybe we can just give None to this self.change_unit_system (i.e., quantity.py line 306: new_quantity = self.change_unit_system(predecessor.units) -> new_quantity = self.change_unit_system(None)) that is causing the problem? This will uses the default_system (which works the same as right now) |
I doubt that would work as intended. Here's another test case that should work, but I think will break with current code. def test_propagation2(self):
""" Tests data propagation for a single converted quantity. """
q1 = Quantity(10.0, units='ft', family_name='depth')
q2 = q1.change_unit_system('METRIC')
q2.data = 2 * q2.data
q2.propagate_data_changes()
self.assertAlmostEqual(q1.data, 20.0) When I add the above test method to the ======================================================================
FAIL: test_propagation2 (scimath.units.tests.test_units.test_units)
Tests data propagation for a single converted quantity.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/mdickinson/Enthought/ETS/scimath/scimath/units/tests/test_units.py", line 207, in test_propagation2
self.assertAlmostEqual(q1.data, 20.0)
AssertionError: 6.096 != 20.0 within 7 places (13.904 difference)
---------------------------------------------------------------------- |
@homosapien-lcy I think you can fix this by avoiding unit systems entirely in Please also add the new test that appeared in my previous comment (possibly with a better name for the test method). |
Thanks for the comment, I made the update in PR #174. I also checked the other change_unit_system function calls, I think they are either using str unit system or None, so seems to be fine. |
The original unit conversion done in propagate_data_changes (scimath.units.quantity) can cause conversion error. This PR adds a fix and test for that. closes issue #171 --------- Co-authored-by: Chengyu Liu <[email protected]>
When running the test suite under
unittest
, there are tracebacks printed to the console. We should discover why those tracebacks are being printed, and either suppress the output (if it's harmless), or fix it (if not).Steps to reproduce:
python -m venv --clear ~/.venvs/scimath && source ~/.venvs/scimath/bin/activate
(with the venv location of your choice, of course)scimath
into the venv withpython -m pip install -e .
python -m unittest
For me, this gives the following output:
The text was updated successfully, but these errors were encountered: