Skip to content

BUG: Incorrect handling of decimals for numbers with exponential

Description

When entering input 12345.6789E-4, it was expected to be converted to 1.23456789. But instead, got 1.234567890000, that is, the converted number plus 4 decimals (the exact number of decimals of the input).

Cause and solution (WIP)

Still needs to investigate where this problem originates from, but probably it's related to the conversion and decimals logic, in defaultConversor and correctDecimals.

By now, i'll skip the failed tests on CI/CD since this bug doesn't affect the core functionality of the widget.

Tests output

Failed:

  • test_input_simple_float_with_exp (AssertionError: assert '1.234567890000' == '1.23456789')

Tests output:

test: commands[3]> xvfb-run coverage run -m pytest
=========================================== test session starts ============================================
platform linux -- Python 3.11.9, pytest-8.3.2, pluggy-1.5.0
cachedir: .tox/test/.pytest_cache
PyQt5 5.15.11 -- Qt runtime 5.15.14 -- Qt compiled 5.15.14
rootdir: /home/brenopelegrin/ciermag/pqwidget
configfile: pytest.ini
plugins: cov-5.0.0, qt-4.4.0, pylama-8.4.1
collected 46 items                                                                                         

tests/backend/test_pint_interface.py .............                                                   [ 28%]
tests/backend/test_utils.py .                                                                        [ 30%]
tests/test_defaults.py ..                                                                            [ 34%]
tests/validators/test_scientificcapturedgroups.py ..                                                 [ 39%]
tests/validators/test_scientificinputvalidator.py ......                                             [ 52%]
tests/widget/gui/test_dimensionless_with_thousand_sep.py ......F                                     [ 67%]
tests/widget/gui/test_dimensionless_wo_thousand_sep.py ......F...                                    [ 89%]
tests/widget/internals/test_scientificspinbox_internals.py .....                                     [100%]

================================================= FAILURES =================================================
_____________________________________ test_input_simple_float_with_exp _____________________________________

qtbot = <pytestqt.qtbot.QtBot object at 0x74dfebff5f90>
gui_utils = <tests.conftest.gui_utils.<locals>.GUIUtils object at 0x74dfebf97f90>
widget_dimensionless_with_thousand_sep = <scientific_spinbox.widget.ScientificSpinBox object at 0x74dfec7e6f80>

    def test_input_simple_float_with_exp(qtbot, gui_utils, widget_dimensionless_with_thousand_sep):
        test_cases = [
            {
                "text": "12345.6789E-4",
                "expected_text": "1.23456789",
                "expected_value": Decimal("1.23456789")
            }
        ]
        widget = widget_dimensionless_with_thousand_sep
        for case in test_cases:
            gui_utils.eraseAndEnterText(widget, case["text"])
>           assert widget.text() == case["expected_text"]
E           AssertionError: assert '1.234567890000' == '1.23456789'
E             
E             - 1.23456789
E             + 1.234567890000
E             ?           ++++

tests/widget/gui/test_dimensionless_with_thousand_sep.py:107: AssertionError
_____________________________________ test_input_simple_float_with_exp _____________________________________

qtbot = <pytestqt.qtbot.QtBot object at 0x74dfebc7a250>
gui_utils = <tests.conftest.gui_utils.<locals>.GUIUtils object at 0x74dfebc78690>
widget_dimensionless_wo_thousand_sep = <scientific_spinbox.widget.ScientificSpinBox object at 0x74dfebc4b640>

    def test_input_simple_float_with_exp(qtbot, gui_utils, widget_dimensionless_wo_thousand_sep):
        test_cases = [
            {
                "text": "12345.6789E-4",
                "expected_text": "1.23456789",
                "expected_value": Decimal("1.23456789")
            }
        ]
    
        widget = widget_dimensionless_wo_thousand_sep
        for case in test_cases:
            gui_utils.eraseAndEnterText(widget, case["text"])
>           assert widget.text() == case["expected_text"]
E           AssertionError: assert '1.234567890000' == '1.23456789'
E             
E             - 1.23456789
E             + 1.234567890000
E             ?           ++++

tests/widget/gui/test_dimensionless_wo_thousand_sep.py:115: AssertionError
========================================= short test summary info ==========================================
FAILED tests/widget/gui/test_dimensionless_with_thousand_sep.py::test_input_simple_float_with_exp - AssertionError: assert '1.234567890000' == '1.23456789'
FAILED tests/widget/gui/test_dimensionless_wo_thousand_sep.py::test_input_simple_float_with_exp - AssertionError: assert '1.234567890000' == '1.23456789'
======================================= 2 failed, 44 passed in 1.94s =======================================