Skip to content
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

tests/test_xpath1_parser.py::LxmlXPath1ParserTest::test_sum_function fails on some systems #66

Closed
mgorny opened this issue May 29, 2023 · 6 comments

Comments

@mgorny
Copy link

mgorny commented May 29, 2023

This is basically a "sigh" kind of problem but when running on my production system, I'm getting the following test failure:

_______________________________________________ LxmlXPath1ParserTest.test_sum_function ________________________________________________

self = <tests.test_xpath1_parser.LxmlXPath1ParserTest testMethod=test_sum_function>

    def test_sum_function(self):
        root = self.etree.XML(XML_DATA_TEST)
        context = XPathContext(root, variables=self.variables)
        self.check_value("sum($values)", 35, context)
        if sys.version_info < (3, 12):
            self.check_selector("sum(/values/a)", root, 13.299999999999999)
        else:
>           self.check_selector("sum(/values/a)", root, 13.3)

context    = XPathContext(root=<Element values at 0x7f63e26e3540>)
root       = <Element values at 0x7f63e26e3540>
self       = <tests.test_xpath1_parser.LxmlXPath1ParserTest testMethod=test_sum_function>

tests/test_xpath1_parser.py:1136: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_xpath1_parser.py:1683: in check_selector
    self.assertEqual(root.xpath(path, namespaces=namespaces, **variables), expected)
E   AssertionError: 13.299999999999999 != 13.3
        expected   = 13.3
        kwargs     = {}
        namespaces = None
        path       = 'sum(/values/a)'
        results    = 13.3
        root       = <Element values at 0x7f63e26e3540>
        self       = <tests.test_xpath1_parser.LxmlXPath1ParserTest testMethod=test_sum_function>
        variables  = {}

However, in the tox venv it's passing.

I've seen another package having weird precision-related test failure with Python 3.12. Perhaps the right solution would be to do testing with some tolerance rather than assuming an exact value?

@brunato
Copy link
Member

brunato commented May 30, 2023

Hi,
i will take a look soon for this. Probably your suggestion should be the right decision.

@hroncok
Copy link

hroncok commented Jun 16, 2023

This fails in Fedora on multiple architectures. I believe it might be related to python/cpython#100425

@hroncok
Copy link

hroncok commented Jun 16, 2023

Oh, sorry but we don't have 81bca86 in Fedora yet, so perhaps I am not hitting the same problem but an older reversed one.

@hroncok
Copy link

hroncok commented Jun 16, 2023

Expecting 13.3 on Python 3.12.0b2 works in Fedora on many tests but one. I agree that rather than if'ing the expected number, asserting the numbers are close seems better. E.g. via assertAlmostEqual.

@mgorny mgorny changed the title tests/test_xpath1_parser.py::LxmlXPath1ParserTest::test_sum_function fails on some system tests/test_xpath1_parser.py::LxmlXPath1ParserTest::test_sum_function fails on some systems Jun 16, 2023
brunato added a commit that referenced this issue Jun 17, 2023
  - Close comparison only with an expected float, not for a
    list/set comparison (check_value and check_selector)
@brunato
Copy link
Member

brunato commented Jun 18, 2023

Release v4.1.3 test helpers (check_value and check_selector) use assertAlmostEqual if the provided expected argument is a float number.

This should be enough to avoid approximation errors in tests (apply it also to decimal.Decimal values shouldn't be necessary).

@mgorny
Copy link
Author

mgorny commented Jun 18, 2023

Thanks. I can confirm that the tests pass for me in 4.1.3.

@brunato brunato closed this as completed Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants